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

    <resultMap type="com.ximai.mes.pro.domain.ProPauseWork" id="ProPauseWorkResult">
        <result property="pauseWorkId" column="pause_work_id"/>
        <result property="taskId" column="task_id"/>
        <result property="taskWorkunitId" column="task_workunit_Id"/>
        <result property="workunitId" column="workunit_id"/>
        <result property="abnormalReason" column="abnormal_reason"/>
        <result property="abnormalDescribe" column="abnormal_describe"/>
        <result property="pauseNum" column="pause_num"/>
        <result property="pauseType" column="pause_type"/>
        <result property="attr1" column="attr1"/>
        <result property="attr2" column="attr2"/>
        <result property="attr3" column="attr3"/>
        <result property="attr4" column="attr4"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectProPauseWorkVo">
        select pause_work_id,
               task_id,
               task_workunit_Id,
               workunit_id,
               abnormal_reason,
               abnormal_describe,
               pause_num,
               pause_type,
               attr1,
               attr2,
               attr3,
               attr4,
               create_by,
               create_time,
               update_by,
               update_time
        from pro_pause_work
    </sql>

    <select id="selectProPauseWorkList" parameterType="com.ximai.mes.pro.domain.ProPauseWork"
            resultMap="ProPauseWorkResult">
        <include refid="selectProPauseWorkVo"/>
        <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="abnormalReason != null  and abnormalReason != ''">and abnormal_reason = #{abnormalReason}</if>
            <if test="abnormalDescribe != null  and abnormalDescribe != ''">and abnormal_describe =
                #{abnormalDescribe}
            </if>
            <if test="pauseNum != null ">and pause_num = #{pauseNum}</if>
            <if test="pauseType != null ">and pause_type = #{pauseType}</if>
            <if test="attr1 != null  and attr1 != ''">and attr1 = #{attr1}</if>
            <if test="attr2 != null  and attr2 != ''">and attr2 = #{attr2}</if>
            <if test="attr3 != null ">and attr3 = #{attr3}</if>
            <if test="attr4 != null ">and attr4 = #{attr4}</if>
        </where>
    </select>

    <select id="selectProPauseWorkByPauseWorkId" parameterType="Long" resultMap="ProPauseWorkResult">
        <include refid="selectProPauseWorkVo"/>
        where pause_work_id = #{pauseWorkId}
    </select>

    <insert id="insertProPauseWork" parameterType="com.ximai.mes.pro.domain.ProPauseWork" useGeneratedKeys="true"
            keyProperty="pauseWorkId">
        insert into pro_pause_work
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="taskWorkunitId != null">task_workunit_Id,</if>
            <if test="workunitId != null">workunit_id,</if>
            <if test="abnormalReason != null">abnormal_reason,</if>
            <if test="abnormalDescribe != null">abnormal_describe,</if>
            <if test="pauseNum != null">pause_num,</if>
            <if test="pauseType != null">pause_type,</if>
            <if test="attr1 != null">attr1,</if>
            <if test="attr2 != null">attr2,</if>
            <if test="attr3 != null">attr3,</if>
            <if test="attr4 != null">attr4,</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="taskId != null">#{taskId},</if>
            <if test="taskWorkunitId != null">#{taskWorkunitId},</if>
            <if test="workunitId != null">#{workunitId},</if>
            <if test="abnormalReason != null">#{abnormalReason},</if>
            <if test="abnormalDescribe != null">#{abnormalDescribe},</if>
            <if test="pauseNum != null">#{pauseNum},</if>
            <if test="pauseType != null">#{pauseType},</if>
            <if test="attr1 != null">#{attr1},</if>
            <if test="attr2 != null">#{attr2},</if>
            <if test="attr3 != null">#{attr3},</if>
            <if test="attr4 != null">#{attr4},</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="updateProPauseWork" parameterType="com.ximai.mes.pro.domain.ProPauseWork">
        update pro_pause_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="abnormalReason != null">abnormal_reason = #{abnormalReason},</if>
            <if test="abnormalDescribe != null">abnormal_describe = #{abnormalDescribe},</if>
            <if test="pauseNum != null">pause_num = #{pauseNum},</if>
            <if test="pauseType != null">pause_type = #{pauseType},</if>
            <if test="attr1 != null">attr1 = #{attr1},</if>
            <if test="attr2 != null">attr2 = #{attr2},</if>
            <if test="attr3 != null">attr3 = #{attr3},</if>
            <if test="attr4 != null">attr4 = #{attr4},</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>
        </trim>
        where pause_work_id = #{pauseWorkId}
    </update>

    <delete id="deleteProPauseWorkByPauseWorkId" parameterType="Long">
        delete
        from pro_pause_work
        where pause_work_id = #{pauseWorkId}
    </delete>

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