<?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.fs.provider.mapper.ServiceOrderTaskRelMapper">
    
    <resultMap type="ServiceOrderTaskRel" id="ServiceOrderTaskRelResult">
        <result property="id"    column="id"    />
        <result property="serviceOrderId"    column="service_order_id"    />
        <result property="taskId"    column="task_id"    />
        <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="deleted"    column="deleted"    />
    </resultMap>

    <sql id="selectServiceOrderTaskRelVo">
        select id, service_order_id, task_id, create_time, update_time, create_by, update_by, deleted from service_order_task_rel
    </sql>

    <select id="selectServiceOrderTaskRelList" parameterType="ServiceOrderTaskRel" resultMap="ServiceOrderTaskRelResult">
        <include refid="selectServiceOrderTaskRelVo"/>
        <where>  
            <if test="serviceOrderId != null "> and service_order_id = #{serviceOrderId}</if>
            <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
            <if test="deleted != null "> and deleted = #{deleted}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectServiceOrderTaskRelById" parameterType="Long" resultMap="ServiceOrderTaskRelResult">
        <include refid="selectServiceOrderTaskRelVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertServiceOrderTaskRel" parameterType="ServiceOrderTaskRel" useGeneratedKeys="true" keyProperty="id">
        insert into service_order_task_rel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serviceOrderId != null">service_order_id,</if>
            <if test="taskId != null and taskId != ''">task_id,</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>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serviceOrderId != null">#{serviceOrderId},</if>
            <if test="taskId != null and taskId != ''">#{taskId},</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>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>

    <update id="updateServiceOrderTaskRel" parameterType="ServiceOrderTaskRel">
        update service_order_task_rel
        <trim prefix="SET" suffixOverrides=",">
            <if test="serviceOrderId != null">service_order_id = #{serviceOrderId},</if>
            <if test="taskId != null and taskId != ''">task_id = #{taskId},</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>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteServiceOrderTaskRelById" parameterType="Long">
        delete from service_order_task_rel where id = #{id}
    </delete>

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