Browse Source

1、数据权限非空判断

dongpo 6 months ago
parent
commit
b519241157

+ 9 - 2
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java

@@ -292,7 +292,12 @@ public class PermissionServiceImpl implements PermissionService {
         Long userDeptId = userDept.get();
         // 设置为用户对应员工的部门
         EmployeeRespDTO employee = employeeApi.getEmployeeByUserId(userId);
-        userDeptId = employee.getDeptId();
+        if (employee != null) {
+            Long employeeDeptId = employee.getDeptId();
+            if (employeeDeptId != null) {
+                userDeptId = employeeDeptId;
+            }
+        }
         // 遍历每个角色,计算
         for (RoleDO role : roles) {
             // 为空时,跳过
@@ -319,7 +324,9 @@ public class PermissionServiceImpl implements PermissionService {
             }
             // 情况四,DEPT_DEPT_AND_CHILD
             if (Objects.equals(role.getDataScope(), DataScopeEnum.DEPT_AND_CHILD.getScope())) {
-                CollUtil.addAll(result.getDeptIds(), deptService.getChildDeptIdListFromCache(userDeptId));
+                if (userDeptId != null) {
+                    CollUtil.addAll(result.getDeptIds(), deptService.getChildDeptIdListFromCache(userDeptId));
+                }
                 // 添加本身部门编号
                 CollUtil.addAll(result.getDeptIds(), userDeptId);
                 continue;