<?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.ximai.mes.pro.mapper.prototypeMake.ProPrototypeMakeProcessItemMapper">

    <resultMap type="ProPrototypeMakeProcessItem" id="ProPrototypeMakeProcessItemResult">
        <result property="prototypeMakeProcessItemId" column="prototype_make_process_item_id"/>
        <result property="prototypeMakeProcessId" column="prototype_make_process_id"/>
        <result property="itemId" column="item_id"/>
        <result property="itemName" column="item_name"/>
        <result property="unitOfMeasure" column="unit_of_measure"/>
        <result property="quantity" column="quantity"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectProPrototypeMakeProcessItemVo">
        select ppmpi.prototype_make_process_item_id,
               ppmpi.prototype_make_process_id,
               ppmpi.item_id,
               ppmpi.unit_of_measure,
               ppmpi.quantity,
               ppmpi.remark,
               mi.item_name
        from pro_prototype_make_process_item ppmpi
left join md_item mi on ppmpi.item_id = mi.item_id
    </sql>

    <select id="selectProPrototypeMakeProcessItemList" parameterType="ProPrototypeMakeProcessItem"
            resultMap="ProPrototypeMakeProcessItemResult">
        <include refid="selectProPrototypeMakeProcessItemVo"/>
        <where>
            <if test="prototypeMakeProcessId != null ">and ppmpi.prototype_make_process_id = #{prototypeMakeProcessId}</if>
            <if test="itemId != null ">and ppmpi.item_id = #{itemId}</if>
            <if test="itemName != null and itemName != ''">and mi.item_name = #{itemName}</if>
            <if test="unitOfMeasure != null  and unitOfMeasure != ''">and ppmpi.unit_of_measure = #{unitOfMeasure}</if>
            <if test="quantity != null ">and ppmpi.quantity = #{quantity}</if>
        </where>
    </select>

    <select id="selectProPrototypeMakeProcessItemByPrototypeMakeProcessItemId" parameterType="Long"
            resultMap="ProPrototypeMakeProcessItemResult">
        <include refid="selectProPrototypeMakeProcessItemVo"/>
        where ppmpi.prototype_make_process_item_id = #{prototypeMakeProcessItemId}
    </select>

    <select id="selectProPrototypeMakeProcessItemByPrototypeMakeProcessId"
            parameterType="Long" resultMap="ProPrototypeMakeProcessItemResult">
        <include refid="selectProPrototypeMakeProcessItemVo"/>
        where ppmpi.prototype_make_process_id = #{prototypeMakeProcessId}
    </select>

    <insert id="insertProPrototypeMakeProcessItem" parameterType="ProPrototypeMakeProcessItem" useGeneratedKeys="true"
            keyProperty="prototypeMakeProcessItemId">
        insert into pro_prototype_make_process_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prototypeMakeProcessId != null">prototype_make_process_id,</if>
            <if test="itemId != null">item_id,</if>
            <if test="unitOfMeasure != null">unit_of_measure,</if>
            <if test="quantity != null">quantity,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="prototypeMakeProcessId != null">#{prototypeMakeProcessId},</if>
            <if test="itemId != null">#{itemId},</if>
            <if test="unitOfMeasure != null">#{unitOfMeasure},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateProPrototypeMakeProcessItem" parameterType="ProPrototypeMakeProcessItem">
        update pro_prototype_make_process_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="prototypeMakeProcessId != null">prototype_make_process_id = #{prototypeMakeProcessId},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
            <if test="unitOfMeasure != null">unit_of_measure = #{unitOfMeasure},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where prototype_make_process_item_id = #{prototypeMakeProcessItemId}
    </update>

    <delete id="deleteProPrototypeMakeProcessItemByPrototypeMakeProcessItemId" parameterType="Long">
        delete
        from pro_prototype_make_process_item
        where prototype_make_process_item_id = #{prototypeMakeProcessItemId}
    </delete>

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