|
@@ -88,7 +88,7 @@ public class DataScopeAspect
|
|
|
public static void dataScopeFilter(JoinPoint joinPoint, SysUserVO user, String deptAlias, String userAlias)
|
|
|
{
|
|
|
StringBuilder sqlString = new StringBuilder();
|
|
|
-
|
|
|
+ StringBuilder sqlLambda = new StringBuilder();
|
|
|
for (SysRoleVO role : user.getRoles())
|
|
|
{
|
|
|
String dataScope = role.getDataScope();
|
|
@@ -96,33 +96,32 @@ public class DataScopeAspect
|
|
|
{
|
|
|
Integer tenantId = SecurityUtils.getTenantId();
|
|
|
sqlString.append(StringUtils.format(" OR {}.tenant_id = {} ", deptAlias, tenantId));
|
|
|
+ sqlLambda.append(StringUtils.format(" OR tenant_id = {} ", tenantId));
|
|
|
}
|
|
|
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
|
|
{
|
|
|
- sqlString.append(StringUtils.format(
|
|
|
- " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
|
|
|
- role.getRoleId()));
|
|
|
+ sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
|
|
|
+ sqlLambda.append(StringUtils.format(" OR dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
|
|
|
}
|
|
|
else if (DATA_SCOPE_DEPT.equals(dataScope))
|
|
|
{
|
|
|
sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
|
|
|
+ sqlLambda.append(StringUtils.format(" OR dept_id = {} ", user.getDeptId()));
|
|
|
}
|
|
|
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
|
|
|
{
|
|
|
- sqlString.append(StringUtils.format(
|
|
|
- " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
|
|
|
- deptAlias, user.getDeptId(), user.getDeptId()));
|
|
|
+ sqlString.append(StringUtils.format( " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", deptAlias, user.getDeptId(), user.getDeptId()));
|
|
|
+ sqlLambda.append(StringUtils.format( " OR dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", user.getDeptId(), user.getDeptId()));
|
|
|
}
|
|
|
else if (DATA_SCOPE_SELF.equals(dataScope))
|
|
|
{
|
|
|
- if (StringUtils.isNotBlank(userAlias))
|
|
|
- {
|
|
|
+ if (StringUtils.isNotBlank(userAlias)) {
|
|
|
sqlString.append(StringUtils.format(" OR {}.create_by = {} ", userAlias, user.getUserName()));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ sqlLambda.append(StringUtils.format(" OR create_by = {} ", user.getUserName()));
|
|
|
+ } else {
|
|
|
// 数据权限为仅本人且没有userAlias别名不查询任何数据
|
|
|
sqlString.append(" OR 1=0 ");
|
|
|
+ sqlLambda.append(StringUtils.format(" OR create_by = '{}' ", user.getUserName()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -135,8 +134,12 @@ public class DataScopeAspect
|
|
|
BaseEntity baseEntity = (BaseEntity) params;
|
|
|
baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
|
|
|
}
|
|
|
- DataScopeContextHolder.setDataScopeSql(" AND (" + sqlString.substring(4) + ")");
|
|
|
}
|
|
|
+ if(StringUtils.isNotBlank(sqlLambda.toString())){
|
|
|
+ DataScopeContextHolder.setDataScopeSql(" (" + sqlLambda.substring(4) + ")");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|