From 029c4cfba82fbbe37d3e854a6e7f04ac743a4ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E7=8E=89=E7=A5=A5?= Date: Sat, 4 Mar 2023 23:59:02 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9B=B4=E6=96=B0=E3=80=91=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E7=94=A8=E6=88=B7=E7=8B=AC=E7=AB=8B=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=92=8C=E6=9D=83=E9=99=90=EF=BC=8C=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/service/impl/SysUserServiceImpl.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java index da590034..3784b299 100644 --- a/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java +++ b/snowy-plugin/snowy-plugin-sys/src/main/java/vip/xiaonuo/sys/modular/user/service/impl/SysUserServiceImpl.java @@ -29,6 +29,7 @@ import cn.hutool.core.lang.tree.TreeNode; import cn.hutool.core.lang.tree.TreeNodeConfig; import cn.hutool.core.lang.tree.TreeUtil; import cn.hutool.core.lang.tree.parser.DefaultNodeParser; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.PhoneUtil; import cn.hutool.core.util.RandomUtil; @@ -556,7 +557,8 @@ public class SysUserServiceImpl extends ServiceImpl impl List roleIdList = this.ownRole(sysUserIdParam); // 获取菜单id列表 - List menuIdList = CollectionUtil.newArrayList(); + List menuIdList = sysRelationService.getRelationTargetIdListByObjectIdAndCategory(sysUserIdParam.getId(), + SysRelationCategoryEnum.SYS_USER_HAS_RESOURCE.getValue());; if (ObjectUtil.isNotEmpty(roleIdList)) { menuIdList = sysRelationService.getRelationTargetIdListByObjectIdListAndCategory(roleIdList, @@ -930,36 +932,35 @@ public class SysUserServiceImpl extends ServiceImpl impl @Override public List getPermissionList(String userId, String orgId) { - List permissionListGrantUser = this.getPermissionListGrantUser(userId, orgId); - List permissionListGrantRole = this.getPermissionListGrantRole(userId, orgId); - // TODO 执行合并 - return permissionListGrantUser; + Map> permissionListGrantUser = this.getPermissionListGrantUser(userId, orgId); + Map> permissionListGrantRole = this.getPermissionListGrantRole(userId, orgId); + permissionListGrantUser.forEach((key, value) -> permissionListGrantRole.merge(key, value, (prev, next) -> { + prev.addAll(next); + return prev; + })); + return getScopeListByMap(permissionListGrantRole, orgId); } - public List getPermissionListGrantUser(String userId, String orgId) { + public Map> getPermissionListGrantUser(String userId, String orgId) { if (ObjectUtil.isNotEmpty(orgId)) { - Map> groupMap = sysRelationService.getRelationListByObjectIdAndCategory(userId, - SysRelationCategoryEnum.SYS_USER_HAS_PERMISSION.getValue()).stream().collect(Collectors.groupingBy(SysRelation::getTargetId)); - if (ObjectUtil.isNotEmpty(groupMap)) { - return getScopeListByMap(groupMap, orgId); - } + return sysRelationService.getRelationListByObjectIdAndCategory(userId, + SysRelationCategoryEnum.SYS_USER_HAS_PERMISSION.getValue()).stream() + .collect(Collectors.groupingBy(SysRelation::getTargetId)); } - return CollectionUtil.newArrayList(); + return MapUtil.newHashMap(); } - public List getPermissionListGrantRole(String userId, String orgId) { + public Map> getPermissionListGrantRole(String userId, String orgId) { if (ObjectUtil.isNotEmpty(orgId)) { List roleIdList = sysRelationService.getRelationTargetIdListByObjectIdAndCategory(userId, SysRelationCategoryEnum.SYS_USER_HAS_ROLE.getValue()); if (ObjectUtil.isNotEmpty(roleIdList)) { - Map> groupMap = sysRelationService.getRelationListByObjectIdListAndCategory(roleIdList, - SysRelationCategoryEnum.SYS_ROLE_HAS_PERMISSION.getValue()).stream().collect(Collectors.groupingBy(SysRelation::getTargetId)); - if (ObjectUtil.isNotEmpty(groupMap)) { - return getScopeListByMap(groupMap, orgId); - } + return sysRelationService.getRelationListByObjectIdListAndCategory(roleIdList, + SysRelationCategoryEnum.SYS_ROLE_HAS_PERMISSION.getValue()).stream() + .collect(Collectors.groupingBy(SysRelation::getTargetId)); } } - return CollectionUtil.newArrayList(); + return MapUtil.newHashMap(); } public List getScopeListByMap(Map> groupMap, String orgId) {