<?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.SltAgreementDetailsMapper">
    <resultMap type="com.bonus.material.settlement.domain.SltAgreementDetails" id="SltAgreementDetailsResult">
        <result property="id"    column="id"    />
        <result property="applyId"    column="apply_id"    />
        <result property="typeId"    column="type_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="sltType"    column="slt_type"    />
        <result property="num"    column="num"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="price"    column="price"    />
        <result property="money"    column="money"    />
        <result property="isCharge"    column="is_charge"    />
    </resultMap>

    <sql id="selectSltAgreementDetailsVo">
        select id, apply_id, type_id, ma_id, slt_type, num, start_time, end_time, price, money, is_charge from slt_agreement_details
    </sql>

    <select id="selectSltAgreementDetailsList" parameterType="com.bonus.material.settlement.domain.SltAgreementDetails" resultMap="SltAgreementDetailsResult">
        <include refid="selectSltAgreementDetailsVo"/>
        <where>  
            <if test="applyId != null "> and apply_id = #{applyId}</if>
            <if test="typeId != null "> and type_id = #{typeId}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="sltType != null  and sltType != ''"> and slt_type = #{sltType}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="money != null "> and money = #{money}</if>
            <if test="isCharge != null  and isCharge != ''"> and is_charge = #{isCharge}</if>
        </where>
    </select>
    
    <select id="selectSltAgreementDetailsById" parameterType="Long" resultMap="SltAgreementDetailsResult">
        <include refid="selectSltAgreementDetailsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSltAgreementDetails" parameterType="com.bonus.material.settlement.domain.SltAgreementDetails" useGeneratedKeys="true" keyProperty="id">
        insert into slt_agreement_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyId != null">apply_id,</if>
            <if test="typeId != null">type_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="sltType != null">slt_type,</if>
            <if test="num != null">num,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="price != null">price,</if>
            <if test="money != null">money,</if>
            <if test="isCharge != null">is_charge,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyId != null">#{applyId},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="sltType != null">#{sltType},</if>
            <if test="num != null">#{num},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="price != null">#{price},</if>
            <if test="money != null">#{money},</if>
            <if test="isCharge != null">#{isCharge},</if>
         </trim>
    </insert>

    <update id="updateSltAgreementDetails" parameterType="com.bonus.material.settlement.domain.SltAgreementDetails">
        update slt_agreement_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyId != null">apply_id = #{applyId},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="sltType != null">slt_type = #{sltType},</if>
            <if test="num != null">num = #{num},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="price != null">price = #{price},</if>
            <if test="money != null">money = #{money},</if>
            <if test="isCharge != null">is_charge = #{isCharge},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSltAgreementDetailsById" parameterType="Long">
        delete from slt_agreement_details where id = #{id}
    </delete>

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