<?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.uavps.system.mapper.UavpsAlgorithmTaskFormationMapper">
    
    <resultMap type="UavpsAlgorithmTaskFormation" id="UavpsAlgorithmTaskFormationResult">
        <result property="algorithmTaskId"    column="algorithm_task_id"    />
        <result property="formationId"    column="formation_id"    />
    </resultMap>

    <sql id="selectUavpsAlgorithmTaskFormationVo">
        select algorithm_task_id, formation_id from uavps_algorithm_task_formation
    </sql>

    <select id="selectUavpsAlgorithmTaskFormationList" parameterType="UavpsAlgorithmTaskFormation" resultMap="UavpsAlgorithmTaskFormationResult">
        <include refid="selectUavpsAlgorithmTaskFormationVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectUavpsAlgorithmTaskFormationByAlgorithmTaskId" parameterType="Long" resultMap="UavpsAlgorithmTaskFormationResult">
        <include refid="selectUavpsAlgorithmTaskFormationVo"/>
        where algorithm_task_id = #{algorithmTaskId}
    </select>

    <insert id="insertUavpsAlgorithmTaskFormation" parameterType="UavpsAlgorithmTaskFormation">
        insert into uavps_algorithm_task_formation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="algorithmTaskId != null">algorithm_task_id,</if>
            <if test="formationId != null">formation_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="algorithmTaskId != null">#{algorithmTaskId},</if>
            <if test="formationId != null">#{formationId},</if>
         </trim>
    </insert>

    <update id="updateUavpsAlgorithmTaskFormation" parameterType="UavpsAlgorithmTaskFormation">
        update uavps_algorithm_task_formation
        <trim prefix="SET" suffixOverrides=",">
            <if test="formationId != null">formation_id = #{formationId},</if>
        </trim>
        where algorithm_task_id = #{algorithmTaskId}
    </update>

    <delete id="deleteUavpsAlgorithmTaskFormationByAlgorithmTaskId" parameterType="Long">
        delete from uavps_algorithm_task_formation where algorithm_task_id = #{algorithmTaskId}
    </delete>

    <delete id="deleteUavpsAlgorithmTaskFormationByAlgorithmTaskIds" parameterType="String">
        delete from uavps_algorithm_task_formation where algorithm_task_id in 
        <foreach item="algorithmTaskId" collection="array" open="(" separator="," close=")">
            #{algorithmTaskId}
        </foreach>
    </delete>

    <insert id="batchTaskFormation">
        insert into uavps_algorithm_task_formation(algorithm_task_id, formation_id) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.algorithmTaskId},#{item.formationId})
        </foreach>
    </insert>

    <delete id="deleteTaskFormationByTaskId" parameterType="Long">
        delete from uavps_algorithm_task_formation where algorithm_task_id = #{algorithmTaskId}
    </delete>

    <select id="selectFormationByTaskId" parameterType="Long" resultType="Long">
        select formation_id from uavps_algorithm_task_formation where algorithm_task_id = #{taskId}
    </select>

    <delete id="deleteTaskFormationByTaskIds" parameterType="Long">
        delete from uavps_algorithm_task_formation where algorithm_task_id in
        <foreach collection="array" item="taskId" open="(" separator="," close=")">
            #{taskId}
        </foreach>
    </delete>

    <select id="selectFormationListByTaskId" parameterType="Long" resultType="com.uavps.system.domain.UavpsMultiTargetFormation">
        SELECT b.* from uavps_algorithm_task_formation a left join uavps_multi_target_formation b on a.formation_id = b.id
        where a.algorithm_task_id = #{taskId}
    </select>
</mapper>