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

<!-- rscm_area_info -->
<mapper namespace="com.upyuns.platform.rs.datacenter.mapper.RscpAreaInfoMapper">
    <!-- This code was generated by TableGo tools, mark 1 begin. -->
    <!-- 字段映射 -->
    <resultMap id="rscmAreaInfoMap" type="com.upyuns.platform.rs.datacenter.entity.RscpAreaInfo">
        <id column="admincode" property="admincode" jdbcType="VARCHAR" />
        <result column="proadcode" property="proadcode" jdbcType="VARCHAR" />
        <result column="cityadcode" property="cityadcode" jdbcType="VARCHAR" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="cityname" property="cityname" jdbcType="VARCHAR" />
        <result column="proname" property="proname" jdbcType="VARCHAR" />
        <result column="shape_leng" property="shapeLeng" jdbcType="INTEGER" />
        <result column="shape_area" property="shapeArea" jdbcType="INTEGER" />
        <result column="geom" property="geom" jdbcType="VARCHAR" />
        <result column="point_geom" property="pointGeom" jdbcType="VARCHAR" />
        <result column="pinyin" property="pinyin" jdbcType="VARCHAR" />
        <result column="pysx" property="pysx" jdbcType="VARCHAR" />
        <result column="geom_samll" property="geomSamll" jdbcType="VARCHAR" />
        <result column="is_handle_cover_rate" property="isHandleCoverRate" jdbcType="INTEGER" />
        <result column="area_parent_percent" property="areaParentPercent" jdbcType="INTEGER" />
    </resultMap>
    <!-- This code was generated by TableGo tools, mark 1 end. -->
    
    <!-- This code was generated by TableGo tools, mark 2 begin. -->
    <!-- 表查询字段 -->
    <sql id="allColumns">
        rai.admincode, rai.proadcode, rai.cityadcode, rai.name, rai.cityname, rai.proname, rai.shape_leng, rai.shape_area, 
        rai.geom, rai.point_geom, rai.pinyin, rai.pysx, rai.geom_samll, rai.is_handle_cover_rate, rai.area_parent_percent
    </sql>
    <!-- This code was generated by TableGo tools, mark 2 end. -->

    <select id="queryAreaInfoByAreaCode" resultType="com.upyuns.platform.rs.datacenter.entity.RscpAreaInfo">
        select a.name,a.shape_area,a.admincode,st_asgeojson(geom_samll,16,0) geom,a.proname,a.cityname
        from rscp_area_info a
        where admincode=#{areaCode}
    </select>

    <select id="getDirectSubAreas" resultType="com.upyuns.platform.rs.datacenter.entity.RscpAreaInfo">
        select admincode ,name, pinyin
            from rscp_area_info where admincode != #{parentId} and admincode like
            CASE WHEN #{parentId} = '000000' THEN '%0000'
            WHEN substring(#{parentId}, 3, 4) = '0000' THEN substring(#{parentId}, 1, 2)||'%'||substring(#{parentId}, 5, 2)
            ELSE substring(#{parentId}, 1, 4)||'%' END
            order by pinyin
    </select>
</mapper>