<?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.task.ProTaskAssistProcessMapper">

    <resultMap type="com.ximai.mes.pro.domain.task.ProTaskAssistProcess" id="ProTaskAssistprocessResult">
        <result property="id" column="id"/>
        <result property="assistProcessCode" column="assist_process_code"/>
        <result property="assistProcessItemCode" column="assist_process_item_code"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="workunitName" column="workunit_name"/>
        <result property="workunitId" column="workunit_id"/>
        <result property="supplierName" column="supplier_name"/>
        <result property="scheduleEndDate" column="schedule_end_date"/>
        <result property="processId" column="process_id"/>
        <result property="processCode" column="process_code"/>
        <result property="taskId" column="task_id"/>
        <result property="taskCode" column="task_code"/>
        <result property="workorderId" column="workorder_id"/>
        <result property="workorderCode" column="workorder_code"/>
        <result property="returnTime" column="return_time"/>
        <result property="quantity" column="quantity"/>
        <result property="workorderProcessId" column="workorder_process_id"/>
        <result property="closeType" column="close_type"/>
        <result property="remark" column="remark"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="deleteState" column="delete_state"/>
        <result property="idx" column="delete_state"/>
    </resultMap>

    <sql id="selectProTaskAssistprocessVo">
        select id,
               assist_process_code,
               assist_process_item_code,
               idx,
               workorder_process_id,
               workstation_id,
               workunit_name,
               workunit_id,
               process_code,
               process_id,
               task_id,
               task_code,
               task_workunit_id,
               workorder_id,
               workorder_code,
               return_time,
               quantity,
               unit,
               supplier_name,
               schedule_end_date,
               source_task_workunits,
               close_type,
               remark,
               create_time,
               update_time,
               create_by,
               update_by
        from pro_task_assist_process
    </sql>


    <select id="selectProTaskAssistProcessByObj" resultMap="ProTaskAssistprocessResult">
        select id,
        assist_process_code,
        assist_process_item_code,
        idx,
        workorder_process_id,
        task_workunit_id,
        workstation_id,
        workunit_name,
        workunit_id,
        process_code,
        process_id,
        task_id,
        task_code,
        workorder_id,
        workorder_code,
        return_time,
        quantity,
        close_type,
        unit,
        remark,
        supplier_name,
        schedule_end_date,
        create_time,
        update_time,
        create_by,
        update_by
        from pro_task_assist_process
        <where>
            <if test="processId != null ">and process_id = #{processId}</if>
            <if test="processName != null ">and process_id = (select process_id from pro_process where process_name =
                #{processName} )
            </if>
            <if test="workorderId != null ">and workorder_id = #{workorderId}</if>
            <if test="workorderCode != null ">and workorder_code = #{workorderCode}</if>
            <if test="assistProcessCode != null ">and assist_process_code = #{assistProcessCode}</if>
        </where>
    </select>


    <select id="selectProTaskAssistProcessById" parameterType="Long" resultMap="ProTaskAssistprocessResult">
        <include refid="selectProTaskAssistprocessVo"/>
        where id = #{id}
    </select>

    <insert id="insertProTaskAssistprocess" parameterType="ProTaskAssistProcess" useGeneratedKeys="true"
            keyProperty="id">
        insert into pro_task_assist_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="assistProcessCode != null">assist_process_code,</if>
            <if test="scheduleEndDate != null">schedule_end_date,</if>
            <if test="supplierName != null">supplier_name,</if>
            <if test="workstationId != null">workstation_id,</if>
            <if test="workunitName != null">workunit_name,</if>
            <if test="workunitId != null">workunit_id,</if>
            <if test="processId != null">process_id,</if>
            <if test="taskWorkunitId != null">task_workunit_id,</if>
            <if test="taskId != null">task_id,</if>
            <if test="taskCode != null">task_code,</if>
            <if test="returnTime != null">return_time,</if>
            <if test="quantity != null">quantity,</if>
            <if test="workorderProcessId != null">workorder_process_id,</if>
            <if test="assistProcessItemCode != null">assist_process_item_code,</if>
            <if test="processCode != null">process_code,</if>
            <if test="workorderId != null">workorder_id,</if>
            <if test="workorderCode != null">workorder_code,</if>
            <if test="unit != null">unit,</if>
            <if test="closeType != null">close_type,</if>
            <if test="remark != null">remark,</if>
            <if test="idx != null">idx,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="assistProcessCode != null">#{assistProcessCode},</if>
            <if test="scheduleEndDate != null">#{scheduleEndDate},</if>
            <if test="supplierName != null">#{supplierName},</if>
            <if test="workstationId != null">#{workstationId},</if>
            <if test="workunitName != null">#{workunitName},</if>
            <if test="workunitId != null">#{workunitId},</if>
            <if test="processId != null">#{processId},</if>
            <if test="taskWorkunitId != null">#{taskWorkunitId},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="returnTime != null">#{returnTime},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="workorderProcessId != null">#{workorderProcessId},</if>
            <if test="assistProcessItemCode != null">#{assistProcessItemCode},</if>
            <if test="processCode != null">#{processCode},</if>
            <if test="workorderId != null">#{workorderId},</if>
            <if test="workorderCode != null">#{workorderCode},</if>
            <if test="unit != null">#{unit},</if>
            <if test="closeType != null">#{closeType},</if>
            <if test="remark != null">#{remark},</if>
            <if test="idx != null">#{idx},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateProTaskAssistProcess" parameterType="ProTaskAssistProcess">
        update pro_task_assist_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="assistProcessCode != null">assist_process_code = #{assistProcessCode},</if>
            <if test="scheduleEndDate != null">schedule_end_date = #{scheduleEndDate},</if>
            <if test="supplierName != null">supplier_name = #{supplierName},</if>
            <if test="workstationId != null">workstation_id = #{workstationId},</if>
            <if test="workunitName != null">workunit_name = #{workunitName},</if>
            <if test="workunitId != null">workunit_id = #{workunitId},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="taskWorkunitId != null">task_workunit_id = #{taskWorkunitId},</if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskCode != null">task_code = #{taskCode},</if>
            <if test="returnTime != null">return_time = #{returnTime},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="workorderProcessId != null">workorder_process_id = #{workorderProcessId},</if>
            <if test="assistProcessItemCode != null">assist_process_item_code=#{assistProcessItemCode},</if>
            <if test="processCode != null">process_code = #{processCode},</if>
            <if test="workorderId != null">workorder_id = #{workorderId},</if>
            <if test="workorderCode != null">workorder_code = #{workorderCode},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="closeType != null">close_type = #{closeType},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="idx != null">idx = #{idx},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProTaskAssistProcessById" parameterType="Long">
        --         delete
--         from pro_task_assist_process
--         where id = #{id}

        update pro_task_assist_process
        set delete_state = 1
        where id = #{id}
    </delete>


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