Browse Source

层级修改补充

jwy
review512jwy@163.com 3 weeks ago
parent
commit
cd79871815
  1. 2
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelRoleMapperExt.java
  2. 42
      dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelRoleMapperExt.xml
  3. 33
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelRoleServiceImpl.java

2
dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/LevelRoleMapperExt.java

@ -40,4 +40,6 @@ public interface LevelRoleMapperExt extends DashboardLevelRoleMapper {
List<UserBindLevelRoleVO> getCanBeBoundUserPage(BaseSearchParams pageSearchParam); List<UserBindLevelRoleVO> getCanBeBoundUserPage(BaseSearchParams pageSearchParam);
Integer checkLevelManager(Long userId); Integer checkLevelManager(Long userId);
List<RefKey> selectAllStoreAreas(Map<String, Object> levelMap);
} }

42
dongjian-dashboard-back-dao/src/main/resources/mappers/ex/LevelRoleMapperExt.xml

@ -97,28 +97,42 @@
WHERE b.flag = 0 and b.company_id = #{companyId} WHERE b.flag = 0 and b.company_id = #{companyId}
</select> </select>
<select id="selectAllStoreAreas" resultType="com.dongjian.dashboard.back.vo.levelrole.RefKey">
SELECT s.id,
s.name,
r.branch_id AS parentId,
'STORE_AREA' AS type
FROM dashboard_level_store_area_merge s
LEFT JOIN dashboard_level_relation_branch_store_area r
ON s.id = r.store_area_id
WHERE s.flag = 0 and s.company_id = #{companyId}
</select>
<!-- 查用户绑定节点 --> <!-- 查用户绑定节点 -->
<select id="selectUserRefs" resultType="com.dongjian.dashboard.back.vo.levelrole.RefKey"> <select id="selectUserRefs" resultType="com.dongjian.dashboard.back.vo.levelrole.RefKey">
SELECT o.ref_type AS type, SELECT
o.ref_type AS type,
o.ref_id AS id o.ref_id AS id
FROM dashboard_level_role_user u FROM dashboard_level_role_user u
INNER JOIN dashboard_level_role_object o INNER JOIN dashboard_level_role_object o
ON u.level_role_id = o.level_role_id ON u.level_role_id = o.level_role_id
LEFT JOIN dashboard_level_branch b LEFT JOIN dashboard_level_branch b
ON o.ref_type = 'BRANCH' AND o.ref_id = b.id ON o.ref_type = 'BRANCH' AND o.ref_id = b.id
LEFT JOIN dashboard_level_store s
ON o.ref_type = 'STORE' AND o.ref_id = s.id LEFT JOIN dashboard_level_store_area_merge sam
LEFT JOIN dashboard_level_area a ON o.ref_type = 'STORE_AREA' AND o.ref_id = sam.id
ON o.ref_type = 'AREA' AND o.ref_id = a.id
LEFT JOIN dashboard_level_site si LEFT JOIN dashboard_level_site si
ON o.ref_type = 'SITE' AND o.ref_id = si.id ON o.ref_type = 'SITE' AND o.ref_id = si.id
LEFT JOIN basic_building bu LEFT JOIN basic_building bu
ON o.ref_type = 'BUILDING' AND o.ref_id = bu.building_id ON o.ref_type = 'BUILDING' AND o.ref_id = bu.building_id
WHERE u.user_id = #{userId} WHERE u.user_id = #{userId}
AND CASE o.ref_type AND CASE o.ref_type
WHEN 'BRANCH' THEN IFNULL(b.flag, 1) WHEN 'BRANCH' THEN IFNULL(b.flag, 1)
WHEN 'STORE' THEN IFNULL(s.flag, 1) WHEN 'STORE_AREA' THEN IFNULL(sam.flag, 1)
WHEN 'AREA' THEN IFNULL(a.flag, 1)
WHEN 'SITE' THEN IFNULL(si.flag, 1) WHEN 'SITE' THEN IFNULL(si.flag, 1)
WHEN 'BUILDING' THEN IFNULL(bu.flag, 1) WHEN 'BUILDING' THEN IFNULL(bu.flag, 1)
END = 0 END = 0
@ -131,22 +145,24 @@
FROM dashboard_level_role_object dlro FROM dashboard_level_role_object dlro
INNER JOIN dashboard_level_role dlr INNER JOIN dashboard_level_role dlr
ON dlr.id = dlro.level_role_id ON dlr.id = dlro.level_role_id
LEFT JOIN dashboard_level_branch b LEFT JOIN dashboard_level_branch b
ON dlro.ref_type = 'BRANCH' AND dlro.ref_id = b.id ON dlro.ref_type = 'BRANCH' AND dlro.ref_id = b.id
LEFT JOIN dashboard_level_store s
ON dlro.ref_type = 'STORE' AND dlro.ref_id = s.id LEFT JOIN dashboard_level_store_area_merge sam
LEFT JOIN dashboard_level_area a ON dlro.ref_type = 'STORE_AREA' AND dlro.ref_id = sam.id
ON dlro.ref_type = 'AREA' AND dlro.ref_id = a.id
LEFT JOIN dashboard_level_site si LEFT JOIN dashboard_level_site si
ON dlro.ref_type = 'SITE' AND dlro.ref_id = si.id ON dlro.ref_type = 'SITE' AND dlro.ref_id = si.id
LEFT JOIN basic_building bu LEFT JOIN basic_building bu
ON dlro.ref_type = 'BUILDING' AND dlro.ref_id = bu.building_id ON dlro.ref_type = 'BUILDING' AND dlro.ref_id = bu.building_id
WHERE dlr.flag != 1 WHERE dlr.flag != 1
AND dlr.id = #{roleId} AND dlr.id = #{roleId}
AND CASE dlro.ref_type AND CASE dlro.ref_type
WHEN 'BRANCH' THEN IFNULL(b.flag, 1) WHEN 'BRANCH' THEN IFNULL(b.flag, 1)
WHEN 'STORE' THEN IFNULL(s.flag, 1) WHEN 'STORE_AREA' THEN IFNULL(sam.flag, 1)
WHEN 'AREA' THEN IFNULL(a.flag, 1)
WHEN 'SITE' THEN IFNULL(si.flag, 1) WHEN 'SITE' THEN IFNULL(si.flag, 1)
WHEN 'BUILDING' THEN IFNULL(bu.flag, 1) WHEN 'BUILDING' THEN IFNULL(bu.flag, 1)
END = 0 END = 0

