|
|
|
@ -1,9 +1,10 @@ |
|
|
|
package com.techsor.datacenter.business.service.impl; |
|
|
|
|
|
|
|
import java.text.MessageFormat; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import com.techsor.datacenter.business.vo.role.DashboardTreeMenusDTO; |
|
|
|
import jakarta.servlet.http.Cookie; |
|
|
|
import jakarta.servlet.http.HttpServletRequest; |
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
@ -183,11 +184,16 @@ public class AccountServiceImpl implements AccountService { |
|
|
|
cacheUserData.setMfaSwitch(userInfoVO.getMfaSwitch()); |
|
|
|
cacheUserData.setMfaBind(userInfoVO.getMfaBind()); |
|
|
|
cacheUserData.setEmail(userInfoVO.getEmail()); |
|
|
|
Map<String, Object> menuMap = new HashMap<>(); |
|
|
|
menuMap.put("userId", userInfoVO.getId()); |
|
|
|
menuMap.put("superRole", userInfoVO.getSuperRole()); |
|
|
|
menuMap.put("targetPlatform", targetPlatform);//区分dashboard等菜单
|
|
|
|
cacheUserData.setMenuIds(basicUserMapperExt.getMenuIdsByUserId(menuMap)); |
|
|
|
|
|
|
|
|
|
|
|
if (null != targetPlatform && 2 == targetPlatform) { |
|
|
|
cacheUserData.setMenuIds(getDashboardMenuIdsForUser(userInfoVO.getId(), userInfoVO.getSuperRole())); |
|
|
|
} else { |
|
|
|
Map<String, Object> menuMap = new HashMap<>(); |
|
|
|
menuMap.put("userId", userInfoVO.getId()); |
|
|
|
menuMap.put("superRole", userInfoVO.getSuperRole()); |
|
|
|
cacheUserData.setMenuIds(basicUserMapperExt.getMenuIdsByUserId(menuMap)); |
|
|
|
} |
|
|
|
|
|
|
|
response.setHeader("AccessToken", accessToken); |
|
|
|
|
|
|
|
@ -222,6 +228,85 @@ public class AccountServiceImpl implements AccountService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public String getDashboardMenuIdsForUser(Long userId, Integer superRole) { |
|
|
|
List<DashboardTreeMenusDTO> allMenus = |
|
|
|
basicUserMapperExt.selectAllDashboardMenu(Collections.emptyMap()); |
|
|
|
// 超级管理员:直接返回全部菜单
|
|
|
|
if (superRole == 1) { |
|
|
|
return allMenus.stream() |
|
|
|
.map(DashboardTreeMenusDTO::getMenuId) |
|
|
|
.collect(Collectors.joining(",")); |
|
|
|
} |
|
|
|
|
|
|
|
// ================= 普通用户 =================
|
|
|
|
// 查询用户叶子权限(dashboard_lowest_node=1)
|
|
|
|
List<DashboardTreeMenusDTO> userMenus = |
|
|
|
basicUserMapperExt.selectDashboardMenusByUserId(userId); |
|
|
|
|
|
|
|
if (userMenus == null || userMenus.isEmpty()) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, DashboardTreeMenusDTO> allMenuMap = allMenus.stream() |
|
|
|
.collect(Collectors.toMap(DashboardTreeMenusDTO::getMenuId, m -> m)); |
|
|
|
|
|
|
|
// 🔥 提前构建 parent -> children 映射(性能优化)
|
|
|
|
Map<String, List<DashboardTreeMenusDTO>> childrenMap = new HashMap<>(); |
|
|
|
for (DashboardTreeMenusDTO menu : allMenus) { |
|
|
|
childrenMap |
|
|
|
.computeIfAbsent(menu.getParentMenuId(), k -> new ArrayList<>()) |
|
|
|
.add(menu); |
|
|
|
} |
|
|
|
|
|
|
|
Set<String> resultIds = new HashSet<>(); |
|
|
|
|
|
|
|
// 核心逻辑
|
|
|
|
for (DashboardTreeMenusDTO menu : userMenus) { |
|
|
|
|
|
|
|
String menuId = menu.getMenuId(); |
|
|
|
Integer permissionType = menu.getPermissionType(); |
|
|
|
|
|
|
|
resultIds.add(menuId); |
|
|
|
|
|
|
|
// ===== 向上找父节点 =====
|
|
|
|
if (permissionType != null && permissionType != 0) { |
|
|
|
String parentId = menu.getParentMenuId(); |
|
|
|
|
|
|
|
while (parentId != null && !"-1".equals(parentId)) { |
|
|
|
if (!resultIds.add(parentId)) { |
|
|
|
break; // 已存在直接结束(防止死循环)
|
|
|
|
} |
|
|
|
|
|
|
|
DashboardTreeMenusDTO parent = allMenuMap.get(parentId); |
|
|
|
if (parent == null) break; |
|
|
|
|
|
|
|
parentId = parent.getParentMenuId(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ===== permission=2 向下找所有子节点 =====
|
|
|
|
if (permissionType != null && permissionType == 2) { |
|
|
|
addAllChildren(menuId, childrenMap, resultIds); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return String.join(",", resultIds); |
|
|
|
} |
|
|
|
|
|
|
|
private void addAllChildren(String menuId, |
|
|
|
Map<String, List<DashboardTreeMenusDTO>> childrenMap, |
|
|
|
Set<String> resultIds) { |
|
|
|
|
|
|
|
List<DashboardTreeMenusDTO> children = childrenMap.get(menuId); |
|
|
|
if (children == null) return; |
|
|
|
|
|
|
|
for (DashboardTreeMenusDTO child : children) { |
|
|
|
if (resultIds.add(child.getMenuId())) { |
|
|
|
addAllChildren(child.getMenuId(), childrenMap, resultIds); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void handleLock(UserInfoVO userInfoVO, Integer languageType) { |
|
|
|
String lockKey = String.format(Constants.LOGIN_LOCK, userInfoVO.getId()); |
|
|
|
|