|
@@ -70,9 +70,15 @@ public class DataScopeAspect
|
|
|
{
|
|
|
SysUser currentUser = loginUser.getUser();
|
|
|
System.out.println("currentUser isTenantAdmin: " + currentUser.isTenantAdmin());
|
|
|
- // 如果是超级管理员,则不过滤数据
|
|
|
- if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
|
|
+ if (StringUtils.isNotNull(currentUser) && currentUser.isAdmin())
|
|
|
{
|
|
|
+ // 如果是超级管理员,则不过滤数据
|
|
|
+ } else if (StringUtils.isNotNull(currentUser) && currentUser.isTenantAdmin()) {
|
|
|
+ // 如果是租户管理员,根据租户ID过滤数据
|
|
|
+ tenantAdminDataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
|
|
+ controllerDataScope.userAlias());
|
|
|
+ } else {
|
|
|
+ // 根据数据权限过滤数据
|
|
|
String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
|
|
|
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
|
|
|
controllerDataScope.userAlias(), permission);
|
|
@@ -80,6 +86,28 @@ public class DataScopeAspect
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void tenantAdminDataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) {
|
|
|
+ StringBuilder sqlString = new StringBuilder();
|
|
|
+ Object params = joinPoint.getArgs()[0];
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(userAlias)) // 根据用户表的租户ID过滤
|
|
|
+ {
|
|
|
+ sqlString.append(StringUtils.format(" OR {}.tenant_id = {} ", userAlias, user.getTenantId()));
|
|
|
+ }
|
|
|
+ else // 根据部门表的租户ID过滤
|
|
|
+ {
|
|
|
+ sqlString.append(StringUtils.format(" OR {}.tenant_id = {} ", deptAlias, user.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
|
|
|
+ {
|
|
|
+ BaseEntity baseEntity = (BaseEntity) params;
|
|
|
+ baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 数据范围过滤
|
|
|
*
|
|
@@ -149,11 +177,6 @@ public class DataScopeAspect
|
|
|
sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
|
|
|
}
|
|
|
|
|
|
- // 租户管理员情况下,根据租户ID过滤数据
|
|
|
- if (user.isTenantAdmin()) {
|
|
|
- sqlString.append(StringUtils.format(" OR {}.tenant_id = {} ", deptAlias, user.getTenantId()));
|
|
|
- }
|
|
|
-
|
|
|
if (StringUtils.isNotBlank(sqlString.toString()))
|
|
|
{
|
|
|
Object params = joinPoint.getArgs()[0];
|