【修复】获取菜单精简信息列表接口没有排除父 ID 非 0 的节点

This commit is contained in:
dongdong.xiang 2024-06-16 22:41:32 +08:00
parent 6419aef36c
commit 1c7ba5c0d6
2 changed files with 7 additions and 4 deletions

View File

@ -109,9 +109,10 @@ public class AuthController {
// 1.3 获得菜单列表 // 1.3 获得菜单列表
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId)); Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId));
List<MenuDO> menuList = menuService.getMenuList(menuIds); List<MenuDO> menuList = menuService.getMenuList(menuIds);
// 过滤掉关闭的菜单及其子菜单 // 过滤掉关闭的菜单
menuList = menuService.filterClosedMenus(menuList); menuList = menuService.filterClosedMenus(menuList);
menuList.removeIf(menu -> !CommonStatusEnum.ENABLE.getStatus().equals(menu.getStatus())); // 移除禁用的菜单
// 2. 拼接结果返回 // 2. 拼接结果返回
return success(AuthConvert.INSTANCE.convert(user, roles, menuList)); return success(AuthConvert.INSTANCE.convert(user, roles, menuList));
} }

View File

@ -126,16 +126,18 @@ public class MenuServiceImpl implements MenuService {
if(CollectionUtils.isEmpty(menuList)){ if(CollectionUtils.isEmpty(menuList)){
return Collections.emptyList(); return Collections.emptyList();
} }
List<MenuDO> allMenuList = getMenuList();
// 根据parentId快速查找子节点 // 根据parentId快速查找子节点
Map<Long, List<MenuDO>> childrenMap = menuList.stream() Map<Long, List<MenuDO>> childrenMap = allMenuList.stream()
.collect(Collectors.groupingBy(MenuDO::getParentId)); .collect(Collectors.groupingBy(MenuDO::getParentId));
// 所有关闭的节点ID // 所有关闭的节点ID
Set<Long> closedNodeIds = new HashSet<>(); Set<Long> closedNodeIds = new HashSet<>();
// 标记所有关闭的节点 // 标记所有关闭的节点
for (MenuDO menu : menuList) { for (MenuDO menu : allMenuList) {
if (Objects.equals(menu.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { if (!Objects.equals(menu.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
markClosedNodes(menu.getId(), childrenMap, closedNodeIds); markClosedNodes(menu.getId(), childrenMap, closedNodeIds);
} }
} }