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

    <resultMap type="ProTaskWorkunitConvertRecord" id="ProTaskWorkunitConvertRecordResult">
        <result property="id"    column="id"    />
        <result property="taskWorkunitId"    column="task_workunit_id"    />
        <result property="newTaskWorkunitId"    column="new_task_workunit_id"    />
        <result property="quantity"    column="quantity"    />
        <result property="operateType"    column="operate_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <resultMap type="com.ximai.mes.pro.dto.task.ProTaskWorkunitConvertRecordDto" id="ProTaskWorkunitConvertRecordResult2">
        <result property="id"    column="id"    />
        <result property="taskWorkunitId"    column="task_workunit_id"    />
        <result property="newTaskWorkunitId"    column="new_task_workunit_id"    />
        <result property="quantity"    column="quantity"    />
        <result property="operateType"    column="operate_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectProTaskWorkunitConvertRecordVo">
        select id, task_workunit_id, new_task_workunit_id, quantity, operate_type, create_by, create_time, remark from pro_task_workunit_convert_record
    </sql>

    <select id="selectProTaskWorkunitConvertRecordList" parameterType="ProTaskWorkunitConvertRecord" resultMap="ProTaskWorkunitConvertRecordResult2">
        <include refid="selectProTaskWorkunitConvertRecordVo"/>
        <where>  
            <if test="taskWorkunitId != null "> and task_workunit_id = #{taskWorkunitId}</if>
            <if test="newTaskWorkunitId != null "> and new_task_workunit_id = #{newTaskWorkunitId}</if>
            <if test="quantity != null "> and quantity = #{quantity}</if>
            <if test="operateType != null "> and operate_type = #{operateType}</if>
        </where>
    </select>
    
    <select id="selectProTaskWorkunitConvertRecordById" parameterType="Long" resultMap="ProTaskWorkunitConvertRecordResult2">
        <include refid="selectProTaskWorkunitConvertRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertProTaskWorkunitConvertRecord" parameterType="ProTaskWorkunitConvertRecord" useGeneratedKeys="true" keyProperty="id">
        insert into pro_task_workunit_convert_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskWorkunitId != null">task_workunit_id,</if>
            <if test="newTaskWorkunitId != null">new_task_workunit_id,</if>
            <if test="quantity != null">quantity,</if>
            <if test="operateType != null">operate_type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskWorkunitId != null">#{taskWorkunitId},</if>
            <if test="newTaskWorkunitId != null">#{newTaskWorkunitId},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="operateType != null">#{operateType},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProTaskWorkunitConvertRecord" parameterType="ProTaskWorkunitConvertRecord">
        update pro_task_workunit_convert_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskWorkunitId != null">task_workunit_id = #{taskWorkunitId},</if>
            <if test="newTaskWorkunitId != null">new_task_workunit_id = #{newTaskWorkunitId},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="operateType != null">operate_type = #{operateType},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProTaskWorkunitConvertRecordById" parameterType="Long">
        delete from pro_task_workunit_convert_record where id = #{id}
    </delete>

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