Commit 1c7ba5c0d6f2dbb95e916aa45eec32a94103a96f
1 parent
6419aef3
【修复】获取菜单精简信息列表接口没有排除父 ID 非 0 的节点
Showing
2 changed files
with
7 additions
and
4 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
| @@ -109,9 +109,10 @@ public class AuthController { | @@ -109,9 +109,10 @@ public class AuthController { | ||
| 109 | // 1.3 获得菜单列表 | 109 | // 1.3 获得菜单列表 |
| 110 | Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId)); | 110 | Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId)); |
| 111 | List<MenuDO> menuList = menuService.getMenuList(menuIds); | 111 | List<MenuDO> menuList = menuService.getMenuList(menuIds); |
| 112 | - // 过滤掉关闭的菜单及其子菜单 | 112 | + // 过滤掉关闭的菜单 |
| 113 | menuList = menuService.filterClosedMenus(menuList); | 113 | menuList = menuService.filterClosedMenus(menuList); |
| 114 | 114 | ||
| 115 | + menuList.removeIf(menu -> !CommonStatusEnum.ENABLE.getStatus().equals(menu.getStatus())); // 移除禁用的菜单 | ||
| 115 | // 2. 拼接结果返回 | 116 | // 2. 拼接结果返回 |
| 116 | return success(AuthConvert.INSTANCE.convert(user, roles, menuList)); | 117 | return success(AuthConvert.INSTANCE.convert(user, roles, menuList)); |
| 117 | } | 118 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
| @@ -126,16 +126,18 @@ public class MenuServiceImpl implements MenuService { | @@ -126,16 +126,18 @@ public class MenuServiceImpl implements MenuService { | ||
| 126 | if(CollectionUtils.isEmpty(menuList)){ | 126 | if(CollectionUtils.isEmpty(menuList)){ |
| 127 | return Collections.emptyList(); | 127 | return Collections.emptyList(); |
| 128 | } | 128 | } |
| 129 | + List<MenuDO> allMenuList = getMenuList(); | ||
| 130 | + | ||
| 129 | // 根据parentId快速查找子节点 | 131 | // 根据parentId快速查找子节点 |
| 130 | - Map<Long, List<MenuDO>> childrenMap = menuList.stream() | 132 | + Map<Long, List<MenuDO>> childrenMap = allMenuList.stream() |
| 131 | .collect(Collectors.groupingBy(MenuDO::getParentId)); | 133 | .collect(Collectors.groupingBy(MenuDO::getParentId)); |
| 132 | 134 | ||
| 133 | // 所有关闭的节点ID | 135 | // 所有关闭的节点ID |
| 134 | Set<Long> closedNodeIds = new HashSet<>(); | 136 | Set<Long> closedNodeIds = new HashSet<>(); |
| 135 | 137 | ||
| 136 | // 标记所有关闭的节点 | 138 | // 标记所有关闭的节点 |
| 137 | - for (MenuDO menu : menuList) { | ||
| 138 | - if (Objects.equals(menu.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { | 139 | + for (MenuDO menu : allMenuList) { |
| 140 | + if (!Objects.equals(menu.getStatus(), CommonStatusEnum.ENABLE.getStatus())) { | ||
| 139 | markClosedNodes(menu.getId(), childrenMap, closedNodeIds); | 141 | markClosedNodes(menu.getId(), childrenMap, closedNodeIds); |
| 140 | } | 142 | } |
| 141 | } | 143 | } |