<?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.cmvr.inspection.mapper.InspectionTaskWaypointMapper">

    <resultMap type="InspectionTaskWaypoint" id="InspectionTaskWaypointResult">
        <result property="taskId"    column="task_id"    />
        <result property="waypointId"    column="waypoint_id"    />
        <result property="sortOrder"    column="sort_order"    />
    </resultMap>

    <select id="selectWaypointsByTaskId" parameterType="String" resultType="InspectionWaypoint">
        select w.id, w.create_by, w.create_time, w.update_by, w.update_time, w.remark,
               w.waypoint_name, w.enabled, w.sort_order, w.detect_item_id
        from inspection_task_waypoint tw
        inner join inspection_waypoint w on tw.waypoint_id = w.id
        where tw.task_id = #{taskId}
        order by tw.sort_order
    </select>

    <select id="selectTaskIdsByWaypointId" parameterType="String" resultType="String">
        select task_id from inspection_task_waypoint where waypoint_id = #{waypointId}
    </select>

    <insert id="batchInsertTaskWaypoint" parameterType="java.util.List">
        insert into inspection_task_waypoint (task_id, waypoint_id, sort_order) values
        <foreach item="item" collection="list" separator=",">
            (#{item.taskId}, #{item.waypointId}, #{item.sortOrder})
        </foreach>
    </insert>

    <delete id="deleteTaskWaypointByTaskId" parameterType="String">
        delete from inspection_task_waypoint where task_id = #{taskId}
    </delete>

    <delete id="deleteTaskWaypointByWaypointId" parameterType="String">
        delete from inspection_task_waypoint where waypoint_id = #{waypointId}
    </delete>

    <delete id="deleteTaskWaypointByTaskIds" parameterType="String">
        delete from inspection_task_waypoint where task_id in
        <foreach item="taskId" collection="array" open="(" separator="," close=")">
            #{taskId}
        </foreach>
    </delete>

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