|
@@ -7,6 +7,8 @@ import cn.hutool.extra.spring.SpringUtil;
|
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
|
|
+import cn.iocoder.yudao.module.employee.api.EmployeeApi;
|
|
|
+import cn.iocoder.yudao.module.employee.api.dto.EmployeeRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuRespVO;
|
|
@@ -60,6 +62,8 @@ public class PermissionServiceImpl implements PermissionService {
|
|
|
private DeptService deptService;
|
|
|
@Resource
|
|
|
private AdminUserService userService;
|
|
|
+ @Resource
|
|
|
+ private EmployeeApi employeeApi;
|
|
|
|
|
|
@Override
|
|
|
public boolean hasAnyPermissions(Long userId, String... permissions) {
|
|
@@ -284,7 +288,11 @@ public class PermissionServiceImpl implements PermissionService {
|
|
|
}
|
|
|
|
|
|
// 获得用户的部门编号的缓存,通过 Guava 的 Suppliers 惰性求值,即有且仅有第一次发起 DB 的查询
|
|
|
- Supplier<Long> userDeptId = Suppliers.memoize(() -> userService.getUser(userId).getDeptId());
|
|
|
+ Supplier<Long> userDept = Suppliers.memoize(() -> userService.getUser(userId).getDeptId());
|
|
|
+ Long userDeptId = userDept.get();
|
|
|
+ // 设置为用户对应员工的部门
|
|
|
+ EmployeeRespDTO employee = employeeApi.getEmployeeByUserId(userId);
|
|
|
+ userDeptId = employee.getDeptId();
|
|
|
// 遍历每个角色,计算
|
|
|
for (RoleDO role : roles) {
|
|
|
// 为空时,跳过
|
|
@@ -301,19 +309,19 @@ public class PermissionServiceImpl implements PermissionService {
|
|
|
CollUtil.addAll(result.getDeptIds(), role.getDataScopeDeptIds());
|
|
|
// 自定义可见部门时,保证可以看到自己所在的部门。否则,一些场景下可能会有问题。
|
|
|
// 例如说,登录时,基于 t_user 的 username 查询会可能被 dept_id 过滤掉
|
|
|
- CollUtil.addAll(result.getDeptIds(), userDeptId.get());
|
|
|
+ CollUtil.addAll(result.getDeptIds(), userDeptId);
|
|
|
continue;
|
|
|
}
|
|
|
// 情况三,DEPT_ONLY
|
|
|
if (Objects.equals(role.getDataScope(), DataScopeEnum.DEPT_ONLY.getScope())) {
|
|
|
- CollectionUtils.addIfNotNull(result.getDeptIds(), userDeptId.get());
|
|
|
+ CollectionUtils.addIfNotNull(result.getDeptIds(), userDeptId);
|
|
|
continue;
|
|
|
}
|
|
|
// 情况四,DEPT_DEPT_AND_CHILD
|
|
|
if (Objects.equals(role.getDataScope(), DataScopeEnum.DEPT_AND_CHILD.getScope())) {
|
|
|
- CollUtil.addAll(result.getDeptIds(), deptService.getChildDeptIdListFromCache(userDeptId.get()));
|
|
|
+ CollUtil.addAll(result.getDeptIds(), deptService.getChildDeptIdListFromCache(userDeptId));
|
|
|
// 添加本身部门编号
|
|
|
- CollUtil.addAll(result.getDeptIds(), userDeptId.get());
|
|
|
+ CollUtil.addAll(result.getDeptIds(), userDeptId);
|
|
|
continue;
|
|
|
}
|
|
|
// 情况五,SELF
|