<?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.ruoyi.system.mapper.OneClickTakeoffMapper">
    
    <resultMap type="OneClickTakeoff" id="OneClickTakeoffResult">
        <result property="id"    column="id"    />
        <result property="droneSerialNumber"    column="drone_serial_number"    />
        <result property="takeoffTime"    column="takeoff_time"    />
        <result property="flightId"    column="flight_id"    />
    </resultMap>

    <sql id="selectOneClickTakeoffVo">
        select id, drone_serial_number, takeoff_time, flight_id from one_click_takeoff
    </sql>

    <select id="selectOneClickTakeoffList" parameterType="OneClickTakeoff" resultMap="OneClickTakeoffResult">
        <include refid="selectOneClickTakeoffVo"/>
        <where>  
            <if test="droneSerialNumber != null  and droneSerialNumber != ''"> and drone_serial_number = #{droneSerialNumber}</if>
            <if test="takeoffTime != null "> and takeoff_time = #{takeoffTime}</if>
            <if test="flightId != null "> and flight_id = #{flightId}</if>
        </where>
    </select>
    
    <select id="selectOneClickTakeoffById" parameterType="Long" resultMap="OneClickTakeoffResult">
        <include refid="selectOneClickTakeoffVo"/>
        where id = #{id}
    </select>

    <insert id="insertOneClickTakeoff" parameterType="OneClickTakeoff" useGeneratedKeys="true" keyProperty="id">
        insert into one_click_takeoff
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="droneSerialNumber != null and droneSerialNumber != ''">drone_serial_number,</if>
            <if test="takeoffTime != null">takeoff_time,</if>
            <if test="flightId != null">flight_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="droneSerialNumber != null and droneSerialNumber != ''">#{droneSerialNumber},</if>
            <if test="takeoffTime != null">#{takeoffTime},</if>
            <if test="flightId != null">#{flightId},</if>
         </trim>
    </insert>

    <update id="updateOneClickTakeoff" parameterType="OneClickTakeoff">
        update one_click_takeoff
        <trim prefix="SET" suffixOverrides=",">
            <if test="droneSerialNumber != null and droneSerialNumber != ''">drone_serial_number = #{droneSerialNumber},</if>
            <if test="takeoffTime != null">takeoff_time = #{takeoffTime},</if>
            <if test="flightId != null">flight_id = #{flightId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOneClickTakeoffById" parameterType="Long">
        delete from one_click_takeoff where id = #{id}
    </delete>

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