<?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.FlightPathsMapper">

    <resultMap type="FlightPaths" id="FlightPathsResult">
        <result property="id"    column="id"/>
        <result property="fileName"    column="file_name"/>
        <result property="fileUrl"    column="file_url"/>
        <result property="fileMd5"    column="file_md5"/>
        <result property="photoNum"    column="photo_num"/>
        <result property="waylineLen"    column="wayline_len"/>
        <result property="flag"    column="flag"/>
        <result property="estimateTime"    column="estimate_time"/>
        <result property="createdAt"    column="created_at"/>
        <result property="updatedAt"    column="updated_at"/>
        <result property="type"    column="type"/>
        <result property="deviceType" column="device_type"/>
        <result property="points"    column="points"/>
        <result property="isImport"    column="is_import"/>
        <result property="globalPointHeight"    column="global_point_height"/>
    </resultMap>

    <sql id="selectFlightPathsVo">
        select id,
               file_name,
               file_url,
               file_md5,
               photo_num,
               wayline_len,
               flag,
               estimate_time,
               created_at,
               updated_at,
               type,
               device_type,
               points,
               is_import,
               global_point_height
        from flight_paths
    </sql>

    <select id="selectFlightPathsList" parameterType="FlightPaths" resultMap="FlightPathsResult">
        <include refid="selectFlightPathsVo"/>
        <where>
            <if test="fileName != null  and fileName != ''">and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileUrl != null  and fileUrl != ''">and file_url = #{fileUrl}</if>
            <if test="fileMd5 != null  and fileMd5 != ''">and file_md5 = #{fileMd5}</if>
            <if test="photoNum != null ">and photo_num = #{photoNum}</if>
            <if test="waylineLen != null  and waylineLen != ''">and wayline_len = #{waylineLen}</if>
            <if test="flag != null  and flag != ''">and flag = #{flag}</if>
            <if test="estimateTime != null  and estimateTime != ''">and estimate_time = #{estimateTime}</if>
            <if test="createdAt != null ">and created_at = #{createdAt}</if>
            <if test="updatedAt != null ">and updated_at = #{updatedAt}</if>
            <if test="type != null ">and type = #{type}</if>
            <if test="deviceType != null">and device_type = #{deviceType}</if>
            <if test="points != null  and points != ''">and points = #{points}</if>
            <if test="isImport != null  and isImport != ''">and is_import = #{isImport}</if>
            <if test="globalPointHeight != null">and global_point_height = #{globalPointHeight}</if>
        </where>
        order by
        <choose>
            <when test="order == 1">updated_at desc</when>
            <otherwise>updated_at asc</otherwise>
        </choose>
    </select>

    <select id="selectFlightPathsById" parameterType="Long" resultMap="FlightPathsResult">
        <include refid="selectFlightPathsVo"/>
        where id = #{id}
    </select>

    <select id="selectByCondition" resultType="com.ruoyi.system.domain.FlightPaths">
        <include refid="selectFlightPathsVo"/>
        <where>
            <if test="fileName != null  and fileName != ''">and file_name = #{fileName}</if>
            <if test="fileUrl != null  and fileUrl != ''">and file_url = #{fileUrl}</if>
            <if test="fileMd5 != null  and fileMd5 != ''">and file_md5 = #{fileMd5}</if>
            <if test="photoNum != null ">and photo_num = #{photoNum}</if>
            <if test="waylineLen != null  and waylineLen != ''">and wayline_len = #{waylineLen}</if>
            <if test="flag != null  and flag != ''">and flag = #{flag}</if>
            <if test="estimateTime != null  and estimateTime != ''">and estimate_time = #{estimateTime}</if>
            <if test="createdAt != null ">and created_at = #{createdAt}</if>
            <if test="updatedAt != null ">and updated_at = #{updatedAt}</if>
            <if test="type != null ">and type = #{type}</if>
            <if test="deviceType != null">and device_type = #{deviceType}</if>
            <if test="points != null  and points != ''">and points = #{points}</if>
            <if test="isImport != null  and isImport != ''">and is_import = #{isImport}</if>
            <if test="globalPointHeight != null">and global_point_height = #{globalPointHeight}</if>
        </where>
        order by
        <choose>
            <when test="order == 1">updated_at desc</when>
            <otherwise>updated_at asc</otherwise>
        </choose>
    </select>

    <insert id="insertFlightPaths" parameterType="FlightPaths" useGeneratedKeys="true" keyProperty="id">
        insert into flight_paths
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileName != null and fileName != ''">file_name,</if>
            <if test="fileUrl != null and fileUrl != ''">file_url,</if>
            <if test="fileMd5 != null and fileMd5 != ''">file_md5,</if>
            <if test="photoNum != null">photo_num,</if>
            <if test="waylineLen != null">wayline_len,</if>
            <if test="flag != null">flag,</if>
            <if test="estimateTime != null">estimate_time,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="type != null">type,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="points != null">points,</if>
            <if test="isImport != null">is_import,</if>
            <if test="globalPointHeight != null">global_point_height,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileName != null and fileName != ''">#{fileName},</if>
            <if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
            <if test="fileMd5 != null and fileMd5 != ''">#{fileMd5},</if>
            <if test="photoNum != null">#{photoNum},</if>
            <if test="waylineLen != null">#{waylineLen},</if>
            <if test="flag != null">#{flag},</if>
            <if test="estimateTime != null">#{estimateTime},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="type != null">#{type},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="points != null">#{points},</if>
            <if test="isImport != null">#{isImport},</if>
            <if test="globalPointHeight != null">#{globalPointHeight},</if>
        </trim>
    </insert>

    <update id="updateFlightPaths" parameterType="FlightPaths">
        update flight_paths
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
            <if test="fileUrl != null and fileUrl != ''">file_url = #{fileUrl},</if>
            <if test="fileMd5 != null and fileMd5 != ''">file_md5 = #{fileMd5},</if>
            <if test="photoNum != null">photo_num = #{photoNum},</if>
            <if test="waylineLen != null">wayline_len = #{waylineLen},</if>
            <if test="flag != null">flag = #{flag},</if>
            <if test="estimateTime != null">estimate_time = #{estimateTime},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="type != null">type = #{type},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="points != null">points = #{points},</if>
            <if test="isImport != null">is_import = #{isImport},</if>
            <if test="globalPointHeight != null">global_point_height = #{globalPointHeight},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFlightPathsById" parameterType="Long">
        delete from flight_paths where id = #{id}
    </delete>

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