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. 44
      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);
Integer checkLevelManager(Long userId);
List<RefKey> selectAllStoreAreas(Map<String, Object> levelMap);
}

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

@ -97,28 +97,42 @@
WHERE b.flag = 0 and b.company_id = #{companyId}
</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 o.ref_type AS type,
o.ref_id AS id
SELECT
o.ref_type AS type,
o.ref_id AS id
FROM dashboard_level_role_user u
INNER JOIN dashboard_level_role_object o
ON u.level_role_id = o.level_role_id
LEFT JOIN dashboard_level_branch b
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_area a
ON o.ref_type = 'AREA' AND o.ref_id = a.id
LEFT JOIN dashboard_level_store_area_merge sam
ON o.ref_type = 'STORE_AREA' AND o.ref_id = sam.id
LEFT JOIN dashboard_level_site si
ON o.ref_type = 'SITE' AND o.ref_id = si.id
LEFT JOIN basic_building bu
ON o.ref_type = 'BUILDING' AND o.ref_id = bu.building_id
WHERE u.user_id = #{userId}
AND CASE o.ref_type
WHEN 'BRANCH' THEN IFNULL(b.flag, 1)
WHEN 'STORE' THEN IFNULL(s.flag, 1)
WHEN 'AREA' THEN IFNULL(a.flag, 1)
WHEN 'STORE_AREA' THEN IFNULL(sam.flag, 1)
WHEN 'SITE' THEN IFNULL(si.flag, 1)
WHEN 'BUILDING' THEN IFNULL(bu.flag, 1)
END = 0
@ -131,22 +145,24 @@
FROM dashboard_level_role_object dlro
INNER JOIN dashboard_level_role dlr
ON dlr.id = dlro.level_role_id
LEFT JOIN dashboard_level_branch b
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_area a
ON dlro.ref_type = 'AREA' AND dlro.ref_id = a.id
LEFT JOIN dashboard_level_store_area_merge sam
ON dlro.ref_type = 'STORE_AREA' AND dlro.ref_id = sam.id
LEFT JOIN dashboard_level_site si
ON dlro.ref_type = 'SITE' AND dlro.ref_id = si.id
LEFT JOIN basic_building bu
ON dlro.ref_type = 'BUILDING' AND dlro.ref_id = bu.building_id
WHERE dlr.flag != 1
AND dlr.id = #{roleId}
AND CASE dlro.ref_type
WHEN 'BRANCH' THEN IFNULL(b.flag, 1)
WHEN 'STORE' THEN IFNULL(s.flag, 1)
WHEN 'AREA' THEN IFNULL(a.flag, 1)
WHEN 'STORE_AREA' THEN IFNULL(sam.flag, 1)
WHEN 'SITE' THEN IFNULL(si.flag, 1)
WHEN 'BUILDING' THEN IFNULL(bu.flag, 1)
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<>();
levelMap.put("companyId", companyId);
List<RefKey> branches = levelRoleMapperExt.selectAllBranches(levelMap);
List<RefKey> stores = levelRoleMapperExt.selectAllStores(levelMap);
List<RefKey> areas = levelRoleMapperExt.selectAllAreas(levelMap);
List<RefKey> storeAreas = levelRoleMapperExt.selectAllStoreAreas(levelMap);
List<RefKey> sites = levelRoleMapperExt.selectAllSites(levelMap);
List<RefKey> buildings = levelRoleMapperExt.selectAllBuildings(levelMap);
@ -341,8 +340,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
List<RefKey> userRefs = new ArrayList<>();
if (levelRoleMapperExt.checkLevelManager(userId) > 0){
userRefs.addAll(branches);
userRefs.addAll(stores);
userRefs.addAll(areas);
userRefs.addAll(storeAreas);
userRefs.addAll(sites);
userRefs.addAll(buildings);
} else {
@ -350,12 +348,11 @@ public class LevelRoleServiceImpl implements LevelRoleService {
paramMap.put("userId", userId);
userRefs = levelRoleMapperExt.selectUserRefs(paramMap);
// 名称填充
fillNames(userRefs, branches, stores, areas, sites, buildings);
fillNames(userRefs, branches, storeAreas, sites, buildings);
}
// 构建 parentId → List<RefKey> 的多值 Map
Map<Long, List<RefKey>> storeMap = groupByParent(stores);
Map<Long, List<RefKey>> areaMap = groupByParent(areas);
Map<Long, List<RefKey>> storeAreaMap = groupByParent(storeAreas);
Map<Long, List<RefKey>> siteMap = groupByParent(sites);
Map<Long, List<RefKey>> buildingMap = groupByParent(buildings);
@ -380,7 +377,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
// 构建该节点下的子树
root.setChildren(buildTree(
ref.getType(), ref.getId(), rootKey,
storeMap, areaMap, siteMap, buildingMap, visitedKeys
storeAreaMap, siteMap, buildingMap, visitedKeys
));
result.add(root);
}
@ -398,22 +395,19 @@ public class LevelRoleServiceImpl implements LevelRoleService {
private void fillNames(List<RefKey> userRefs,
List<RefKey> branches,
List<RefKey> stores,
List<RefKey> areas,
List<RefKey> storeAreas,
List<RefKey> sites,
List<RefKey> buildings) {
Map<Long, String> branchName = toNameMap(branches);
Map<Long, String> storeName = toNameMap(stores);
Map<Long, String> areaName = toNameMap(areas);
Map<Long, String> storeAreaName = toNameMap(storeAreas);
Map<Long, String> siteName = toNameMap(sites);
Map<Long, String> buildingName = toNameMap(buildings);
userRefs.removeIf(r -> {
String name = switch (r.getType()) {
case "BRANCH" -> branchName.get(r.getId());
case "STORE" -> storeName.get(r.getId());
case "AREA" -> areaName.get(r.getId());
case "STORE_AREA" -> storeAreaName.get(r.getId());
case "SITE" -> siteName.get(r.getId());
case "BUILDING" -> buildingName.get(r.getId());
default -> null;
@ -443,19 +437,18 @@ public class LevelRoleServiceImpl implements LevelRoleService {
private List<TreeMenusDTO> buildTree(String type,
Long parentId,
String parentKey,
Map<Long, List<RefKey>> storeMap,
Map<Long, List<RefKey>> areaMap,
Map<Long, List<RefKey>> storeAreaMap,
Map<Long, List<RefKey>> siteMap,
Map<Long, List<RefKey>> buildingMap,
Set<String> visitedKeys) {
Map<Long, List<RefKey>> childMap = switch (type) {
case "BRANCH" -> storeMap;
case "STORE" -> areaMap;
case "AREA" -> siteMap;
case "BRANCH" -> storeAreaMap;
case "STORE_AREA" -> siteMap;
case "SITE" -> buildingMap;
default -> null;
};
if (childMap == null) return Collections.emptyList();
// 直接取 parentId 的子节点
@ -477,7 +470,7 @@ public class LevelRoleServiceImpl implements LevelRoleService {
node.setChildren(buildTree(
c.getType(), c.getId(), key,
storeMap, areaMap, siteMap, buildingMap, visitedKeys
storeAreaMap, siteMap, buildingMap, visitedKeys
));
list.add(node);

Loading…
Cancel
Save