<?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.CmcPriceMapper">
    
    <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="pricePercentage"    column="price_percentage"    />
        <result property="scaleGrade"    column="scale_grade"    />
        <result property="unit"    column="unit"    />
        <result property="commonPrice"    column="common_price"    />
        <result property="complexPrice"    column="complex_price"    />
    </resultMap>

    <sql id="selectCmcPriceVo">
        select id, work_type, work_item, sub_item, price_percentage, scale_grade, unit, common_price, complex_price from cmc_price
    </sql>

    <select id="selectCmcPriceList" parameterType="CmcPrice" resultMap="CmcPriceResult">
        <include refid="selectCmcPriceVo"/>
        <where>  
            <if test="workType != null  and workType != ''"> and work_type like concat('%', #{workType}, '%')</if>
            <if test="workItem != null  and workItem != ''"> and work_item like concat('%', #{workItem}, '%')</if>
            <if test="subItem != null  and subItem != ''"> and sub_item = #{subItem}</if>
            <if test="pricePercentage != null  and pricePercentage != ''"> and price_percentage = #{pricePercentage}</if>
            <if test="scaleGrade != null  and scaleGrade != ''"> and scale_grade = #{scaleGrade}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="commonPrice != null "> and common_price = #{commonPrice}</if>
            <if test="complexPrice != null "> and complex_price = #{complexPrice}</if>
        </where>
    </select>
    
    <select id="selectCmcPriceById" parameterType="Long" resultMap="CmcPriceResult">
        <include refid="selectCmcPriceVo"/>
        where id = #{id}
    </select>

    <select id="selectCmcPriceByWorkType" parameterType="String" resultMap="CmcPriceResult">
        <include refid="selectCmcPriceVo"/>
        where work_type = #{workType}
    </select>

    <select id="selectCmcPriceByWorkItem" parameterType="String" resultMap="CmcPriceResult">
        <include refid="selectCmcPriceVo"/>
        where work_item = #{workItem}
    </select>

    <select id="selectCmcPriceByScaleGrade" parameterType="String" resultMap="CmcPriceResult">
        <include refid="selectCmcPriceVo"/>
        <where>
            <if test="param1 != null  and param1 != ''"> and work_item = #{param1}</if>
            <if test="param2 != null  and param2 != ''"> and sub_item = #{param2}</if>
            <if test="param3 != null  and param3 != ''"> and scale_grade = #{param3}</if>
        </where>
    </select>

    <insert id="insertCmcPrice" parameterType="CmcPrice" useGeneratedKeys="true" keyProperty="id">
        insert into cmc_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workType != null">work_type,</if>
            <if test="workItem != null">work_item,</if>
            <if test="subItem != null">sub_item,</if>
            <if test="pricePercentage != null">price_percentage,</if>
            <if test="scaleGrade != null">scale_grade,</if>
            <if test="unit != null">unit,</if>
            <if test="commonPrice != null">common_price,</if>
            <if test="complexPrice != null">complex_price,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workType != null">#{workType},</if>
            <if test="workItem != null">#{workItem},</if>
            <if test="subItem != null">#{subItem},</if>
            <if test="pricePercentage != null">#{pricePercentage},</if>
            <if test="scaleGrade != null">#{scaleGrade},</if>
            <if test="unit != null">#{unit},</if>
            <if test="commonPrice != null">#{commonPrice},</if>
            <if test="complexPrice != null">#{complexPrice},</if>
         </trim>
    </insert>

    <update id="updateCmcPrice" parameterType="CmcPrice">
        update cmc_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="workType != null">work_type = #{workType},</if>
            <if test="workItem != null">work_item = #{workItem},</if>
            <if test="subItem != null">sub_item = #{subItem},</if>
            <if test="pricePercentage != null">price_percentage = #{pricePercentage},</if>
            <if test="scaleGrade != null">scale_grade = #{scaleGrade},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="commonPrice != null">common_price = #{commonPrice},</if>
            <if test="complexPrice != null">complex_price = #{complexPrice},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCmcPriceById" parameterType="Long">
        delete from cmc_price where id = #{id}
    </delete>

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