diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index 4f5a4744b..041671d41 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -48,7 +48,9 @@ public class AdminController { public CommonResult> menuResourceTree() { List resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, AdminSecurityContextHolder.getContext().getRoleIds()); // 创建 AdminMenuTreeNodeVO Map - Map treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert)); +// Map treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert)); + Map treeNodeMap = new LinkedHashMap<>(); // 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。 + resources.stream().sorted(Comparator.comparing(ResourceBO::getSort)).forEach(resourceBO -> treeNodeMap.put(resourceBO.getId(), ResourceConvert.INSTANCE.convert(resourceBO))); // 处理父子关系 treeNodeMap.values().stream() .filter(node -> !node.getPid().equals(ResourceConstants.PID_ROOT)) @@ -64,7 +66,7 @@ public class AdminController { // 获得到所有的根节点 List rootNodes = treeNodeMap.values().stream() .filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT)) - .sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort)) +// .sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort)) .collect(Collectors.toList()); return CommonResult.success(rootNodes); }