<?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.SltProjectMonthCostsMapper">
    <resultMap type="com.bonus.material.settlement.domain.SltProjectMonthCosts" id="SltProjectMonthCostsResult">
        <result property="id"    column="id"    />
        <result property="agreementId"    column="agreement_id"    />
        <result property="unitId"    column="unit_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="month"    column="month"    />
        <result property="costBearingParty"    column="cost_bearing_party"    />
        <result property="costs"    column="costs"    />
        <result property="taskId"    column="task_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSltProjectMonthCostsVo">
        select id, agreement_id, unit_id, project_id, month, cost_bearing_party, costs, task_id, create_time, update_time from slt_project_month_costs
    </sql>

    <select id="selectSltProjectMonthCostsList" parameterType="com.bonus.material.settlement.domain.SltProjectMonthCosts" resultMap="SltProjectMonthCostsResult">
        <include refid="selectSltProjectMonthCostsVo"/>
        <where>  
            <if test="agreementId != null "> and agreement_id = #{agreementId}</if>
            <if test="unitId != null "> and unit_id = #{unitId}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="month != null  and month != ''"> and month = #{month}</if>
            <if test="costBearingParty != null  and costBearingParty != ''"> and cost_bearing_party = #{costBearingParty}</if>
            <if test="costs != null "> and costs = #{costs}</if>
            <if test="taskId != null "> and task_id = #{taskId}</if>
        </where>
    </select>
    
    <select id="selectSltProjectMonthCostsById" parameterType="Long" resultMap="SltProjectMonthCostsResult">
        <include refid="selectSltProjectMonthCostsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSltProjectMonthCosts" parameterType="com.bonus.material.settlement.domain.SltProjectMonthCosts" useGeneratedKeys="true" keyProperty="id">
        insert into slt_project_month_costs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agreementId != null">agreement_id,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="month != null">month,</if>
            <if test="costBearingParty != null">cost_bearing_party,</if>
            <if test="costs != null">costs,</if>
            <if test="taskId != null">task_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="unitId != null">#{unitId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="month != null">#{month},</if>
            <if test="costBearingParty != null">#{costBearingParty},</if>
            <if test="costs != null">#{costs},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateSltProjectMonthCosts" parameterType="com.bonus.material.settlement.domain.SltProjectMonthCosts">
        update slt_project_month_costs
        <trim prefix="SET" suffixOverrides=",">
            <if test="agreementId != null">agreement_id = #{agreementId},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="month != null">month = #{month},</if>
            <if test="costBearingParty != null">cost_bearing_party = #{costBearingParty},</if>
            <if test="costs != null">costs = #{costs},</if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSltProjectMonthCostsById" parameterType="Long">
        delete from slt_project_month_costs where id = #{id}
    </delete>

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