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

    <resultMap type="ProProductionRequestProcess" id="ProProductionRequestProcessResult">
        <result property="productionRequestProcessId"    column="production_request_process_id"    />
        <result property="productionRequestId"    column="production_request_id"    />
        <result property="recordId"    column="record_id"    />
        <result property="workstationId"    column="workstation_id"    />
        <result property="stdWorkingTime"    column="std_working_time"    />
        <result property="defaultPreTime"    column="default_pre_time"    />
        <result property="defaultSufTime"    column="default_suf_time"    />
        <result property="keyFlag"    column="key_flag"    />
        <result property="isCheck"    column="is_check"    />
        <result property="remark"    column="remark"    />
        <result property="processName" column="process_name"/>
        <result property="processCode" column="process_code"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="nextProcessName" column="next_process_name"/>
        <result property="linkType" column="link_type"/>
        <result property="colorCode" column="color_code"/>
        <result property="orderNum" column="order_num"/>
    </resultMap>

    <sql id="selectProProductionRequestProcessVo">
        select production_request_process_id, production_request_id, t1.record_id, t1.workstation_id, t1.std_working_time, t1.default_pre_time, t1.default_suf_time, t1.key_flag, t1.is_check, t1.remark,
           prp.process_name,prp.process_code,prp.next_process_name,prp.order_num,mw.workstation_name,
               prp.color_code,prp.link_type
        from pro_production_request_process t1
        left join pro_route_process prp on t1.record_id = prp.record_id
        left join md_workstation mw on t1.workstation_id = mw.workstation_id
    </sql>
    <select id="selectProProductionRequestProcessList" parameterType="ProProductionRequestProcess" resultMap="ProProductionRequestProcessResult">
        <include refid="selectProProductionRequestProcessVo"/>
        <where>
            <if test="productionRequestId != null "> and production_request_id = #{productionRequestId}</if>
            <if test="recordId != null "> and record_id = #{recordId}</if>
            <if test="workstationId != null "> and workstation_id = #{workstationId}</if>
            <if test="stdWorkingTime != null "> and std_working_time = #{stdWorkingTime}</if>
            <if test="defaultPreTime != null "> and default_pre_time = #{defaultPreTime}</if>
            <if test="defaultSufTime != null "> and default_suf_time = #{defaultSufTime}</if>
            <if test="keyFlag != null  and keyFlag != ''"> and key_flag = #{keyFlag}</if>
            <if test="isCheck != null  and isCheck != ''"> and is_check = #{isCheck}</if>
        </where>
    </select>

    <select id="selectProProductionRequestProcessByProductionRequestProcessId" parameterType="Long" resultMap="ProProductionRequestProcessResult">
        <include refid="selectProProductionRequestProcessVo"/>
        where production_request_process_id = #{productionRequestProcessId}
    </select>

    <insert id="insertProProductionRequestProcess" parameterType="ProProductionRequestProcess" useGeneratedKeys="true" keyProperty="productionRequestProcessId">
        insert into pro_production_request_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionRequestId != null">production_request_id,</if>
            <if test="recordId != null">record_id,</if>
            <if test="workstationId != null">workstation_id,</if>
            <if test="stdWorkingTime != null">std_working_time,</if>
            <if test="defaultPreTime != null">default_pre_time,</if>
            <if test="defaultSufTime != null">default_suf_time,</if>
            <if test="keyFlag != null">key_flag,</if>
            <if test="isCheck != null">is_check,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="productionRequestId != null">#{productionRequestId},</if>
            <if test="recordId != null">#{recordId},</if>
            <if test="workstationId != null">#{workstationId},</if>
            <if test="stdWorkingTime != null">#{stdWorkingTime},</if>
            <if test="defaultPreTime != null">#{defaultPreTime},</if>
            <if test="defaultSufTime != null">#{defaultSufTime},</if>
            <if test="keyFlag != null">#{keyFlag},</if>
            <if test="isCheck != null">#{isCheck},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProProductionRequestProcess" parameterType="ProProductionRequestProcess">
        update pro_production_request_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionRequestId != null">production_request_id = #{productionRequestId},</if>
            <if test="recordId != null">record_id = #{recordId},</if>
            <if test="workstationId != null">workstation_id = #{workstationId},</if>
            <if test="stdWorkingTime != null">std_working_time = #{stdWorkingTime},</if>
            <if test="defaultPreTime != null">default_pre_time = #{defaultPreTime},</if>
            <if test="defaultSufTime != null">default_suf_time = #{defaultSufTime},</if>
            <if test="keyFlag != null">key_flag = #{keyFlag},</if>
            <if test="isCheck != null">is_check = #{isCheck},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where production_request_process_id = #{productionRequestProcessId}
    </update>

    <delete id="deleteProProductionRequestProcessByProductionRequestProcessId" parameterType="Long">
        delete from pro_production_request_process where production_request_process_id = #{productionRequestProcessId}
    </delete>

    <delete id="deleteProProductionRequestProcessByProductionRequestId" parameterType="Long">
        delete from pro_production_request_process where production_request_id = #{productionRequestId}
    </delete>


    <delete id="deleteProProductionRequestProcessByProductionRequestProcessIds" parameterType="String">
        delete from pro_production_request_process where production_request_process_id in
        <foreach item="productionRequestProcessId" collection="array" open="(" separator="," close=")">
            #{productionRequestProcessId}
        </foreach>
    </delete>
</mapper>
