<?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.ruoyi.oa.mapper.CmcBudgetSettleMapper">
    
    <resultMap type="CmcBudgetSettle" id="CmcBudgetSettleResult">
        <result property="budgetSettleId"    column="budget_settle_id"    />
        <result property="budgetId"    column="budget_id"    />
        <result property="priceId"    column="price_id"    />
        <result property="checkPriceId"    column="check_price_id"    />
        <result property="content"    column="content"    />
        <result property="workload"    column="workload"    />
        <result property="coefficient"    column="coefficient"    />
        <result property="groundType"    column="ground_type"    />
        <result property="settle"    column="settle"    />
        <result property="remark"    column="remark"    />
        <association property="cmcPrice"    javaType="CmcPrice"         resultMap="CmcPriceResult" />
        <association property="cmcCheckPrice"    javaType="CmcCheckPrice"         resultMap="CmcCheckPriceResult" />
    </resultMap>

    <resultMap type="CmcPrice" id="CmcPriceResult">
        <result property="id"    column="id"    />
        <result property="workType"    column="work_type"    />
        <result property="workItem"    column="work_item"    />
        <result property="subItem"    column="sub_item"    />
        <result property="scaleGrade"    column="scale_grade"    />
        <result property="unit"    column="unit"    />
        <result property="commonPrice"    column="common_price"    />
        <result property="complexPrice"    column="complex_price"    />
    </resultMap>

    <resultMap type="CmcCheckPrice" id="CmcCheckPriceResult">
        <result property="id"    column="id"    />
        <result property="workType"    column="check_work_type"    />
        <result property="workItem"    column="check_work_item"    />
        <result property="subItem"    column="check_sub_item"    />
        <result property="scaleGrade"    column="check_scale_grade"    />
        <result property="unit"    column="check_unit"    />
        <result property="commonPrice"    column="check_common_price"    />
        <result property="complexPrice"    column="check_complex_price"    />
        <result property="remark"    column="check_remark"    />
    </resultMap>

    <sql id="selectCmcBudgetSettleVo">
        select bs.budget_settle_id, bs.budget_id, bs.content, bs.price_id, bs.check_price_id, p.work_type, p.work_item, p.sub_item, p.scale_grade, p.unit, 
        p.common_price, p.complex_price, cp.work_type as check_work_type, cp.work_item as check_work_item, cp.sub_item as check_sub_item, cp.scale_grade as check_scale_grade, 
        cp.unit as check_unit, cp.common_price as check_common_price, cp.complex_price as check_complex_price, cp.remark as check_remark, bs.workload, bs.coefficient, 
        bs.ground_type, bs.settle , bs.remark from cmc_budget_settle as bs
        left join cmc_price as p on p.id = bs.price_id
        left join cmc_check_price as cp on cp.id = bs.check_price_id
    </sql>

    <select id="selectCmcBudgetSettleList" parameterType="CmcBudgetSettle" resultMap="CmcBudgetSettleResult">
        <include refid="selectCmcBudgetSettleVo"/>
        <where>  
            <if test="budgetId != null  and budgetId != ''"> and bs.budget_id = #{budgetId}</if>
            <if test="priceId != null "> and bs.price_id = #{priceId}</if>
            <if test="workload != null "> and bs.workload = #{workload}</if>
            <if test="coefficient != null "> and bs.coefficient = #{coefficient}</if>
            <if test="groundType != null and groundType != ''"> and bs.ground_type = #{groundType}</if>
            <if test="settle != null "> and bs.settle = #{settle}</if>
        </where>
    </select>
    
    <select id="selectCmcBudgetSettleByBudgetId" parameterType="String" resultMap="CmcBudgetSettleResult">
        <include refid="selectCmcBudgetSettleVo"/>
        where bs.budget_id = #{budgetId}
    </select>
        
    <insert id="insertCmcBudgetSettle" parameterType="CmcBudgetSettle">
        insert into cmc_budget_settle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="budgetSettleId != null">budget_settle_id,</if>
            <if test="budgetId != null">budget_id,</if>
            <if test="content != null">content,</if>
            <if test="priceId != null">price_id,</if>
            <if test="checkPriceId != null">check_price_id,</if>
            <if test="workload != null">workload,</if>
            <if test="coefficient != null">coefficient,</if>
            <if test="groundType != null">ground_type,</if>
            <if test="settle != null">settle,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="budgetSettleId != null">#{budgetSettleId},</if>
            <if test="budgetId != null">#{budgetId},</if>
            <if test="content != null">#{content},</if>
            <if test="priceId != null">#{priceId},</if>
            <if test="checkPriceId != null">#{checkPriceId},</if>
            <if test="workload != null">#{workload},</if>
            <if test="coefficient != null">#{coefficient},</if>
            <if test="groundType != null">#{groundType},</if>
            <if test="settle != null">#{settle},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcBudgetSettle" parameterType="CmcBudgetSettle">
        update cmc_budget_settle
        <trim prefix="SET" suffixOverrides=",">
            <if test="budgetId != null">budget_id = #{budgetId},</if>
            <if test="content != null">content = #{content},</if>
            <if test="priceId != null">price_id = #{priceId},</if>
            <if test="checkPriceId != null">check_price_id = #{checkPriceId},</if>
            <if test="workload != null">workload = #{workload},</if>
            <if test="coefficient != null">coefficient = #{coefficient},</if>
            <if test="groundType != null">ground_type = #{groundType},</if>
            <if test="settle != null">settle = #{settle},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where budget_settle_id = #{budgetSettleId}
    </update>

    <delete id="deleteCmcBudgetSettleByBudgetId" parameterType="String">
        delete from cmc_budget_settle where budget_id = #{budgetId}
    </delete>

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