<?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.productionMake.ProProductionMakeProcessMapper">

    <resultMap type="ProProductionMakeProcess" id="ProProductionMakeProcessResult">
        <result property="productionMakeProcessId"    column="production_make_process_id"    />
        <result property="productionMakeId"    column="production_make_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="nextProcessName" column="next_process_name"/>
        <result property="linkType" column="link_type"/>
        <result property="colorCode" column="color_code"/>
        <result property="workstationName" column="workstation_name"/>
    </resultMap>

    <sql id="selectProProductionMakeProcessVo">
        select t1.*,mw.workstation_name,prp.process_name,
               prp.process_code,
               prp.next_process_name,
               prp.color_code,
               prp.link_type from pro_production_make_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="selectProProductionMakeProcessList" parameterType="ProProductionMakeProcess" resultMap="ProProductionMakeProcessResult">
        <include refid="selectProProductionMakeProcessVo"/>
        <where>
            <if test="productionMakeId != null "> and production_make_id = #{productionMakeId}</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="selectProProductionMakeProcessByProductionMakeProcessId" parameterType="Long" resultMap="ProProductionMakeProcessResult">
        <include refid="selectProProductionMakeProcessVo"/>
        where production_make_process_id = #{productionMakeProcessId}
    </select>

    <insert id="insertProProductionMakeProcess" parameterType="ProProductionMakeProcess" useGeneratedKeys="true" keyProperty="productionMakeProcessId">
        insert into pro_production_make_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="productionMakeId != null">production_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="productionMakeId != null">#{productionMakeId},</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="updateProProductionMakeProcess" parameterType="ProProductionMakeProcess">
        update pro_production_make_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="productionMakeId != null">production_make_id = #{productionMakeId},</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_make_process_id = #{productionMakeProcessId}
    </update>

    <delete id="deleteProProductionMakeProcessByProductionMakeProcessId" parameterType="Long">
        delete from pro_production_make_process where production_make_process_id = #{productionMakeProcessId}
    </delete>

    <delete id="deleteProProductionMakeProcessByProductionMakeId" parameterType="Long">
        delete from pro_production_make_process where production_make_id = #{productionMakeId}
    </delete>

    <delete id="deleteProProductionMakeProcessByProductionMakeProcessIds" parameterType="String">
        delete from pro_production_make_process where production_make_process_id in
        <foreach item="productionMakeProcessId" collection="array" open="(" separator="," close=")">
            #{productionMakeProcessId}
        </foreach>
    </delete>
</mapper>
