<?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="org.springblade.sysarea.mapper.SysAreaMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="sysAreaResultMap" type="org.springblade.sysarea.entity.SysArea">
        <id column="id" property="id"/>
        <result column="s_code" property="sCode"/>
        <result column="s_parent_code" property="sParentCode"/>
        <result column="s_name" property="sName"/>
        <result column="s_short_name" property="sShortName"/>
        <result column="s_traditional_name" property="sTraditionalName"/>
        <result column="s_english_name" property="sEnglishName"/>
        <result column="s_merger_name" property="sMergerName"/>
        <result column="i_layer_number" property="iLayerNumber"/>
        <result column="s_zip_code" property="sZipCode"/>
        <result column="s_city_code" property="sCityCode"/>
        <result column="s_pinyin" property="sPinyin"/>
        <result column="s_lat" property="sLat"/>
        <result column="s_lng" property="sLng"/>
        <result column="s_first_letter" property="sFirstLetter"/>
        <result column="t_create_date" property="tCreateDate"/>
        <result column="i_status" property="iStatus"/>
    </resultMap>


    <select id="selectSysAreaPage" resultMap="sysAreaResultMap">
        select * from blade_sys_area where is_deleted = 0
    </select>

    <select id="getAllProvince" resultMap="sysAreaResultMap">
        select * from blade_sys_area where i_status = 0 and s_parent_code=100000
    </select>

    <select id="getCityOrAreaByParentCode" resultMap="sysAreaResultMap">
        select * from blade_sys_area where i_status = 0 and s_parent_code = ${code}
    </select>


    <select id="getDetailByCode" resultMap="sysAreaResultMap">
        select * from blade_sys_area where i_status = 0 and s_code = ${code}
    </select>


    <select id="getCityByProvinceSName" resultMap="sysAreaResultMap">
        select * from blade_sys_area  where i_status = 0 and s_parent_code in (
            select s_code from blade_sys_area where s_name='${province_name}')
    </select>
    <select id="getParentNameAndCodeByLevel" resultMap="sysAreaResultMap">
       select
            s_code,concat(s_name,s_code) as s_name
        from blade_sys_area
        where i_status = 0 and i_layer_number=  ${i_layer_number-1}
    </select>
    <select id="scodeIsExist" resultMap="sysAreaResultMap">
       select
            s_code
        from blade_sys_area
        where i_status = 0 and s_code = ${scode}
    </select>

    <select id="getAreaList" resultType="String">
        SELECT distinct area_code FROM system_street
    </select>
</mapper>
