From 17378574f495b8b0fa88e1a49a12d022664bdf9d Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期四, 20 十一月 2025 11:18:11 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mobile_community
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java | 39 +++++++++++++++++++++++++++++++++++----
1 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
index b4855e9..7f1f50c 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
@@ -19,6 +19,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
@@ -542,13 +543,43 @@
public List<SysMenu> roleInfoFromUserId(Long userId) {
SysRole sysRole = roleMapper.selectRoleByUserId(userId);
// 获取当前角色的菜单列表
- List<SysMenu> menus = menuMapper.selectListByRoleId(sysRole.getRoleId());
- if(menus.size()==0){
+ List<SysRoleMenu> roleMenus = menuMapper.selectRoleMenuByRoleId(sysRole.getRoleId());
+ if(CollectionUtils.isEmpty(roleMenus)){
return new ArrayList<>();
}
- List<Long> menusId = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
+ List<Long> menusId = roleMenus.stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
// 获取当前的权限菜单(有层级)
- return this.getMenuLevelList(menusId);
+ return this.getResourcesLevelList(menusId);
+ }
+
+ public List<SysMenu> getResourcesLevelList(List<Long> menusId) {
+ //获取当前的权限菜单
+ List<SysMenu> allResources = menuMapper.getAllInIds(menusId);
+ SysMenu item;
+ //获取根节点的集合
+ List<SysMenu> root = new ArrayList<>();
+ Map<Long, SysMenu> tempMap = new HashMap<>(3);
+ //子节点集合
+ SysMenu parent;
+ for (SysMenu resources : allResources) {
+ item = com.ruoyi.system.utils.util.SpringUtils.beanCopy(resources, SysMenu.class);
+ //每次循环都将集合重新循环添加到父集合中
+ tempMap.put(resources.getMenuId(), item);
+ parent = tempMap.get(resources.getParentId());
+ if (Objects.nonNull(parent)) {
+ //父集合不为空时,获取下级集合
+ //子节点集合
+ parent.getChildren().add(item);
+ // 对子集排序,升序
+// parent.getChildren().sort(comparing(SysMenu::getSort));
+ } else {
+ //根集合
+ root.add(item);
+ // 对根集合排序,升序
+// root.sort(comparing(SysMenu::getSort));
+ }
+ }
+ return root;
}
@Override
--
Gitblit v1.7.1