<?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.prototypeRequest.ProPrototypeRequestProcessMapper">

    <resultMap type="proPrototypeRequestProcessVo" id="ProPrototypeRequestProcessResult">
        <result property="prototypeRequestProcessId" column="prototype_request_process_id"/>
        <result property="prototypeRequestId" column="prototype_request_id"/>
        <result property="recordId" column="record_id"/>
        <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="workstationId" column="workstation_id"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="stdWorkingTime" column="std_working_time"/>
        <result property="linkType" column="link_type"/>
        <result property="colorCode" column="color_code"/>
        <result property="processName" column="process_name"/>
        <result property="processCode" column="process_code"/>
        <result property="nextProcessName" column="next_process_name"/>
        <result property="orderNum" column="order_num"/>
        <result property="processId" column="process_id"/>
    </resultMap>

    <sql id="selectProPrototypeRequestProcessVo">
        select pprp.prototype_request_process_id,
               pprp.prototype_request_id,
               pprp.record_id,
               pprp.default_pre_time,
               pprp.default_suf_time,
               pprp.key_flag,
               pprp.is_check,
               pprp.remark,
               pprp.workstation_id,
               pprp.std_working_time,
               prp.link_type,
               prp.color_code,
               prp.process_name,
               prp.process_code,
               prp.process_id,
               prp.next_process_name,
               prp.order_num,
               mw.workstation_name
        from pro_prototype_request_process pprp
                 left join pro_route_process prp on pprp.record_id = prp.record_id
                 left join md_workstation mw on pprp.workstation_id = mw.workstation_id
    </sql>

    <select id="selectProPrototypeRequestProcessList" parameterType="ProPrototypeRequestProcess"
            resultMap="ProPrototypeRequestProcessResult">
        <include refid="selectProPrototypeRequestProcessVo"/>
        <where>
            <if test="prototypeRequestId != null ">and pprp.prototype_request_id = #{prototypeRequestId}</if>
            <if test="recordId != null ">and pprp.record_id = #{recordId}</if>
            <if test="defaultPreTime != null ">and  pprp.default_pre_time = #{defaultPreTime}</if>
            <if test="defaultSufTime != null ">and  pprp.default_suf_time = #{defaultSufTime}</if>
            <if test="keyFlag != null  and keyFlag != ''">and  pprp.key_flag = #{keyFlag}</if>
            <if test="isCheck != null  and isCheck != ''">and  pprp.is_check = #{isCheck}</if>
            <if test="workstationId != null ">and  pprp.workstation_id = #{workstationId}</if>
            <if test="stdWorkingTime != null ">and  pprp.std_working_time = #{stdWorkingTime}</if>
        </where>
    </select>

    <select id="selectProPrototypeRequestProcessByPrototypeRequestProcessId" parameterType="Long"
            resultMap="ProPrototypeRequestProcessResult">
        <include refid="selectProPrototypeRequestProcessVo"/>
        where  pprp.prototype_request_process_id = #{prototypeRequestProcessId}
    </select>
    <select id="selectProPrototypeRequestProcessByPrototypeRequestId"
            parameterType="Long" resultMap="ProPrototypeRequestProcessResult">
        <include refid="selectProPrototypeRequestProcessVo"/>
        where  pprp.prototype_request_id = #{prototypeRequestId}
    </select>

    <insert id="insertProPrototypeRequestProcess" parameterType="ProPrototypeRequestProcess" useGeneratedKeys="true"
            keyProperty="prototypeRequestProcessId">
        insert into pro_prototype_request_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prototypeRequestId != null">prototype_request_id,</if>
            <if test="recordId != null">record_id,</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>
            <if test="workstationId != null">workstation_id,</if>
            <if test="stdWorkingTime != null">std_working_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="prototypeRequestId != null">#{prototypeRequestId},</if>
            <if test="recordId != null">#{recordId},</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>
            <if test="workstationId != null">#{workstationId},</if>
            <if test="stdWorkingTime != null">#{stdWorkingTime},</if>
        </trim>
    </insert>

    <update id="updateProPrototypeRequestProcess" parameterType="ProPrototypeRequestProcess">
        update pro_prototype_request_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="prototypeRequestId != null">prototype_request_id = #{prototypeRequestId},</if>
            <if test="recordId != null">record_id = #{recordId},</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>
            <if test="workstationId != null">workstation_id = #{workstationId},</if>
            <if test="stdWorkingTime != null">std_working_time = #{stdWorkingTime},</if>
        </trim>
        where prototype_request_process_id = #{prototypeRequestProcessId}
    </update>

    <delete id="deleteProPrototypeRequestProcessByPrototypeRequestProcessId" parameterType="Long">
        delete
        from pro_prototype_request_process
        where prototype_request_process_id = #{prototypeRequestProcessId}
    </delete>

    <delete id="deleteProPrototypeRequestProcessByPrototypeRequestProcessIds" parameterType="String">
        delete from pro_prototype_request_process where prototype_request_process_id in
        <foreach item="prototypeRequestProcessId" collection="array" open="(" separator="," close=")">
            #{prototypeRequestProcessId}
        </foreach>
    </delete>
</mapper>
