<?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.ruoyi.erp.mapper.RegionMapper">

    <resultMap id="RegionMap" type="com.ruoyi.erp.domain.Region">
        <result property="provId" column="prov_id" />
        <result property="provName" column="prov_name" />
        <result property="cityId" column="city_id" />
        <result property="cityName" column="city_name" />
        <result property="areaId" column="area_id" />
        <result property="areaName" column="area_name" />
    </resultMap>

    <select id="selectProvinces" resultMap="RegionMap">
        SELECT DISTINCT prov_id, prov_name, 0 AS city_id, '' AS city_name, 0 AS area_id, '' AS area_name
        FROM xgj_region
        ORDER BY prov_id
    </select>

    <select id="selectCitiesByProv" parameterType="int" resultMap="RegionMap">
        SELECT DISTINCT prov_id, prov_name, city_id, city_name, 0 AS area_id, '' AS area_name
        FROM xgj_region
        WHERE prov_id = #{provId}
        ORDER BY city_id
    </select>

    <select id="selectAreasByCity" resultMap="RegionMap">
        SELECT prov_id, prov_name, city_id, city_name, area_id, area_name
        FROM xgj_region
        WHERE prov_id = #{provId} AND city_id = #{cityId}
        ORDER BY area_id
    </select>

</mapper>


