<?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.hzs.system.config.mapper.BdContinentMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdContinent">
        <id column="PK_ID" property="pkId" />
    <result column="DEL_FLAG" property="delFlag" />
    <result column="PK_COUNTRY" property="pkCountry" />
    <result column="CREATION_TIME" property="creationTime" />
    <result column="MODIFIED_TIME" property="modifiedTime" />
    <result column="PK_CREATOR" property="pkCreator" />
    <result column="PK_MODIFIED" property="pkModified" />
        <result column="REGION_NAME" property="regionName" />
        <result column="SORT" property="sort" />
        <result column="PK_PARENT_ID" property="pkParentId" />
        <result column="REGION_TYPE" property="regionType" />
        <result column="PK_AREA_ID" property="pkAreaId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        PK_COUNTRY,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, CONTINENT_NAME, SORT
    </sql>

    <select id="selectRegionList" parameterType="com.hzs.system.config.vo.BdContinentVO"
            resultType="com.hzs.system.config.vo.BdContinentVO">
        select
        a.PK_ID pkId,
        a.PK_PARENT_ID pkParentId,
        a.PK_AREA_ID pkAreaId,
        a.REGION_TYPE regionType,
        b.SHORT_NAME shortName
        from BD_CONTINENT a
        INNER  JOIN  BD_COUNTRY b on a.PK_AREA_ID=b.PK_ID
        where a.DEL_FLAG=0
        <if test="regionType != null">
            AND a.REGION_TYPE = #{regionType}
        </if>
        <if test="pkParentId != null">
            AND a.PK_PARENT_ID = #{pkParentId}
        </if>
        order by a.PK_ID DESC
    </select>

    <select id="selectProvinceList" parameterType="com.hzs.system.config.vo.BdContinentVO"
            resultType="com.hzs.system.config.vo.BdContinentVO">
        select
        a.PK_ID pkId,
        a.PK_PARENT_ID pkParentId,
        a.PK_AREA_ID pkAreaId,
        a.REGION_TYPE regionType,
        b.NAME provinceName
        from BD_CONTINENT a
        INNER  JOIN  BD_AREA b on a.PK_AREA_ID=b.PK_ID
        where a.DEL_FLAG=0
        <if test="regionType != null">
            AND a.REGION_TYPE = #{regionType}
        </if>
        <if test="pkParentId != null">
            AND a.PK_PARENT_ID = #{pkParentId}
        </if>
        order by a.PK_ID DESC
    </select>

    <!--洲际配置-根据上级查询下一级或国家-->
    <select id="sonlist" parameterType="com.hzs.system.config.vo.BdContinentVO"
            resultType="com.hzs.system.config.vo.BdContinentVO">
        select
        a.PK_ID pkId,
        a.PK_PARENT_ID pkParentId,
        a.PK_AREA_ID pkAreaId,
        a.REGION_TYPE regionType,
        a.REGION_NAME regionName,
        b.SHORT_NAME shortName
        from BD_CONTINENT a
        left JOIN  BD_COUNTRY b on a.PK_AREA_ID=b.PK_ID
        where a.DEL_FLAG=0 and (a.REGION_TYPE=1 or a.REGION_TYPE=2)
        <if test="pkParentId != null">
            AND a.PK_PARENT_ID = #{pkParentId}
        </if>
        order by a.PK_ID DESC
    </select>

    <!--区域配置-根据上级查询下一级区域或省-->
    <select id="sonlistRegion" parameterType="com.hzs.system.config.vo.BdContinentVO"
            resultType="com.hzs.system.config.vo.BdContinentVO">
        select
        a.PK_ID pkId,
        a.PK_PARENT_ID pkParentId,
        a.PK_AREA_ID pkAreaId,
        a.REGION_TYPE regionType,
        a.REGION_NAME regionName,
        b.NAME provinceName
        from BD_CONTINENT a
        left  JOIN  BD_AREA b on a.PK_AREA_ID=b.PK_ID
        where a.DEL_FLAG=0 and (a.REGION_TYPE=3 or a.REGION_TYPE=4)
        <if test="pkParentId != null">
            AND a.PK_PARENT_ID = #{pkParentId}
        </if>
        order by a.PK_ID DESC
    </select>



</mapper>
