<?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.UavpsAlgorithmTaskMapper">
    
    <resultMap type="UavpsAlgorithmTask" id="UavpsAlgorithmTaskResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="uavId"    column="uav_id"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <association property="uav" resultMap="uavResult" />
    </resultMap>

    <resultMap id="uavResult" type="com.uavps.system.domain.UavpsUnmannedAerialVehicle">
        <id     property="id"    column="uav_id"     />
        <result property="name"  column="uav_name"   />
    </resultMap>

    <sql id="selectUavpsAlgorithmTaskVo">
        select t.id, t.name, t.uav_id, u.name as uav_name, t.remark, t.create_by, t.create_time, t.update_by, t.update_time
          from uavps_algorithm_task t
     left join uavps_unmanned_aerial_vehicle u on u.id = t.uav_id
    </sql>

    <select id="selectUavpsAlgorithmTaskList" parameterType="UavpsAlgorithmTask" resultMap="UavpsAlgorithmTaskResult">
        <include refid="selectUavpsAlgorithmTaskVo"/>
        <where>  
            <if test="name != null  and name != ''"> and t.name like concat('%', #{name}, '%')</if>
            <if test="uavId != null "> and t.uav_id = #{uavId}</if>
        </where>
    </select>
    
    <select id="selectUavpsAlgorithmTaskById" parameterType="Long" resultMap="UavpsAlgorithmTaskResult">
        <include refid="selectUavpsAlgorithmTaskVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertUavpsAlgorithmTask" parameterType="UavpsAlgorithmTask" useGeneratedKeys="true" keyProperty="id">
        insert into uavps_algorithm_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="uavId != null">uav_id,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="uavId != null">#{uavId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateUavpsAlgorithmTask" parameterType="UavpsAlgorithmTask">
        update uavps_algorithm_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="uavId != null">uav_id = #{uavId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUavpsAlgorithmTaskById" parameterType="Long">
        delete from uavps_algorithm_task where id = #{id}
    </delete>

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