<?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.productionSolution.ProProductionSolutionProcessItemMapper">

    <resultMap type="ProProductionSolutionProcessItem" id="ProProductionSolutionProcessItemResult">
        <result property="productionSolutionProcessItemId" column="production_solution_process_item_id"/>
        <result property="productionSolutionProcessId" column="production_solution_process_id"/>
        <result property="sapItemCode" column="sap_item_code"/>
        <result property="sapItemName" column="sap_item_name"/>
        <result property="itemId" column="item_id"/>
        <result property="usageCode" column="usage_code"/>
        <result property="unitOfMeasure" column="unit_of_measure"/>
        <result property="deputyUnitOfMeasure" column="deputy_unit_of_measure"/>
        <result property="unitConvert" column="unit_convert"/>
        <result property="quantity" column="quantity"/>
        <result property="remark" column="remark"/>
        <result property="idx" column="idx"/>
        <result property="recoil" column="recoil"/>
    </resultMap>

    <sql id="selectProProductionSolutionProcessItemVo">
        select production_solution_process_item_id,
               production_solution_process_id,
               sap_item_code,
               sap_item_name,
               usage_code,
               unit_of_measure,
               deputy_unit_of_measure,
               unit_convert,
               quantity,
               remark,
               idx,
               recoil,
               item_id
        from pro_production_solution_process_item
    </sql>

    <select id="selectProProductionSolutionProcessItemList" parameterType="ProProductionSolutionProcessItem"
            resultMap="ProProductionSolutionProcessItemResult">
        <include refid="selectProProductionSolutionProcessItemVo"/>
        <where>
            <if test="productionSolutionProcessId != null ">and production_solution_process_id =
                #{productionSolutionProcessId}
            </if>
            <if test="itemId != null ">and item_id = #{itemId}</if>
        </where>
    </select>

    <select id="selectProProductionSolutionProcessItemByProductionSolutionProcessItemId" parameterType="Long"
            resultMap="ProProductionSolutionProcessItemResult">
        <include refid="selectProProductionSolutionProcessItemVo"/>
        where production_solution_process_item_id = #{productionSolutionProcessItemId}
    </select>
    <select id="selectProProductionSolutionProcessItemByProductionSolutionProcessId"
            parameterType="Long"
            resultMap="ProProductionSolutionProcessItemResult">
        <include refid="selectProProductionSolutionProcessItemVo"/>
        where production_solution_process_id = #{productionSolutionProcessId}
    </select>

    <insert id="insertProProductionSolutionProcessItem" parameterType="ProProductionSolutionProcessItem"
            useGeneratedKeys="true" keyProperty="productionSolutionProcessItemId">
        insert into pro_production_solution_process_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionSolutionProcessId != null">production_solution_process_id,</if>
            <if test="sapItemCode != null">sap_item_code,</if>
            <if test="sapItemName != null">sap_item_name,</if>
            <if test="usageCode != null">usage_code,</if>
            <if test="unitOfMeasure != null">unit_of_measure,</if>
            <if test="deputyUnitOfMeasure != null">deputy_unit_of_measure,</if>
            <if test="unitConvert != null">unit_convert,</if>
            <if test="quantity != null">quantity,</if>
            <if test="remark != null">remark,</if>
            <if test="idx != null">idx,</if>
            <if test="recoil != null">recoil,</if>
            <if test="itemId != null">item_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productionSolutionProcessId != null">#{productionSolutionProcessId},</if>
            <if test="sapItemCode != null">#{sapItemCode},</if>
            <if test="sapItemName != null">#{sapItemName},</if>
            <if test="usageCode != null">#{usageCode},</if>
            <if test="unitOfMeasure != null">#{unitOfMeasure},</if>
            <if test="deputyUnitOfMeasure != null">#{deputyUnitOfMeasure},</if>
            <if test="unitConvert != null">#{unitConvert},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="remark != null">#{remark},</if>
            <if test="idx != null">#{idx},</if>
            <if test="recoil != null">#{recoil},</if>
            <if test="itemId != null">#{itemId},</if>
        </trim>
    </insert>

    <update id="updateProProductionSolutionProcessItem" parameterType="ProProductionSolutionProcessItem">
        update pro_production_solution_process_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionSolutionProcessId != null">production_solution_process_id
                = #{productionSolutionProcessId},
            </if>
            <if test="sapItemCode != null">sap_item_code = #{sapItemCode},</if>
            <if test="sapItemName != null">sap_item_name = #{sapItemName},</if>
            <if test="usageCode != null">usage_code = #{usageCode},</if>
            <if test="unitOfMeasure != null">unit_of_measure = #{unitOfMeasure},</if>
            <if test="deputyUnitOfMeasure != null">deputy_unit_of_measure = #{deputyUnitOfMeasure},</if>
            <if test="unitConvert != null">unit_convert = #{unitConvert},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="idx != null">idx = #{idx},</if>
            <if test="recoil != null">recoil = #{recoil},</if>
            <if test="itemId != null">item_id = #{itemId},</if>
        </trim>
        where production_solution_process_item_id = #{productionSolutionProcessItemId}
    </update>

    <delete id="deleteProProductionSolutionProcessItemByProductionSolutionProcessItemId" parameterType="Long">
        delete
        from pro_production_solution_process_item
        where production_solution_process_item_id = #{productionSolutionProcessItemId}
    </delete>

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