<?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.airspace.mapper.AirplaneMapper">

    <resultMap type="com.djhk.uav.airspace.domain.AirplaneApply" id="AirplaneApplyResult">
        <result column="id"         property="id"/>
        <result column="sts" property="sts"/>
        <result column="dept_id"  property="deptId"/>
        <result column="name"  property="name"/>
        <result column="type"  property="type"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="flyTime" column="fly_time"/>
        <result property="remark" column="remark"/>
        <result property="taskProp" column="task_prop"/>
        <result property="finalUrl" column="final_url"/>
        <result property="proUrl" column="pro_url"/>
    </resultMap>

    <sql id="selectAirplaneApplyVo">
        select id,
        sts,
        dept_id,
        name,
        create_by,
        create_time,
        fly_time,
        remark,
        task_prop,
        tel,
        final_url,
        pro_url,
        create_by
        from
        airplane_apply
    </sql>

    <select id="selectAirplaneApplyList" parameterType="com.djhk.uav.airspace.domain.AirplaneApply" resultMap="AirplaneApplyResult">
        <include refid="selectAirplaneApplyVo"/>
        <where>
            <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="createBy != null and createBy != ''"> and create_by like concat('%', #{createBy}, '%')</if>
            <if test="sts != null and sts != ''"> and sts = #{sts}</if>
            <if test="type != null and type != ''"> and type = #{type}</if>
            <if test="taskProp != null and taskProp != ''"> and task_prop = #{taskProp}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(fly_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(fly_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
            <if test="deptId != null and deptId != '' ">
                AND (dept_id = #{deptId} OR dept_id IN ( SELECT dept_id FROM sys_dept WHERE
                find_in_set(#{deptId}, ancestors) ))
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectAirplaneApplyLists" parameterType="com.djhk.uav.airspace.domain.AirplaneApply" resultMap="AirplaneApplyResult">
        <include refid="selectAirplaneApplyVo"/>
        <where>
            <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="createBy != null and createBy != ''"> and create_by like concat('%', #{createBy}, '%')</if>
            <if test="sts != null and sts != ''"> and sts = #{sts}</if>
            <if test="type != null and type != ''"> and type = #{type}</if>
            <if test="taskProp != null and taskProp != ''"> and task_prop = #{taskProp}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(fly_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(fly_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
        order by create_time asc
    </select>

    <select id="selectAirplaneApplyId" parameterType="Long" resultMap="AirplaneApplyResult">
        select max(id) as id
        from
        airplane_apply
    </select>

    <select id="selectAirplaneApplyById" parameterType="Long" resultMap="AirplaneApplyResult">
        <include refid="selectAirplaneApplyVo"/>
        where id = #{id}
    </select>

    <insert id="insertAirplaneApply" parameterType="com.djhk.uav.airspace.domain.AirplaneApply">
        insert into airplane_apply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name, </if>
            <if test="type != null">type, </if>
            <if test="sts != null">sts,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="flyTime != null">fly_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="remark != null">remark,</if>
            <if test="taskProp != null">task_prop,</if>
            <if test="tel != null">tel,</if>
            <if test="proUrl != null">pro_url,</if>
            <if test="finalUrl != null">final_url,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="sts != null">#{sts},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="flyTime != null">#{flyTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="taskProp != null">#{taskProp},</if>
            <if test="tel != null">#{tel},</if>
            <if test="proUrl != null">#{proUrl},</if>
            <if test="finalUrl != null">#{finalUrl},</if>
        </trim>
    </insert>


    <update id="updateAirplaneApply" parameterType="com.djhk.uav.airspace.domain.AirplaneApply">
        update airplane_apply
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="sts != null">sts = #{sts},</if>
            <if test="flyTime != null"> fly_time = #{flyTime} ,</if>
            <if test="remark != null"> remark = #{remark} ,</if>
            <if test="taskProp != null"> task_prop = #{taskProp} ,</if>
            <if test="tel != null"> tel = #{tel} ,</if>
            <if test="proUrl != null"> pro_url = #{proUrl} ,</if>
            <if test="finalUrl != null"> final_url = #{finalUrl} ,</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAirplaneApplyById" parameterType="Long">
        DELETE FROM airplane_apply
        WHERE id = #{id}
    </delete>

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