<?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.djhk.uav.tfly.mapper.TFlyMapper">
    
    <resultMap type="com.djhk.uav.tfly.model.TFly" id="TFlyResult">
        <result property="flySeq"    column="fly_seq"    />
        <result property="deptId"    column="dept_id"    />
        <result property="equSn"    column="equ_sn"    />
        <result property="begTime"    column="beg_time"    />
        <result property="begLocLon"    column="beg_loc_lon"    />
        <result property="begLocLat"    column="beg_loc_lat"    />
        <result property="flySts"    column="fly_sts"    />
        <result property="endTime"    column="end_time"    />
        <result property="endLocLon"    column="end_loc_lon"    />
        <result property="endLocLat"    column="end_loc_lat"    />
        <result property="orderid"    column="orderid"    />
        <result property="planCode"    column="plan_code"    />
    </resultMap>

    <sql id="selectTFlyVo">
        select fly_seq, dept_id, equ_sn, beg_time, beg_loc_lon, beg_loc_lat, fly_sts, end_time, end_loc_lon, end_loc_lat, orderid, plan_code from t_fly
    </sql>

    <select id="selectTFlyList" parameterType="com.djhk.uav.tfly.model.TFly" resultMap="TFlyResult">
        <include refid="selectTFlyVo"/>
        <where>  
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="equSn != null  and equSn != ''"> and equ_sn like concat('%',#{equSn},'%') </if>

            <if test="flySts != null  and flySts != ''"> and fly_sts = #{flySts}</if>

            <if test="orderid != null  and orderid != ''"> and orderid like concat('%',#{orderid},'%')</if>
            <if test="planCode != null  and planCode != ''"> and plan_code like concat('%',#{planCode},'%')</if>

            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                 and date_format(beg_time,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{params.beginTime},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                 and date_format(beg_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{params.endTime},'%Y-%m-%d %H:%i:%s')
            </if>

        </where>
        order by beg_time desc
    </select>
    
    <select id="selectTFlyByFlySeq" parameterType="String" resultMap="TFlyResult">
        <include refid="selectTFlyVo"/>
        where fly_seq = #{flySeq}
    </select>


</mapper>