<?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.yami.shop.dao.AreaMapper">
    <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.Area">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="area_id" jdbcType="BIGINT" property="areaId"/>
        <result column="area_name" jdbcType="VARCHAR" property="areaName"/>
        <result column="parent_id" jdbcType="BIGINT" property="parentId"/>
        <result column="level" jdbcType="INTEGER" property="level"/>
        <result column="code" jdbcType="BIGINT" property="code"/>
    </resultMap>

    <resultMap id="AreaListMap" type="com.yami.shop.bean.dto.AreaDto">
        <id column="pid" property="areaId"></id>
        <result column="pname" property="areaName"/>
        <result column="ppid" property="parentId"/>
        <result column="plevel" property="level"/>
        <collection property="areas" ofType="com.yami.shop.bean.dto.AreaDto">
            <id column="cid" property="areaId"></id>
            <result column="cname" property="areaName"/>
            <result column="cpid" property="parentId"/>
            <result column="clevel" property="level"/>
            <collection property="areas" ofType="com.yami.shop.bean.dto.AreaDto">
                <id column="area_id" property="areaId"/>
                <result column="area_name" property="areaName"/>
                <result column="parent_id" property="parentId"/>
                <result column="level" property="level"/>
            </collection>
        </collection>
    </resultMap>
    <select id="getAreaListInfo" resultMap="AreaListMap">
        SELECT *
        FROM (SELECT p.area_id   pid,
                     p.area_name pname,
                     p.parent_id ppid,
                     p.level     plevel,
                     c.code      cid,
                     c.area_name cname,
                     c.parent_id cpid,
                     c.level     clevel
              FROM tz_area p
                       JOIN tz_area c ON p.code = 0 AND c.parent_id = p.code) tal
                 LEFT JOIN tz_area a ON tal.cid = a.parent_id
    </select>

</mapper>
