<?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.njcn.system.mapper.AreaMapper">
    <!--行政区域树-->
    <select id="getAreaTree" resultType="AreaTreeVO">
        SELECT sys_area.id id,
               sys_area.name name,
               sys_area.pid pid,
               sys_area.pids pids,
               sys_area.short_name shortName,
               sys_area.area_code areaCode,
               sys_area.lng lng,
               sys_area.lat lat
        FROM sys_area sys_area
        WHERE sys_area.type = #{type}
          AND sys_area.state = #{state}
          AND sys_area.pid = #{id}
    </select>

    <!--行政区域树-->
    <select id="getAreaIdTree" resultType="AreaTreeVO">
        SELECT sys_area.id id,
               sys_area.name name,
               sys_area.pid pid,
               sys_area.pids pids,
               sys_area.short_name shortName,
               sys_area.area_code areaCode,
               sys_area.lng lng,
               sys_area.lat lat
        FROM sys_area sys_area
        WHERE sys_area.type = #{type}
          AND sys_area.state = #{state}
    </select>



    <select id="selectPid" resultType="Area">
        SELECT sys_area.*
        FROM sys_area sys_area
        WHERE sys_area.pid in
        <foreach item="item" index="index" collection="ids" open="("
                 separator="," close=")">
            #{item}
        </foreach>
        AND sys_area.type = 1
        AND sys_area.state = #{state}
    </select>

    <select id="getIdString" resultType="String">
        SELECT sys_area.pids pids
        FROM sys_area sys_area
        WHERE sys_area.id = #{id}
    </select>

    <!--行政区域树-->
    <select id="getAreaDeptTree" resultType="AreaTreeDTO">
        SELECT sys_area.id id,
               sys_area.name name,
               sys_area.pid pid,
               sys_area.pids pids,
               sys_area.short_name shortName,
               sys_area.area_code areaCode,
               sys_area.lng lng,
               sys_area.lat lat
        FROM sys_area sys_area
        WHERE sys_area.type = #{type}
          AND sys_area.state = #{state}
    </select>

    <select id="getAreaAll" resultType="AreaTreeVO">
        SELECT sys_area.*
        FROM sys_area sys_area
    </select>

    <select id="areaDeptProDetail" resultType="Area">
        SELECT
            *
        FROM
            sys_area
        WHERE
            id = (
                SELECT
                    area
                FROM
                    sys_dept
                WHERE
                    id = #{id})
    </select>
</mapper>
