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

    <resultMap type="ProStartWork" id="ProStartWorkResult">
        <result property="startWorkId" column="start_work_id"/>
        <result property="taskId" column="task_id"/>
        <result property="taskWorkunitId" column="task_workunit_Id"/>
        <result property="workunitId" column="workunit_id"/>
        <result property="arrangeCode" column="arrange_code"/>
        <result property="recordType" column="record_type"/>
        <result property="startDate" column="start_date"/>
        <result property="endDate" column="end_date"/>
        <result property="workTimeSec" column="work_time_sec"/>
        <result property="breakTimeSec" column="break_time_sec"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="idx" column="idx"/>
        <result property="pauseType" column="pause_type"/>
        <result property="abnormalReason" column="abnormal_reason"/>
        <result property="abnormalDescribe" column="abnormal_describe"/>

    </resultMap>

    <sql id="selectProStartWorkVo">
        select start_work_id,
               task_id,
               task_workunit_Id,
               idx,
               arrange_code,
               pause_type,
               abnormal_reason,
               abnormal_describe,
               workunit_id,
               record_type,
               work_time_sec,
               break_time_sec,
               start_date,
               end_date,
               create_by,
               create_time,
               update_by,
               update_time
        from pro_start_work
    </sql>

    <select id="selectProStartWorkList" parameterType="ProStartWork" resultMap="ProStartWorkResult">
        <include refid="selectProStartWorkVo"/>
        <where>
            <if test="taskId != null ">and task_id = #{taskId}</if>
            <if test="taskWorkunitId != null ">and task_workunit_Id = #{taskWorkunitId}</if>
            <if test="workunitId != null ">and workunit_id = #{workunitId}</if>
            <if test="idx != null ">and idx = #{idx}</if>

        </where>
    </select>

    <select id="selectProStartWorkByStartWorkId" parameterType="Long" resultMap="ProStartWorkResult">
        <include refid="selectProStartWorkVo"/>
        where start_work_id = #{startWorkId}
    </select>

    <insert id="insertProStartWork" parameterType="ProStartWork">
        insert into pro_start_work
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="startWorkId != null">start_work_id,</if>
            <if test="taskId != null">task_id,</if>
            <if test="taskWorkunitId != null">task_workunit_Id,</if>
            <if test="workunitId != null">workunit_id,</if>
            <if test="idx != null ">idx,</if>
            <if test="arrangeCode != null ">arrange_code,</if>
            <if test="pauseType != null ">pause_type,</if>
            <if test="abnormalReason != null ">abnormal_reason,</if>
            <if test="abnormalDescribe != null ">abnormal_describe,</if>
            <if test="recordType != null">record_type,</if>
            <if test="recordUuid != null">record_uuid,</if>
            <if test="workTimeSec != null">work_time_sec,</if>
            <if test="breakTimeSec != null">break_time_sec,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="startWorkId != null">#{startWorkId},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="taskWorkunitId != null">#{taskWorkunitId},</if>
            <if test="workunitId != null">#{workunitId},</if>
            <if test="idx != null ">#{idx},</if>
            <if test="arrangeCode != null ">#{arrangeCode},</if>
            <if test="pauseType != null ">#{pauseType},</if>
            <if test="abnormalReason != null ">#{abnormalReason},</if>
            <if test="abnormalDescribe != null ">#{abnormalDescribe},</if>
            <if test="recordType != null">#{recordType},</if>
            <if test="recordUuid != null">#{recordUuid},</if>
            <if test="workTimeSec != null">#{workTimeSec},</if>
            <if test="breakTimeSec != null">#{breakTimeSec},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateProStartWork" parameterType="ProStartWork">
        update pro_start_work
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskWorkunitId != null">task_workunit_Id = #{taskWorkunitId},</if>
            <if test="workunitId != null">workunit_id = #{workunitId},</if>
            <if test="idx != null ">idx=#{idx},</if>
            <if test="arrangeCode != null ">arrange_code=#{arrangeCode},</if>
            <if test="pauseType != null ">pause_type=#{pauseType},</if>
            <if test="abnormalReason != null ">abnormal_reason=#{abnormalReason},</if>
            <if test="abnormalDescribe != null ">abnormal_describe=#{abnormalDescribe},</if>
            <if test="recordType != null">record_type=#{recordType},</if>
            <if test="workTimeSec != null">work_time_sec=#{workTimeSec},</if>
            <if test="breakTimeSec != null">break_time_sec=#{breakTimeSec},</if>
            <if test="startDate != null">start_date=#{startDate},</if>
            <if test="endDate != null">end_date=#{endDate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="recordUuid != null">record_uuid=#{recordUuid},</if>

        </trim>
        where start_work_id = #{startWorkId}
    </update>

    <delete id="deleteProStartWorkByStartWorkId" parameterType="Long">
        delete
        from pro_start_work
        where start_work_id = #{startWorkId}
    </delete>

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