修复获得管理员权限时,排序错误的问题
parent
f47e564772
commit
6b6b4d9514
|
@ -48,7 +48,9 @@ public class AdminController {
|
||||||
public CommonResult<List<AdminMenuTreeNodeVO>> menuResourceTree() {
|
public CommonResult<List<AdminMenuTreeNodeVO>> menuResourceTree() {
|
||||||
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, AdminSecurityContextHolder.getContext().getRoleIds());
|
List<ResourceBO> resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, AdminSecurityContextHolder.getContext().getRoleIds());
|
||||||
// 创建 AdminMenuTreeNodeVO Map
|
// 创建 AdminMenuTreeNodeVO Map
|
||||||
Map<Integer, AdminMenuTreeNodeVO> treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert));
|
// Map<Integer, AdminMenuTreeNodeVO> treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert));
|
||||||
|
Map<Integer, AdminMenuTreeNodeVO> 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()
|
treeNodeMap.values().stream()
|
||||||
.filter(node -> !node.getPid().equals(ResourceConstants.PID_ROOT))
|
.filter(node -> !node.getPid().equals(ResourceConstants.PID_ROOT))
|
||||||
|
@ -64,7 +66,7 @@ public class AdminController {
|
||||||
// 获得到所有的根节点
|
// 获得到所有的根节点
|
||||||
List<AdminMenuTreeNodeVO> rootNodes = treeNodeMap.values().stream()
|
List<AdminMenuTreeNodeVO> rootNodes = treeNodeMap.values().stream()
|
||||||
.filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT))
|
.filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT))
|
||||||
.sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort))
|
// .sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return CommonResult.success(rootNodes);
|
return CommonResult.success(rootNodes);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue