<?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.modules.baseinfo.region.mapper.BaseRegionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="baseRegionResultMap" type="org.springblade.modules.baseinfo.region.entity.RegionInfoEntity">
        <result column="code" property="adcd"/>
        <result column="name" property="adnm"/>
        <result column="parent_code" property="parentCode"/>
        <result column="ancestors" property="ancestors"/>
        <result column="region_level" property="regionLevel"/>
    </resultMap>

    <select id="getCount" resultType="java.lang.Long">
        SELECT
        count(*)
        FROM
        blade_region n
        WHERE
        1 = 1
        <if test="dto.adcd != null">
            and n.code = #{dto.adcd}
        </if>
        <if test="dto.parentCode != null">
            and n.parent_code = #{dto.parentCode}
        </if>
    </select>

    <select id="selectList" resultMap="baseRegionResultMap">
        SELECT
        n.code,n.name,n.parent_code,n.ancestors,n.region_level
        FROM
        blade_region n
        WHERE
        1 = 1
        <if test="dto.adcd != null">
            and n.code = #{dto.adcd}
        </if>
        <if test="dto.parentCode != null">
            and n.parent_code = #{dto.parentCode}
        </if>
        order by n.code
    </select>

    <select id="getByCode" resultMap="baseRegionResultMap">
        SELECT
        n.code,n.name,n.parent_code,n.ancestors,n.region_level
        FROM
        blade_region n
        WHERE
        n.code = #{code}
    </select>
</mapper>
