Bonus-Cloud-Houqin/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/auth/MgrRoleCanteenMapper.xml

109 lines
5.3 KiB
XML

<?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.auth.role.mapper.MgrRoleCanteenMapper">
<insert id="insertBatch" parameterType="object">
insert into sys_role_canteen
values
<foreach collection="canteenList" item="canteen" index="index" separator=",">
(#{roleId}, #{canteen.dataId}, #{canteen.type})
</foreach>
</insert>
<select id="getTenantCanteen" resultType="com.bonus.canteen.core.allocation.canteen.vo.AllocCanteenTreeVO">
<choose>
<when test="'3'.toString() == authPO.roleType.toString()">
SELECT id, parent_id, tree_name, tree_type, biz_type
FROM (select data_id
<!-- ,half_select -->
from (SELECT r.data_id
<!-- , r.half_select -->
FROM sys_role_canteen r
LEFT JOIN sys_role o ON o.role_id = r.role_id
LEFT JOIN sys_user_role u ON r.role_id = u.role_id
WHERE u.user_id = #{authPO.userId}
AND o.role_key = #{authPO.roleCode}
AND o.del_flag = 0) s
ORDER BY data_id) t
LEFT JOIN (SELECT #{merchantId} AS id,
-1 AS parent_id,
merchant_name AS tree_name,
-1 AS tree_type,
0 AS biz_type,
2 AS if_del
FROM merc_merchant
UNION ALL
SELECT area_id AS id,
super_id AS parent_id,
area_name AS tree_name,
0 AS tree_type,
0 AS biz_type,
if_del
FROM alloc_area
UNION ALL
SELECT canteen_id AS id,
area_id AS parent_id,
canteen_name AS tree_name,
1 AS tree_type,
canteen_type AS biz_type,
if_del
FROM alloc_canteen
UNION ALL
SELECT stall_id AS id,
canteen_id AS parent_id,
stall_name AS tree_name,
2 AS tree_type,
stall_type AS biz_type,
if_del
FROM alloc_stall) s ON s.id = t.data_id
<where>
<if test="delFlag != null">
AND if_del = #{delFlag}
</if>
<if test="excludeMiddle == 1">
AND t.half_select = 1
</if>
</where>
</when>
<otherwise>
SELECT id, parent_id, tree_name, tree_type, biz_type
FROM (SELECT #{merchantId} AS id,
-1 AS parent_id,
merchant_name AS tree_name,
-1 AS tree_type,
0 AS biz_type,
2 AS if_del
FROM merc_merchant
UNION ALL
SELECT area_id AS id,
super_id AS parent_id,
area_name AS tree_name,
0 AS tree_type,
0 AS biz_type,
if_del
FROM alloc_area
UNION ALL
SELECT canteen_id AS id,
area_id AS parent_id,
canteen_name AS tree_name,
1 AS tree_type,
canteen_type AS biz_type,
if_del
FROM alloc_canteen
UNION ALL
SELECT stall_id AS id,
canteen_id AS parent_id,
stall_name AS tree_name,
2 AS tree_type,
stall_type AS biz_type,
if_del
FROM alloc_stall) s
<where>
<if test="delFlag != null">
AND if_del = #{delFlag}
</if>
</where>
</otherwise>
</choose>
</select>
</mapper>