<?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.bonus.canteen.core.allocation.canteen.mapper.AllocAreaMapper">

<!--    &lt;!&ndash; 分页查询区域列表 &ndash;&gt;-->
<!--    <select id="pageArea" resultType="com.bonus.canteen.core.allocation.canteen.model.AllocArea">-->
<!--        SELECT-->
<!--            t1.area_id, t1.area_num, t1.area_name, t1.first_area_name, t1.second_area_name, t1.third_area_name, t1.super_id,-->
<!--            t1.director, t1.contact_tel, t1.area_describe, t1.crtime, t1.uptime-->
<!--        FROM-->
<!--            alloc_area t1-->
<!--        WHERE-->
<!--            t1.if_del = #{param.ifDel}-->
<!--            <if test="param.areaName != null and param.areaName != ''">-->
<!--               AND t1.area_name LIKE #{param.areaName}-->
<!--            </if>-->
<!--            <if test="param.areaIdList != null and param.areaIdList.size() > 0">-->
<!--                AND t1.area_id IN-->
<!--                <foreach collection="param.areaIdList" item="areaId" separator="," open="(" close=")">-->
<!--                    #{areaId}-->
<!--                </foreach>-->
<!--            </if>-->
<!--    </select>-->

    <!-- 获取所有区域树对象列表 -->
    <select id="listAllTreeArea" resultType="com.bonus.canteen.core.allocation.canteen.vo.AllocAreaTreeVO">
       SELECT
            t1.area_id AS id,
            t1.super_id AS parent_id
        FROM alloc_area t1
        WHERE t1.if_del = 2
    </select>

    <!-- 系统区域树（无权限） -->
    <select id="listSystemArea" resultType="com.bonus.canteen.core.allocation.canteen.vo.AllocAreaTreeVO">
        SELECT id, parent_id, tree_name, area_level, sort_no, crtime
        FROM (
             SELECT #{merchantId}                            AS id,
                    - 1                                      AS parent_id,
                    merchant_name                            AS tree_name,
                    0                                        AS area_level,
                    0                                        AS sort_no,
                    2                                        AS if_del,
                    crtime
             FROM merc_merchant
             UNION ALL
             SELECT  area_id                                 AS id,
                     super_id                                AS parent_id,
                     area_name                               AS tree_name,
                     if(third_area_name is not null, 3, 0)   AS area_level,
                     sort_no                                 AS sort_no,
                     if_del,
                     crtime
             FROM alloc_area )  as s
        WHERE if_del = 2
    </select>

<!--    <select id="listAreaByUserRole" resultType="net.xnzn.core.allocation.canteen.vo.AllocAreaVO">-->
<!--        SELECT t1.area_id,-->
<!--               t1.area_name,-->
<!--               t1.super_id-->
<!--        FROM alloc_area t1-->
<!--        WHERE t1.if_del = 2-->
<!--        <if test="'-1'.toString() != authPO.roleType.toString()">-->
<!--            and EXISTS (-->
<!--            SELECT null-->
<!--            FROM mgr_role_area it1-->
<!--            LEFT JOIN mgr_role it2 ON it2.role_id = it1.role_id-->
<!--            LEFT JOIN mgr_user_role it3 ON it1.role_id = it3.role_id-->
<!--            WHERE it2.del_flag = 2-->
<!--            AND it2.role_code = #{authPO.roleCode}-->
<!--            AND it3.user_id = #{authPO.userId}-->
<!--            AND t1.area_id = it1.data_id-->
<!--            )-->
<!--        </if>-->
<!--    </select>-->
</mapper>
