<?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.LeaseAgreementSltMapper">
    <resultMap type="com.bonus.material.lease.domain.LeaseAgreementSlt" 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>




    <select id="selectLeaseAgreementSltList" resultType="com.bonus.material.lease.domain.LeaseAgreementSlt">
        SELECT
            sai.id as id,
            sai.agreement_id as agreementId,
            sai.type_id as typeId,
            sai.ma_id as maId,
            sai.num as num,
            sai.start_time as outTime,
            sai.end_time as backTime,
            sai.`status` as  status,
            sai.lease_id as pickId,
            sai.back_id as backId,
            sai.lease_price as leasePrice,
            sai.is_slt as isSlt,
            sai.slt_time as sltTime
        FROM
            slt_agreement_info sai
        where 1=1
        <if test="agreementId != null and agreementId != ''">
            and sai.agreement_id = #{agreementId}
        </if>
        <if test="typeId != null and typeId != ''">
            and sai.type_id = #{typeId}
        </if>
        <if test="maId != null and maId != ''">
            and sai.ma_id = #{maId}
        </if>
    </select>

    <select id="getInfo" resultType="com.bonus.material.lease.domain.LeaseAgreementSlt">
        SELECT
            sai.id as id,
            sai.agreement_id as agreementId,
            sai.type_id as typeId,
            sai.ma_id as maId,
            sai.num as num,
            sai.start_time as outTime,
            sai.end_time as backTime,
            sai.`status` as  status,
            sai.lease_id as pickId,
            sai.back_id as backId,
            sai.lease_price as leasePrice,
            sai.is_slt as isSlt,
            sai.slt_time as sltTime
        FROM
            slt_agreement_info sai
        where id = #{id}
    </select>

    <update id="updateLeaseSltInfo">
        update slt_agreement_info
        <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">start_time = #{outTime},</if>
            <if test="pickId != null">lease_id = #{pickId},</if>
            <if test="backTime != null">end_time = #{backTime},</if>
            <if test="backId != null">back_id = #{backId},</if>
            <if test="isSlt != null">is_slt = #{isSlt},</if>
            <if test="leasePrice != null">lease_price = #{leasePrice},</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="deleteLeaseSltInfo">
        delete from slt_agreement_info where id = #{id}
    </delete>

    <insert id="insertLeaseSltInfo">

        insert into slt_agreement_info
        <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">start_time,</if>
            <if test="pickId != null">lease_id,</if>
            <if test="backTime != null">end_time,</if>
            <if test="backId != null">back_id,</if>
            <if test="isSlt != null">is_slt,</if>
            <if test="leasePrice != null">lease_price,</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="leasePrice != null">#{leasePrice},</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>
</mapper>
