<?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.material.lease.mapper.LeaseUserBookMapper">
    <resultMap type="com.bonus.material.lease.domain.LeaseUserBook" id="LeaseUserBookResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="bookNum"    column="book_num"    />
        <result property="bookTime"    column="book_time"    />
        <result property="remark"    column="remark"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectLeaseUserBookVo">
        select id, user_id, type_id, book_num, book_time, remark, company_id, create_time, update_time from lease_user_book
    </sql>

    <select id="selectLeaseUserBookList" parameterType="com.bonus.material.lease.domain.LeaseUserBook" resultMap="LeaseUserBookResult">
        <include refid="selectLeaseUserBookVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="bookNum != null "> and book_num = #{bookNum}</if>
            <if test="bookTime != null "> and book_time = #{bookTime}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectLeaseUserBookById" parameterType="Long" resultMap="LeaseUserBookResult">
        <include refid="selectLeaseUserBookVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertLeaseUserBook" parameterType="com.bonus.material.lease.domain.LeaseUserBook" useGeneratedKeys="true" keyProperty="id">
        insert into lease_user_book
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="bookNum != null">book_num,</if>
            <if test="bookTime != null">book_time,</if>
            <if test="remark != null">remark,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="bookNum != null">#{bookNum},</if>
            <if test="bookTime != null">#{bookTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateLeaseUserBook" parameterType="com.bonus.material.lease.domain.LeaseUserBook">
        update lease_user_book
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="bookNum != null">book_num = #{bookNum},</if>
            <if test="bookTime != null">book_time = #{bookTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLeaseUserBookById" parameterType="Long">
        delete from lease_user_book where id = #{id}
    </delete>

    <delete id="deleteLeaseUserBookByIds" parameterType="String">
        delete from lease_user_book where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>