<?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.productionRequest.ProProductionRequestProcessToolMapper">

    <resultMap type="ProProductionRequestProcessTool" id="ProProductionRequestProcessToolResult">
        <result property="productionRequestProcessToolId"    column="production_request_process_tool_id"    />
        <result property="productionRequestId"    column="production_request_id"    />
        <result property="productionRequestProcessId"    column="production_request_process_id"    />
        <result property="toolId"    column="tool_id"    />
        <result property="quantity"    column="quantity"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectProProductionRequestProcessToolVo">
        select production_request_process_tool_id, production_request_id, production_request_process_id, tool_id, quantity, remark from pro_production_request_process_tool
    </sql>

    <select id="selectProProductionRequestProcessToolList" parameterType="ProProductionRequestProcessTool" resultMap="ProProductionRequestProcessToolResult">
        <include refid="selectProProductionRequestProcessToolVo"/>
        <where>
            <if test="productionRequestId != null ">and production_request_id =
                #{productionRequestId}
            </if>
            <if test="productionRequestProcessId != null ">and production_request_process_id =
                #{productionRequestProcessId}
            </if>
            <if test="productionRequestProcessToolId != null ">and production_request_process_tool_id = #{productionRequestProcessToolId}</if>
        </where>
    </select>

    <select id="selectProProductionRequestProcessToolByProductionRequestProcessToolId" parameterType="Long" resultMap="ProProductionRequestProcessToolResult">
        <include refid="selectProProductionRequestProcessToolVo"/>
        where production_request_process_tool_id = #{productionRequestProcessToolId}
    </select>

    <insert id="insertProProductionRequestProcessTool" parameterType="ProProductionRequestProcessTool" useGeneratedKeys="true" keyProperty="productionRequestProcessToolId">
        insert into pro_production_request_process_tool
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionRequestId != null">production_request_id,</if>
            <if test="productionRequestProcessId != null">production_request_process_id,</if>
            <if test="toolId != null">tool_id,</if>
            <if test="quantity != null">quantity,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productionRequestId != null">#{productionRequestId},</if>
            <if test="productionRequestProcessId != null">#{productionRequestProcessId},</if>
            <if test="toolId != null">#{toolId},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProProductionRequestProcessTool" parameterType="ProProductionRequestProcessTool">
        update pro_production_request_process_tool
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionRequestId != null">production_request_id = #{productionRequestId},</if>
            <if test="productionRequestProcessId != null">production_request_process_id = #{productionRequestProcessId},</if>
            <if test="toolId != null">tool_id = #{toolId},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where production_request_process_tool_id = #{productionRequestProcessToolId}
    </update>

    <delete id="deleteProProductionRequestProcessToolByProductionRequestProcessToolId" parameterType="Long">
        delete from pro_production_request_process_tool where production_request_process_tool_id = #{productionRequestProcessToolId}
    </delete>

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