<?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.huashe.common.data.mapper.DimGbRegionMapper">
    <resultMap id="BaseResultMap" type="com.huashe.common.data.model.GbRegion">
        <result column="adcode" property="adcode" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="area_type" property="areaType" jdbcType="INTEGER"/>
        <result column="parent_area" property="parentArea" jdbcType="VARCHAR"/>
        <result column="parent_area_name" property="parentAreaName" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="selectGbRegion">
        SELECT
            `adcode`, `name`, `area_type`, `parent_area`, `parent_area_name`
        FROM
            dim_gb_region
    </sql>

    <select id="getRegionByCode" resultMap="BaseResultMap">
        <include refid="selectGbRegion"/>
        WHERE adcode = #{adcode}
    </select>

    <select id="getAll" resultMap="BaseResultMap">
        <include refid="selectGbRegion"/>
    </select>

    <select id="getGbRegion" parameterType="com.huashe.common.domain.model.Region" resultMap="BaseResultMap">
        <include refid="selectGbRegion"/>
        <where>
            <if test="parentArea != null and parentArea != ''">and parent_area = #{parentArea}</if>
            <if test="areaType != null">and area_type = #{areaType}</if>
            <if test="name != null and name != ''">and `name` like '%#{name}'</if>
        </where>
    </select>

    <select id="getMunicipality" resultMap="BaseResultMap">
        SELECT
            `adcode`, `name`, `area_type`, `parent_area`, `parent_area_name`
        FROM
            dim_gb_region
        WHERE
            area_type = 1 and `name` like '%市'
    </select>
</mapper>
