<?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="cn.pluss.platform.mapper.RegionReflectMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.RegionReflect">
        <id column="id" property="id" />
        <result column="channel" property="channel" />
        <result column="regionSrc" property="regionSrc" />
        <result column="regionDes" property="regionDes" />
    </resultMap>

    <resultMap id="baseResultVOMap" type="cn.pluss.platform.vo.RegionReflectVO">
        <id column="id" property="id" />
        <result column="channel" property="channel" />
        <result column="regionSrc" property="regionSrc" />
        <result column="regionDes" property="regionDes" />
        <association property="src">
            <result property="area" column="srcArea" />
            <result property="areaCode" column="srcAreaCode" />
            <result property="city" column="srcCity" />
            <result property="cityCode" column="srcCityCode" />
            <result property="province" column="srcProvince" />
            <result property="provinceCode" column="srcProvinceCode" />
        </association>
        <association property="sxf">
            <result property="area" column="sxfArea" />
            <result property="areaCode" column="sxfAreaCode" />
            <result property="city" column="sxfCity" />
            <result property="cityCode" column="sxfCityCode" />
            <result property="province" column="sxfProvince" />
            <result property="provinceCode" column="sxfProvinceCode" />
        </association>
        <association property="ryx">
            <result property="area" column="ryxArea" />
            <result property="areaCode" column="ryxAreaCode" />
            <result property="city" column="ryxCity" />
            <result property="cityCode" column="ryxCityCode" />
            <result property="province" column="ryxProvince" />
            <result property="provinceCode" column="ryxProvinceCode" />
        </association>
        <association property="ys">
            <result property="area" column="ysArea" />
            <result property="areaCode" column="ysAreaCode" />
            <result property="city" column="ysCity" />
            <result property="cityCode" column="ysCityCode" />
            <result property="province" column="ysProvince" />
            <result property="provinceCode" column="ysProvinceCode" />
        </association>
    </resultMap>

    <select id="selectRegionReflectList" resultMap="baseResultVOMap">
        SELECT
            ls.id regionSrc,
            ls.province srcProvince, ls.city srcCity, ls.area srcArea,
            sxf.province sxfProvince, sxf.city sxfCity, sxf.area sxfArea,
            ryx.province ryxProvince, ryx.city ryxCity, ryx.area ryxArea,
            ys.province ysProvince, ys.city ysCity, ys.area ysArea
        FROM tb_pluss_region_code_ls ls
          LEFT JOIN tb_pluss_region_reflect rr1 ON ls.id = rr1.regionSrc AND rr1.channel = 1
          LEFT JOIN tb_pluss_region_code_sxf sxf ON rr1.regionDes = sxf.id
          LEFT JOIN tb_pluss_region_reflect rr2 ON ls.id = rr2.regionSrc AND rr2.channel = 3
          LEFT JOIN tb_pluss_region_code_ryx ryx ON rr2.regionDes = ryx.id
          LEFT JOIN tb_pluss_region_reflect rr3 ON ls.id = rr3.regionSrc AND rr3.channel = 4
          LEFT JOIN tb_pluss_region_code_ys ys ON rr3.regionDes = ys.id
        <where>
            ls.area IS NOT NULL
            <if test="province != null and province != ''">
                AND ls.province LIKE CONCAT(#{province}, "%")
            </if>
            <if test="city != null and city != ''">
                AND ls.city LIKE CONCAT(#{city}, "%")
            </if>
            <if test="area != null and area != ''">
                AND ls.area LIKE CONCAT(#{area}, "%")
            </if>
        </where>
    </select>
</mapper>