33
dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/LevelRoleServiceImpl.java

@ -332,8 +332,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
Map<String, Object> levelMap = new HashMap<>(); Map<String, Object> levelMap = new HashMap<>();
levelMap.put("companyId", companyId); levelMap.put("companyId", companyId);
List<RefKey> branches = levelRoleMapperExt.selectAllBranches(levelMap); List<RefKey> branches = levelRoleMapperExt.selectAllBranches(levelMap);
List<RefKey> stores = levelRoleMapperExt.selectAllStores(levelMap); List<RefKey> storeAreas = levelRoleMapperExt.selectAllStoreAreas(levelMap);
List<RefKey> areas = levelRoleMapperExt.selectAllAreas(levelMap);
List<RefKey> sites = levelRoleMapperExt.selectAllSites(levelMap); List<RefKey> sites = levelRoleMapperExt.selectAllSites(levelMap);
List<RefKey> buildings = levelRoleMapperExt.selectAllBuildings(levelMap); List<RefKey> buildings = levelRoleMapperExt.selectAllBuildings(levelMap);
@ -341,8 +340,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
List<RefKey> userRefs = new ArrayList<>(); List<RefKey> userRefs = new ArrayList<>();
if (levelRoleMapperExt.checkLevelManager(userId) > 0){ if (levelRoleMapperExt.checkLevelManager(userId) > 0){
userRefs.addAll(branches); userRefs.addAll(branches);
userRefs.addAll(stores); userRefs.addAll(storeAreas);
userRefs.addAll(areas);
userRefs.addAll(sites); userRefs.addAll(sites);
userRefs.addAll(buildings); userRefs.addAll(buildings);
} else { } else {
@ -350,12 +348,11 @@ public class LevelRoleServiceImpl implements LevelRoleService {
paramMap.put("userId", userId); paramMap.put("userId", userId);
userRefs = levelRoleMapperExt.selectUserRefs(paramMap); userRefs = levelRoleMapperExt.selectUserRefs(paramMap);
// 名称填充 // 名称填充
fillNames(userRefs, branches, stores, areas, sites, buildings); fillNames(userRefs, branches, storeAreas, sites, buildings);
} }
// 构建 parentId → List<RefKey> 的多值 Map // 构建 parentId → List<RefKey> 的多值 Map
Map<Long, List<RefKey>> storeMap = groupByParent(stores); Map<Long, List<RefKey>> storeAreaMap = groupByParent(storeAreas);
Map<Long, List<RefKey>> areaMap = groupByParent(areas);
Map<Long, List<RefKey>> siteMap = groupByParent(sites); Map<Long, List<RefKey>> siteMap = groupByParent(sites);
Map<Long, List<RefKey>> buildingMap = groupByParent(buildings); Map<Long, List<RefKey>> buildingMap = groupByParent(buildings);
@ -380,7 +377,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
// 构建该节点下的子树 // 构建该节点下的子树
root.setChildren(buildTree( root.setChildren(buildTree(
ref.getType(), ref.getId(), rootKey, ref.getType(), ref.getId(), rootKey,
storeMap, areaMap, siteMap, buildingMap, visitedKeys storeAreaMap, siteMap, buildingMap, visitedKeys
)); ));
result.add(root); result.add(root);
} }
@ -398,22 +395,19 @@ public class LevelRoleServiceImpl implements LevelRoleService {
private void fillNames(List<RefKey> userRefs, private void fillNames(List<RefKey> userRefs,
List<RefKey> branches, List<RefKey> branches,
List<RefKey> stores, List<RefKey> storeAreas,
List<RefKey> areas,
List<RefKey> sites, List<RefKey> sites,
List<RefKey> buildings) { List<RefKey> buildings) {
Map<Long, String> branchName = toNameMap(branches); Map<Long, String> branchName = toNameMap(branches);
Map<Long, String> storeName = toNameMap(stores); Map<Long, String> storeAreaName = toNameMap(storeAreas);
Map<Long, String> areaName = toNameMap(areas);
Map<Long, String> siteName = toNameMap(sites); Map<Long, String> siteName = toNameMap(sites);
Map<Long, String> buildingName = toNameMap(buildings); Map<Long, String> buildingName = toNameMap(buildings);
userRefs.removeIf(r -> { userRefs.removeIf(r -> {
String name = switch (r.getType()) { String name = switch (r.getType()) {
case "BRANCH" -> branchName.get(r.getId()); case "BRANCH" -> branchName.get(r.getId());
case "STORE" -> storeName.get(r.getId()); case "STORE_AREA" -> storeAreaName.get(r.getId());
case "AREA" -> areaName.get(r.getId());
case "SITE" -> siteName.get(r.getId()); case "SITE" -> siteName.get(r.getId());
case "BUILDING" -> buildingName.get(r.getId()); case "BUILDING" -> buildingName.get(r.getId());
default -> null; default -> null;
@ -443,19 +437,18 @@ public class LevelRoleServiceImpl implements LevelRoleService {
private List<TreeMenusDTO> buildTree(String type, private List<TreeMenusDTO> buildTree(String type,
Long parentId, Long parentId,
String parentKey, String parentKey,
Map<Long, List<RefKey>> storeMap, Map<Long, List<RefKey>> storeAreaMap,
Map<Long, List<RefKey>> areaMap,
Map<Long, List<RefKey>> siteMap, Map<Long, List<RefKey>> siteMap,
Map<Long, List<RefKey>> buildingMap, Map<Long, List<RefKey>> buildingMap,
Set<String> visitedKeys) { Set<String> visitedKeys) {
Map<Long, List<RefKey>> childMap = switch (type) { Map<Long, List<RefKey>> childMap = switch (type) {
case "BRANCH" -> storeMap; case "BRANCH" -> storeAreaMap;
case "STORE" -> areaMap; case "STORE_AREA" -> siteMap;
case "AREA" -> siteMap;
case "SITE" -> buildingMap; case "SITE" -> buildingMap;
default -> null; default -> null;
}; };
if (childMap == null) return Collections.emptyList(); if (childMap == null) return Collections.emptyList();
// 直接取 parentId 的子节点 // 直接取 parentId 的子节点
@ -477,7 +470,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
node.setChildren(buildTree( node.setChildren(buildTree(
c.getType(), c.getId(), key, c.getType(), c.getId(), key,
storeMap, areaMap, siteMap, buildingMap, visitedKeys storeAreaMap, siteMap, buildingMap, visitedKeys
)); ));
list.add(node); list.add(node);

Loading…
Cancel
Save