<?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.ProProductionSolutionProcessToolMapper">

    <resultMap type="ProProductionSolutionProcessTool" id="ProProductionSolutionProcessToolResult">
        <result property="prototypeSolutionProcessToolId" column="prototype_solution_process_tool_id"/>
        <result property="prototypeSolutionId" column="prototype_solution_id"/>
        <result property="prototypeSolutionProcessId" column="prototype_solution_process_id"/>
        <result property="toolId" column="tool_id"/>
        <result property="quantity" column="quantity"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectProProductionSolutionProcessToolVo">
        select prototype_solution_process_tool_id,
               prototype_solution_id,
               prototype_solution_process_id,
               tool_id,
               quantity,
               remark
        from pro_production_solution_process_tool
    </sql>

    <select id="selectProProductionSolutionProcessToolList" parameterType="ProProductionSolutionProcessTool"
            resultMap="ProProductionSolutionProcessToolResult">
        <include refid="selectProProductionSolutionProcessToolVo"/>
        <where>
            <if test="prototypeSolutionId != null ">and prototype_solution_id = #{prototypeSolutionId}</if>
            <if test="prototypeSolutionProcessId != null ">and prototype_solution_process_id =
                #{prototypeSolutionProcessId}
            </if>
            <if test="toolId != null ">and tool_id = #{toolId}</if>
            <if test="quantity != null ">and quantity = #{quantity}</if>
        </where>
    </select>

    <select id="selectProProductionSolutionProcessToolByPrototypeSolutionProcessToolId" parameterType="Long"
            resultMap="ProProductionSolutionProcessToolResult">
        <include refid="selectProProductionSolutionProcessToolVo"/>
        where prototype_solution_process_tool_id = #{prototypeSolutionProcessToolId}
    </select>


    <select id="selectProProductionSolutionProcessToolByPrototypeSolutionProcessId"
            parameterType="Long"
            resultMap="ProProductionSolutionProcessToolResult">
        <include refid="selectProProductionSolutionProcessToolVo"/>
        where prototype_solution_process_id = #{productionSolutionProcessId}
    </select>


    <insert id="insertProProductionSolutionProcessTool" parameterType="ProProductionSolutionProcessTool"
            useGeneratedKeys="true" keyProperty="prototypeSolutionProcessToolId">
        insert into pro_production_solution_process_tool
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prototypeSolutionId != null">prototype_solution_id,</if>
            <if test="prototypeSolutionProcessId != null">prototype_solution_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="prototypeSolutionId != null">#{prototypeSolutionId},</if>
            <if test="prototypeSolutionProcessId != null">#{prototypeSolutionProcessId},</if>
            <if test="toolId != null">#{toolId},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateProProductionSolutionProcessTool" parameterType="ProProductionSolutionProcessTool">
        update pro_production_solution_process_tool
        <trim prefix="SET" suffixOverrides=",">
            <if test="prototypeSolutionId != null">prototype_solution_id = #{prototypeSolutionId},</if>
            <if test="prototypeSolutionProcessId != null">prototype_solution_process_id =
                #{prototypeSolutionProcessId},
            </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 prototype_solution_process_tool_id = #{prototypeSolutionProcessToolId}
    </update>

    <delete id="deleteProProductionSolutionProcessToolByPrototypeSolutionProcessToolId" parameterType="Long">
        delete
        from pro_production_solution_process_tool
        where prototype_solution_process_tool_id = #{prototypeSolutionProcessToolId}
    </delete>

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