Parcourir la source

系统树权限展示bug修复

haoyu il y a 2 ans
Parent
commit
c80a59e60e

+ 7 - 6
src/main/java/com/ydtech/modules/admin/service/impl/SysUserServiceImpl.java

@@ -754,11 +754,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         // 获取可能作为顶层节点的用户ID列表
         List<String> topUserId = users.stream().map(SysUser::getLeaderId).collect(Collectors.toList());
 
-        List<SysUser> list2;
+        List<SysUser> list2 = lambdaQuery().in(SysUser::getId, topUserId).list();
+
+        List<String> strings = list2.stream().map(SysUser::getId).collect(Collectors.toList());
         // 根据组织结构展示级别,筛选顶层节点并构建组织结构树
         switch (treeShowLevel.getShowLevel()) {
             case "all": // 展示所有级别的用户
-                list2 = lambdaQuery().in(SysUser::getId, topUserId).list();
                 // 从查询结果中筛选出没有上级的人员,作为组织结构树的顶层节点
                 for (SysUser sysUser : list2) {
                     if (Objects.isNull(sysUser.getLeaderId())) {
@@ -769,20 +770,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
                 buildUserTree(topUsers, users);
                 break;
             case "same": // 只展示当前用户
-                for (String ids : topUserId) {
+                for (String ids : strings) {
                     if (ids.equals(userId)) {
                         topUsers.add(user);
                     }
                 }
                 break;
             case "subordinate": // 只展示当前用户及下属
-                for (String ids : topUserId) {
+                for (String ids : strings) {
                     if (ids.equals(userId)) {
                         topUsers.add(user);
-                        // 递归构建用户树结构
-                        buildUserTree(topUsers, users);
                     }
                 }
+                // 递归构建用户树结构
+                buildUserTree(topUsers, users);
                 break;
         }
         return topUsers;