机构查询 区分管理员和普通用户查询方式
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run

This commit is contained in:
lxd 2024-08-31 01:56:38 +08:00
parent e559c8f2ba
commit 192c0f67cf

View File

@ -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<List<OrgUnitRespVO>> getlist() {
List<OrgUnitDO> aDo = Service.getOrgUnitList();
//获取当前登陆用户
AdminUserDO user = userService.getUser(getLoginUserId());
// 获取当前用户所拥有的角色
List<RoleDO> 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));
}