<?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.LeaseAgreementRecordMapper">
    <resultMap type="com.bonus.material.lease.domain.LeaseAgreementRecord" id="LeaseAgreementRecordResult">
        <result property="id"    column="id"    />
        <result property="agreementId"    column="agreement_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="num"    column="num"    />
        <result property="status"    column="status"    />
        <result property="outTime"    column="out_time"    />
        <result property="pickId"    column="pick_id"    />
        <result property="backTime"    column="back_time"    />
        <result property="backId"    column="back_id"    />
        <result property="isSlt"    column="is_slt"    />
        <result property="sltTime"    column="slt_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectLeaseAgreementRecordVo">
        select id, agreement_id, type_id, ma_id, num, status, out_time, pick_id, back_time, back_id, is_slt, slt_time, company_id, create_time, update_time from lease_agreement_record
    </sql>

    <select id="selectLeaseAgreementRecordList" parameterType="com.bonus.material.lease.domain.LeaseAgreementRecord" resultMap="LeaseAgreementRecordResult">
        <include refid="selectLeaseAgreementRecordVo"/>
        <where>  
            <if test="agreementId != null "> and agreement_id = #{agreementId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="outTime != null "> and out_time = #{outTime}</if>
            <if test="pickId != null "> and pick_id = #{pickId}</if>
            <if test="backTime != null "> and back_time = #{backTime}</if>
            <if test="backId != null "> and back_id = #{backId}</if>
            <if test="isSlt != null  and isSlt != ''"> and is_slt = #{isSlt}</if>
            <if test="sltTime != null "> and slt_time = #{sltTime}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectLeaseAgreementRecordById" parameterType="Long" resultMap="LeaseAgreementRecordResult">
        <include refid="selectLeaseAgreementRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertLeaseAgreementRecord" parameterType="com.bonus.material.lease.domain.LeaseAgreementRecord" useGeneratedKeys="true" keyProperty="id">
        insert into lease_agreement_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agreementId != null">agreement_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="num != null">num,</if>
            <if test="status != null">status,</if>
            <if test="outTime != null">out_time,</if>
            <if test="pickId != null">pick_id,</if>
            <if test="backTime != null">back_time,</if>
            <if test="backId != null">back_id,</if>
            <if test="isSlt != null">is_slt,</if>
            <if test="sltTime != null">slt_time,</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="agreementId != null">#{agreementId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="num != null">#{num},</if>
            <if test="status != null">#{status},</if>
            <if test="outTime != null">#{outTime},</if>
            <if test="pickId != null">#{pickId},</if>
            <if test="backTime != null">#{backTime},</if>
            <if test="backId != null">#{backId},</if>
            <if test="isSlt != null">#{isSlt},</if>
            <if test="sltTime != null">#{sltTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateLeaseAgreementRecord" parameterType="com.bonus.material.lease.domain.LeaseAgreementRecord">
        update lease_agreement_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="agreementId != null">agreement_id = #{agreementId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="num != null">num = #{num},</if>
            <if test="status != null">status = #{status},</if>
            <if test="outTime != null">out_time = #{outTime},</if>
            <if test="pickId != null">pick_id = #{pickId},</if>
            <if test="backTime != null">back_time = #{backTime},</if>
            <if test="backId != null">back_id = #{backId},</if>
            <if test="isSlt != null">is_slt = #{isSlt},</if>
            <if test="sltTime != null">slt_time = #{sltTime},</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="deleteLeaseAgreementRecordById" parameterType="Long">
        delete from lease_agreement_record where id = #{id}
    </delete>

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