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

    <resultMap type="ProTaskWorkorder" id="ProTaskWorkorderResult">
        <result property="taskWorkorderId"    column="task_workorder_id"    />
        <result property="taskId"    column="task_id"    />
        <result property="idx"    column="idx"    />
        <result property="workorderId"    column="workorder_id"    />
    </resultMap>

    <sql id="selectProTaskWorkorderVo">
        select task_workorder_id, task_id, idx, workorder_id from pro_task_workorder
    </sql>

    <select id="selectProTaskWorkorderList" parameterType="ProTaskWorkorder" resultMap="ProTaskWorkorderResult">
        <include refid="selectProTaskWorkorderVo"/>
        <where>
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="idx != null "> and idx = #{idx}</if>
            <if test="workorderId != null "> and workorder_id = #{workorderId}</if>
        </where>
    </select>

    <select id="selectProTaskWorkorderByTaskWorkorderId" parameterType="Long" resultMap="ProTaskWorkorderResult">
        <include refid="selectProTaskWorkorderVo"/>
        where task_workorder_id = #{taskWorkorderId}
    </select>

    <insert id="insertProTaskWorkorder" parameterType="ProTaskWorkorder" useGeneratedKeys="true" keyProperty="taskWorkorderId">
        insert into pro_task_workorder
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskId != null">task_id,</if>
            <if test="idx != null">idx,</if>
            <if test="workorderId != null">workorder_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskId != null">#{taskId},</if>
            <if test="idx != null">#{idx},</if>
            <if test="workorderId != null">#{workorderId},</if>
         </trim>
    </insert>

    <update id="updateProTaskWorkorder" parameterType="ProTaskWorkorder">
        update pro_task_workorder
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="idx != null">idx = #{idx},</if>
            <if test="workorderId != null">workorder_id = #{workorderId},</if>
        </trim>
        where task_workorder_id = #{taskWorkorderId}
    </update>

    <delete id="deleteProTaskWorkorderByTaskWorkorderId" parameterType="Long">
        delete from pro_task_workorder where task_workorder_id = #{taskWorkorderId}
    </delete>

    <delete id="deleteProTaskWorkorderByTaskWorkorderIds" parameterType="String">
        delete from pro_task_workorder where task_workorder_id in
        <foreach item="taskWorkorderId" collection="array" open="(" separator="," close=")">
            #{taskWorkorderId}
        </foreach>
    </delete>
    <delete id="deleteByTaskIds">
        delete from pro_task_workorder where task_id in
        <foreach item="taskId" collection="taskIds" open="(" separator="," close=")">
            #{taskId}
        </foreach>
    </delete>
</mapper>
