<?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.settlement.mapper.SltAgreementRelationMapper">
    <resultMap type="com.bonus.material.settlement.domain.SltAgreementRelation" id="SltAgreementRelationResult">
        <result property="id"    column="id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="agreementId"    column="agreement_id"    />
        <result property="addCost"    column="add_cost"    />
        <result property="subCost"    column="sub_cost"    />
        <result property="remark"    column="remark"    />
        <result property="leaseOneCost"    column="lease_one_cost"    />
        <result property="repairCost"    column="repair_cost"    />
        <result property="scrapCost"    column="scrap_cost"    />
        <result property="loseCost"    column="lose_cost"    />
        <result property="cost"    column="cost"    />
        <result property="status"    column="status"    />
        <result property="leaseThreeCost"    column="lease_three_cost"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSltAgreementRelationVo">
        select id, apply_id, agreement_id, add_cost, sub_cost, remark, lease_one_cost, repair_cost, scrap_cost, lose_cost, cost, status, lease_three_cost, create_time, update_time from slt_agreement_relation
    </sql>

    <select id="selectSltAgreementRelationList" parameterType="com.bonus.material.settlement.domain.SltAgreementRelation" resultMap="SltAgreementRelationResult">
        <include refid="selectSltAgreementRelationVo"/>
        <where>  
            <if test="applyId != null  and applyId != ''"> and apply_id = #{applyId}</if>
            <if test="agreementId != null  and agreementId != ''"> and agreement_id = #{agreementId}</if>
            <if test="addCost != null "> and add_cost = #{addCost}</if>
            <if test="subCost != null "> and sub_cost = #{subCost}</if>
            <if test="leaseOneCost != null "> and lease_one_cost = #{leaseOneCost}</if>
            <if test="repairCost != null "> and repair_cost = #{repairCost}</if>
            <if test="scrapCost != null "> and scrap_cost = #{scrapCost}</if>
            <if test="loseCost != null "> and lose_cost = #{loseCost}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="leaseThreeCost != null "> and lease_three_cost = #{leaseThreeCost}</if>
        </where>
    </select>
    
    <select id="selectSltAgreementRelationById" parameterType="Long" resultMap="SltAgreementRelationResult">
        <include refid="selectSltAgreementRelationVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSltAgreementRelation" parameterType="com.bonus.material.settlement.domain.SltAgreementRelation" useGeneratedKeys="true" keyProperty="id">
        insert into slt_agreement_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="agreementId != null">agreement_id,</if>
            <if test="addCost != null">add_cost,</if>
            <if test="subCost != null">sub_cost,</if>
            <if test="remark != null">remark,</if>
            <if test="leaseOneCost != null">lease_one_cost,</if>
            <if test="repairCost != null">repair_cost,</if>
            <if test="scrapCost != null">scrap_cost,</if>
            <if test="loseCost != null">lose_cost,</if>
            <if test="cost != null">cost,</if>
            <if test="status != null">status,</if>
            <if test="leaseThreeCost != null">lease_three_cost,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="agreementId != null">#{agreementId},</if>
            <if test="addCost != null">#{addCost},</if>
            <if test="subCost != null">#{subCost},</if>
            <if test="remark != null">#{remark},</if>
            <if test="leaseOneCost != null">#{leaseOneCost},</if>
            <if test="repairCost != null">#{repairCost},</if>
            <if test="scrapCost != null">#{scrapCost},</if>
            <if test="loseCost != null">#{loseCost},</if>
            <if test="cost != null">#{cost},</if>
            <if test="status != null">#{status},</if>
            <if test="leaseThreeCost != null">#{leaseThreeCost},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateSltAgreementRelation" parameterType="com.bonus.material.settlement.domain.SltAgreementRelation">
        update slt_agreement_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="agreementId != null">agreement_id = #{agreementId},</if>
            <if test="addCost != null">add_cost = #{addCost},</if>
            <if test="subCost != null">sub_cost = #{subCost},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="leaseOneCost != null">lease_one_cost = #{leaseOneCost},</if>
            <if test="repairCost != null">repair_cost = #{repairCost},</if>
            <if test="scrapCost != null">scrap_cost = #{scrapCost},</if>
            <if test="loseCost != null">lose_cost = #{loseCost},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="status != null">status = #{status},</if>
            <if test="leaseThreeCost != null">lease_three_cost = #{leaseThreeCost},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSltAgreementRelationById" parameterType="Long">
        delete from slt_agreement_relation where id = #{id}
    </delete>

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