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)); }