<?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.multictrl.modules.business.dao.NoflyZoneDao">
    <resultMap type="com.multictrl.modules.business.entity.NoflyZoneEntity" id="busNoflyZoneMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="status" column="status"/>
        <result property="extent" column="extent"/>
        <result property="deptId" column="dept_id"/>
        <result property="creator" column="creator"/>
        <result property="createDate" column="create_date"/>
    </resultMap>

    <select id="pageList" resultType="com.multictrl.modules.business.dto.NoflyZoneDTO">
        SELECT
        f.id,
               f."name",
               ST_AsText(f.extent) AS extent_wkt,
               f.create_date,
               u.real_name            user_name,
               d.name                 dept_name,
               f.status
        FROM bus_nofly_zone f
                 left join sys_user u on f.creator = u.id
                 left join sys_dept d on f.dept_id = d.id
        ${ew.customSqlSegment}
    </select>

    <insert id="saveNoFlyZone">
        INSERT INTO bus_nofly_zone (id, name, extent, dept_id, creator, create_date, status)
        VALUES (#{id}, #{name}, ST_GeomFromText(${extent}, 4326), #{deptId}, #{creator}, #{createDate}, #{status})
    </insert>

    <select id="getNoFlyZoneList" resultType="com.multictrl.modules.business.dto.NoflyZoneDTO">
        SELECT f.id,
               f."name",
               ST_AsText(f.extent) AS extent_wkt,
               f.create_date,
               u.real_name            user_name,
               d.name                 dept_name,
               f.status
        FROM bus_nofly_zone f
                 left join sys_user u on f.creator = u.id
                 left join sys_dept d on f.dept_id = d.id
            ${ew.customSqlSegment}
    </select>
</mapper>