<?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.zhongzheng.modules.base.mapper.ApplyAreasMapper">

    <resultMap type="com.zhongzheng.modules.base.domain.ApplyAreas" id="ApplyAreasResult">
        <result property="areaId" column="area_id"/>
        <result property="code" column="code"/>
        <result property="areaName" column="area_name"/>
        <result property="areaFullName" column="area_full_name"/>
        <result property="parentId" column="parent_id"/>
        <result property="areaType" column="area_type"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="parentName" column="parent_name"/>
    </resultMap>

    <select id="selectCityList" parameterType="com.zhongzheng.modules.base.bo.ApplyAreasQueryBo"  resultMap="ApplyAreasResult">
        SELECT
        a1.*,
        a2.area_name AS parent_name
        FROM
        apply_areas a1
        LEFT JOIN apply_areas a2 ON a1.parent_id = a2.area_id
        WHERE a1.area_type=2
        <if test="status != null and status.size()!=0 ">
            AND a1.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="areaName != null and areaName != ''">
            AND a1.area_name like concat('%', #{areaName}, '%')
        </if>
        <if test="parentId != null and parentId != ''">
            AND a1.parent_id = #{parentId}
        </if>
    </select>

</mapper>
