<?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.prototypeMake.ProPrototypeMakeProcessMapper">

    <resultMap type="ProPrototypeMakeProcessVo" id="ProPrototypeMakeProcessResult">
        <id property="prototypeMakeProcessId" column="prototype_make_process_id"/>
        <result property="prototypeMakeId" column="prototype_make_id"/>
        <result property="recordId" column="record_id"/>
        <result property="processId" column="process_id"/>
        <result property="processName" column="process_name"/>
        <result property="processCode" column="process_code"/>
        <result property="nextProcessName" column="next_process_name"/>
        <result property="linkType" column="link_type"/>
        <result property="colorCode" column="color_code"/>
        <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="workstationName" column="workstation_name"/>
    </resultMap>

    <sql id="selectProPrototypeMakeProcessVo">
        select ppmp.prototype_make_process_id,
               ppmp.prototype_make_id,
               ppmp.record_id,
               ppmp.workstation_id,
               ppmp.std_working_time,
               ppmp.default_pre_time,
               ppmp.default_suf_time,
               ppmp.key_flag,
               ppmp.is_check,
               ppmp.remark,
               prp.process_name,
               prp.process_code,
               prp.next_process_name,
               prp.color_code,
               prp.link_type,
               prp.process_id,
               mw.workstation_name
        from pro_prototype_make_process ppmp
                 left join pro_route_process prp on ppmp.record_id = prp.record_id
                 left join md_workstation mw on ppmp.workstation_id = mw.workstation_id
    </sql>

    <select id="selectProPrototypeMakeProcessList" parameterType="ProPrototypeMakeProcess"
            resultMap="ProPrototypeMakeProcessResult">
        <include refid="selectProPrototypeMakeProcessVo"/>
        <where>
            <if test="prototypeMakeId != null ">and ppmp.prototype_make_id = #{prototypeMakeId}</if>
            <if test="recordId != null ">and ppmp.record_id = #{recordId}</if>
            <if test="workstationId != null ">and ppmp.workstation_id = #{workstationId}</if>
            <if test="workstationName != null ">and ppmp.workstation_name = #{workstationName}</if>
            <if test="stdWorkingTime != null ">and ppmp.std_working_time = #{stdWorkingTime}</if>
            <if test="defaultPreTime != null ">and ppmp.default_pre_time = #{defaultPreTime}</if>
            <if test="defaultSufTime != null ">and ppmp.default_suf_time = #{defaultSufTime}</if>
            <if test="keyFlag != null  and keyFlag != ''">and ppmp.key_flag = #{keyFlag}</if>
            <if test="isCheck != null  and isCheck != ''">and ppmp.is_check = #{isCheck}</if>
        </where>
    </select>

    <select id="selectProPrototypeMakeProcessByPrototypeMakeProcessId" parameterType="Long"
            resultMap="ProPrototypeMakeProcessResult">
        <include refid="selectProPrototypeMakeProcessVo"/>
        where ppmp.prototype_make_process_id = #{prototypeMakeProcessId}
    </select>

    <select id="selectProPrototypeMakeProcessByPrototypeMakeId"
            parameterType="Long" resultMap="ProPrototypeMakeProcessResult">
        <include refid="selectProPrototypeMakeProcessVo"/>
        where  ppmp.prototype_make_id = #{prototypeMakeId}
    </select>
    <insert id="insertProPrototypeMakeProcess" parameterType="ProPrototypeMakeProcess" useGeneratedKeys="true"
            keyProperty="prototypeMakeProcessId">
        insert into pro_prototype_make_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prototypeMakeId != null">prototype_make_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="prototypeMakeId != null">#{prototypeMakeId},</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="updateProPrototypeMakeProcess" parameterType="ProPrototypeMakeProcess">
        update pro_prototype_make_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="prototypeMakeId != null">prototype_make_id = #{prototypeMakeId},</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 prototype_make_process_id = #{prototypeMakeProcessId}
    </update>

    <delete id="deleteProPrototypeMakeProcessByPrototypeMakeProcessId" parameterType="Long">
        delete
        from pro_prototype_make_process
        where prototype_make_process_id = #{prototypeMakeProcessId}
    </delete>

    <delete id="deleteProPrototypeMakeProcessByPrototypeMakeProcessIds" parameterType="String">
        delete from pro_prototype_make_process where prototype_make_process_id in
        <foreach item="prototypeMakeProcessId" collection="array" open="(" separator="," close=")">
            #{prototypeMakeProcessId}
        </foreach>
    </delete>
</mapper>
