<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.app.mapper.LeaseUserBookMapper">
    <insert id="add">
        insert into lease_user_book (user_id,type_id,book_num,book_time,company_id)
        values (#{userId},#{typeId},#{bookNum},now(),#{companyId});
    </insert>
    <update id="update">
        update lease_user_book
        set book_num = #{bookNum}
        where id = #{id}
    </update>
    <delete id="batchDel">
        delete
        from lease_user_book
        where id in 
        <foreach close=")" collection="ids" item="id" open="(" separator=", ">
            #{id}
        </foreach>
    </delete>


    <select id="getLeaseUserBook" resultType="com.bonus.sgzb.app.domain.LeaseUserBook">
        select lub.id,
               lub.user_id as userId,
               lub.type_id as typeId,
                mt2.type_name as parentName,
               mt.type_name as typeName,
               lub.book_num as bookNum,
               lub.company_id as companyId
        from lease_user_book lub
        left join ma_type mt on lub.type_id = mt.type_id
        left join ma_type mt2 on mt.parent_id = mt2.type_id
        where lub.user_id = #{userId}
    </select>
</mapper>