<?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.CmcProcurePlanMapper">
    
    <resultMap type="CmcProcurePlan" id="CmcProcurePlanResult">
        <result property="procurePlanId"    column="procure_plan_id"    />
        <result property="procureApplyId"    column="procure_apply_id"    />
        <result property="name"    column="name"    />
        <result property="series"    column="series"    />
        <result property="unit"    column="unit"    />
        <result property="price"    column="price"    />
        <result property="num"    column="num"    />
        <result property="amount"    column="amount"    />
        <result property="procureWay"    column="procure_way"    />
        <result property="usage"    column="usage"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcProcurePlanVo">
        select procure_plan_id, procure_apply_id, `name`, series, unit, price, num, amount, procure_way, `usage`, remark from cmc_procure_plan
    </sql>

    <select id="selectCmcProcurePlanList" parameterType="CmcProcurePlan" resultMap="CmcProcurePlanResult">
        <include refid="selectCmcProcurePlanVo"/>
        <where>  
            <if test="procureApplyId != null  and procureApplyId != ''"> and procure_apply_id = #{procureApplyId}</if>
            <if test="name != null  and name != ''"> and `name` like concat('%', #{name}, '%')</if>
            <if test="series != null  and series != ''"> and series = #{series}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="num != null "> and num = #{num}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="procureWay != null  and procureWay != ''"> and procure_way = #{procureWay}</if>
            <if test="usage != null  and usage != ''"> and `usage` = #{usage}</if>
        </where>
    </select>
    
    <select id="selectCmcProcurePlanByProcurePlanId" parameterType="Integer" resultMap="CmcProcurePlanResult">
        <include refid="selectCmcProcurePlanVo"/>
        where procure_plan_id = #{procurePlanId}
    </select>
        
    <insert id="insertCmcProcurePlan" parameterType="CmcProcurePlan" useGeneratedKeys="true" keyProperty="procurePlanId">
        insert into cmc_procure_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="procureApplyId != null">procure_apply_id,</if>
            <if test="name != null">`name`,</if>
            <if test="series != null">series,</if>
            <if test="unit != null">unit,</if>
            <if test="price != null">price,</if>
            <if test="num != null">num,</if>
            <if test="amount != null">amount,</if>
            <if test="procureWay != null">procure_way,</if>
            <if test="usage != null">`usage`,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="procureApplyId != null">#{procureApplyId},</if>
            <if test="name != null">#{name},</if>
            <if test="series != null">#{series},</if>
            <if test="unit != null">#{unit},</if>
            <if test="price != null">#{price},</if>
            <if test="num != null">#{num},</if>
            <if test="amount != null">#{amount},</if>
            <if test="procureWay != null">#{procureWay},</if>
            <if test="usage != null">#{usage},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCmcProcurePlan" parameterType="CmcProcurePlan">
        update cmc_procure_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="procureApplyId != null">procure_apply_id = #{procureApplyId},</if>
            <if test="name != null">`name` = #{name},</if>
            <if test="series != null">series = #{series},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="price != null">price = #{price},</if>
            <if test="num != null">num = #{num},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="procureWay != null">procure_way = #{procureWay},</if>
            <if test="usage != null">`usage` = #{usage},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where procure_plan_id = #{procurePlanId}
    </update>

    <delete id="deleteCmcProcurePlanByProcurePlanId" parameterType="Integer">
        delete from cmc_procure_plan where procure_plan_id = #{procurePlanId}
    </delete>

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