From 192c0f67cf11463ea0d652549c6061ae352e601f Mon Sep 17 00:00:00 2001 From: lxd <1004405501@qq.com> Date: Sat, 31 Aug 2024 01:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E6=9E=84=E6=9F=A5=E8=AF=A2=20?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E7=AE=A1=E7=90=86=E5=91=98=E5=92=8C=E6=99=AE?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E6=88=B7=E6=9F=A5=E8=AF=A2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/org/OrgUnitController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/org/OrgUnitController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/org/OrgUnitController.java index 4a4bcb25e..7ff273ce5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/org/OrgUnitController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/org/OrgUnitController.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.system.controller.admin.org; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.service.permission.PermissionService; +import cn.iocoder.yudao.module.system.service.permission.RoleService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.starter.annotation.LogRecord; @@ -16,6 +19,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.io.IOException; +import java.util.stream.Collectors; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -48,6 +52,12 @@ public class OrgUnitController { private OrgUnitService Service; @Resource private AdminUserService userService; + + @Resource + private PermissionService permissionService; + @Resource + private RoleService roleService; + @PostMapping("/create") @Operation(summary = "创建机构管理") @PreAuthorize("@ss.hasPermission('org::create')") @@ -108,6 +118,20 @@ public class OrgUnitController { @PreAuthorize("@ss.hasPermission('org::query')") public CommonResult> getlist() { List aDo = Service.getOrgUnitList(); + //获取当前登陆用户 + AdminUserDO user = userService.getUser(getLoginUserId()); +// 获取当前用户所拥有的角色 + List userRoles = roleService.getRoleListFromCache(permissionService.getUserRoleIdListByUserId(user.getId())); +// 判断是否有角色名称包含"管理员" + boolean containsAdmin = userRoles.stream() + .anyMatch(role -> role.getName().contains("管理员")); + + if (!containsAdmin) { + // 筛选条件: + aDo = aDo.stream() + .filter(OrgUnitDO -> Objects.equals(OrgUnitDO.getOrgID(), user.getOrgId())) + .collect(Collectors.toList()); + } return success(BeanUtils.toBean(aDo, OrgUnitRespVO.class)); }