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

    <resultMap type="com.djhk.uav.airspace.domain.AirspaceApply" id="AirspaceApplyResult">
        <result column="id"         property="id"/>
        <result column="apply_time" property="applyTime"/>
        <result column="user_type"  property="userType"/>
        <result column="user_name"  property="userName"/>
        <result column="dept_type"  property="deptType"/>
        <result column="dept_code"  property="deptCode"/>
        <result column="dept_pname" property="deptPname"/>
        <result column="phone"       property="phone"/>
        <result column="email"       property="email"/>
        <result column="plan_type" property="planType"/>
        <result column="max_hegiht" property="maxHegiht"/>
        <result column="plan_beg" property="planBeg"/>
        <result column="plan_end" property="planEnd"/>
        <result column="txll" property="txll"/>
        <result column="task_type" property="taskType"/>
        <result column="opt_type" property="optType"/>
        <result column="fly_type" property="flyType"/>
        <result column="remark_qjbj" property="remarkQjbj"/>
        <result column="remark_yjcz" property="remarkYjcz"/>
        <result column="remark_tsxq" property="remarkTsxq"/>
        <result column="remark_tdjn" property="remarkTdjn"/>
        <result column="remark_fxhx" property="remarkFxhx"/>
        <result column="remark_zhkz" property="remarkZhkz"/>
        <result column="remark_ecld" property="remarkEcld"/>
        <result column="remark_qtxx" property="remarkQtxx"/>
        <result column="six" property="six"/>
        <result column="spaces" property="spaces"/>
        <result column="files" property="files"/>
        <result column="apply_sts" property="applySts"/>
        <result column="apply_dsc" property="applyDsc"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="hight_max" property="hightMax"/>
        <result column="hight_min" property="hightMin"/>
        <result column="lat" property="lat"/>
        <result column="lng" property="lng"/>
        <result column="military_area_name" property="militaryAreaName"/>
        <result column="military_area_id" property="militaryAreaId"/>
        <result column="name" property="name"/>
        <result column="flight_rule" property="flightRule"/>
        <result column="airspace_type" property="airspaceType"/>
        <result column="airspace_prop" property="airspaceProp"/>
        <result column="rad_length" property="radLength"/>
        <result column="uuid" property="uuid"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>

    <sql id="selectAirspaceApplyVo">
        select id,
        apply_time,
        user_type,
        user_name,
        dept_type,
        dept_code,
        dept_pname,
        phone,
        email,
        plan_type,
        max_hegiht,
        plan_beg,
        plan_end,
        txll,
        task_type,
        opt_type,
        fly_type,
        remark_qjbj,
        remark_yjcz,
        remark_tsxq,
        remark_tdjn,
        remark_fxhx,
        remark_zhkz,
        remark_ecld,
        remark_qtxx,
        six,
        spaces,
        files,
        apply_sts,
        apply_dsc,
        create_by,
        update_by,
        create_time,
        update_time,
        hight_max,
        hight_min,
        lat,
        lng,
        military_area_name,
        military_area_id,
        name,
        flight_rule,
        airspace_type,
        airspace_prop,
        rad_length,
        uuid
        from
        airspace_apply
    </sql>

    <select id="selectAirspaceApplyList" parameterType="com.djhk.uav.airspace.domain.AirspaceApply" resultMap="AirspaceApplyResult">
        <include refid="selectAirspaceApplyVo"/>
        <where>
            <if test="applySts != null and applySts != ''"> and apply_sts = #{applySts}</if>
            <if test="taskType != null  and taskType != ''"> and task_type = #{taskType}</if>
            <if test="optType != null  and optType != ''"> and opt_type = #{optType}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="flyType != null  and flyType != ''"> and fly_type = #{flyType}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and date_format(apply_time,'%y%m%d') &gt;= date_format(#{startTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and date_format(apply_time,'%y%m%d') &lt;= date_format(#{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 asc
    </select>

    <select id="selectAirspaceApplyId" parameterType="Long" resultMap="AirspaceApplyResult">
        select max(id)
        from
        airspace_apply
    </select>

    <select id="selectAirspaceApplyById" parameterType="Long" resultMap="AirspaceApplyResult">
        <include refid="selectAirspaceApplyVo"/>
        where id = #{id}
    </select>

    <insert id="insertAirspaceApply" parameterType="com.djhk.uav.airspace.domain.AirspaceApply">
        insert into airspace_apply
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="applyTime != null">apply_time, </if>
            <if test="userType != null">user_type,</if>
            <if test="userName != null">user_name,</if>
            <if test="deptType != null">dept_type,</if>
            <if test="deptCode != null">dept_code,</if>
            <if test="deptPname != null">dept_pname,</if>
            <if test="phone != null">phone,</if>
            <if test="email != null">email,</if>
            <if test="planType != null">plan_type},</if>
            <if test="maxHegiht != null">max_hegiht,</if>
            <if test="planBeg != null">plan_beg,</if>
            <if test="planEnd != null">plan_end,</if>
            <if test="txll != null">txll,</if>
            <if test="taskType != null">task_type,</if>
            <if test="optType != null">opt_type,</if>
            <if test="flyType != null">fly_type},</if>
            <if test="remarkQjbj != null">remark_qjbj,</if>
            <if test="remarkYjcz != null">remark_yjcz,</if>
            <if test="remarkTsxq != null">remark_tsxq,</if>
            <if test="remarkTdjn != null">remark_tdjn,</if>
            <if test="remarkFxhx != null">remark_fxhx,</if>
            <if test="remarkZhkz != null">remark_zhkz,</if>
            <if test="remarkEcld != null">remark_ecld,</if>
            <if test="remarkQtxx != null">remark_qtxx,</if>
            <if test="six != null">six,</if>
            <if test="spaces != null">spaces,</if>
            <if test="files != null">files,</if>
            <if test="applySts != null">apply_sts,</if>
            <if test="applyDsc != null">apply_dsc,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="hightMax != null">hight_max,</if>
            <if test="hightMin != null">hight_min,</if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="militaryAreaName != null">military_area_name,</if>
            <if test="militaryAreaId != null">military_area_id,</if>
            <if test="name != null">name,</if>
            <if test="flightRule != null">flight_rule,</if>
            <if test="airspaceType != null">airspace_type,</if>
            <if test="airspaceProp != null">airspace_prop,</if>
            <if test="radLength != null">rad_length,</if>
            <if test="uuid != null">uuid,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="applyTime != null">#{applyTime},</if>
            <if test="userType != null">#{userType},</if>
            <if test="userName != null">#{userName},</if>
            <if test="deptType != null">#{deptType},</if>
            <if test="deptCode != null">#{deptCode},</if>
            <if test="deptPname != null">#{deptPname},</if>
            <if test="phone != null">#{phone},</if>
            <if test="email != null">#{email},</if>
            <if test="planType != null">#{planType},</if>
            <if test="maxHegiht != null">#{maxHegiht},</if>
            <if test="planBeg != null">#{planBeg},</if>
            <if test="planEnd != null">#{planEnd},</if>
            <if test="txll != null">#{txll},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="optType != null">#{optType},</if>
            <if test="flyType != null">#{flyType},</if>
            <if test="remarkQjbj != null">#{remarkQjbj},</if>
            <if test="remarkYjcz != null">#{remarkYjcz},</if>
            <if test="remarkTsxq != null">#{remarkTsxq},</if>
            <if test="remarkTdjn != null">#{remarkTdjn},</if>
            <if test="remarkFxhx != null">#{remarkFxhx},</if>
            <if test="remarkZhkz != null">#{remarkZhkz},</if>
            <if test="remarkEcld != null">#{remarkEcld},</if>
            <if test="remarkQtxx != null">#{remarkQtxx},</if>
            <if test="six != null">#{six},</if>
            <if test="spaces != null">#{spaces},</if>
            <if test="files != null">#{files},</if>
            <if test="applySts != null">#{applySts},</if>
            <if test="applyDsc != null">#{applyDsc},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="hightMax != null">#{hightMax},</if>
            <if test="hightMin != null">#{hightMin},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="militaryAreaName != null">#{militaryAreaName},</if>
            <if test="militaryAreaId != null">#{militaryAreaId},</if>
            <if test="name != null">#{name},</if>
            <if test="flightRule != null">#{flightRule},</if>
            <if test="airspaceType != null">#{airspaceType},</if>
            <if test="airspaceProp != null">#{airspaceProp},</if>
            <if test="radLength != null">#{radLength},</if>
            <if test="uuid != null">#{uuid},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>


    <update id="updateAirspaceApply" parameterType="com.djhk.uav.airspace.domain.AirspaceApply">
        update airspace_apply
        <trim prefix="SET" suffixOverrides=",">
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="deptType != null">dept_type = #{deptType},</if>
            <if test="deptCode != null">dept_code = #{deptCode},</if>
            <if test="deptPname != null">dept_pname = #{deptPname},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="email != null">email = #{email},</if>
            <if test="planType != null">plan_type = #{planType},</if>
            <if test="maxHegiht != null">max_hegiht = #{maxHegiht},</if>
            <if test="planBeg != null">plan_beg = #{planBeg},</if>
            <if test="planEnd != null">plan_end = #{planEnd},</if>
            <if test="txll != null">txll = #{txll},</if>
            <if test="taskType != null">task_type = #{taskType},</if>
            <if test="optType != null">opt_type = #{optType},</if>
            <if test="flyType != null">fly_type = #{flyType},</if>
            <if test="remarkQjbj != null">remark_qjbj = #{remarkQjbj},</if>
            <if test="remarkYjcz != null">remark_yjcz = #{remarkYjcz},</if>
            <if test="remarkTsxq != null">remark_tsxq = #{remarkTsxq},</if>
            <if test="remarkTdjn != null">remark_tdjn = #{remarkTdjn},</if>
            <if test="remarkFxhx != null">remark_fxhx = #{remarkFxhx},</if>
            <if test="remarkZhkz != null">remark_zhkz = #{remarkZhkz},</if>
            <if test="remarkEcld != null">remark_ecld = #{remarkEcld},</if>
            <if test="remarkQtxx != null">remark_qtxx = #{remarkQtxx},</if>
            <if test="six != null">six = #{six},</if>
            <if test="spaces != null">spaces = #{spaces},</if>
            <if test="files != null">files = #{files},</if>
            <if test="applySts != null">apply_sts = #{applySts},</if>
            <if test="applyDsc != null">apply_dsc = #{applyDsc},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="hightMax != null">hight_max = #{hightMax},</if>
            <if test="hightMin != null">hight_min = #{hightMin},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="militaryAreaName != null">military_area_name = #{militaryAreaName},</if>
            <if test="militaryAreaId != null">military_area_id = #{militaryAreaId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="flightRule != null">flight_rule = #{flightRule},</if>
            <if test="airspaceType != null">airspace_type = #{airspaceType},</if>
            <if test="airspaceProp != null">airspace_prop = #{airspaceProp},</if>
            <if test="radLength != null">rad_length = #{radLength},</if>
            <if test="uuid != null">uuid = #{uuid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAirspaceApplyById" parameterType="Long">
        DELETE FROM airspace_apply
        WHERE id = #{id}
    </delete>

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