|
@@ -92,16 +92,22 @@ public class DataScopeAspect |
|
@@ -92,16 +92,22 @@ public class DataScopeAspect |
|
92
|
{
|
92
|
{
|
|
93
|
StringBuilder sqlString = new StringBuilder();
|
93
|
StringBuilder sqlString = new StringBuilder();
|
|
94
|
List<String> conditions = new ArrayList<String>();
|
94
|
List<String> conditions = new ArrayList<String>();
|
|
|
|
95
|
+ List<String> scopeCustomIds = new ArrayList<String>();
|
|
|
|
96
|
+ user.getRoles().forEach(role -> {
|
|
|
|
97
|
+ if (DATA_SCOPE_CUSTOM.equals(role.getDataScope()) && StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
|
|
|
|
98
|
+ {
|
|
|
|
99
|
+ scopeCustomIds.add(Convert.toStr(role.getRoleId()));
|
|
|
|
100
|
+ }
|
|
|
|
101
|
+ });
|
|
95
|
|
102
|
|
|
96
|
for (SysRole role : user.getRoles())
|
103
|
for (SysRole role : user.getRoles())
|
|
97
|
{
|
104
|
{
|
|
98
|
String dataScope = role.getDataScope();
|
105
|
String dataScope = role.getDataScope();
|
|
99
|
- if (!DATA_SCOPE_CUSTOM.equals(dataScope) && conditions.contains(dataScope))
|
106
|
+ if (conditions.contains(dataScope))
|
|
100
|
{
|
107
|
{
|
|
101
|
continue;
|
108
|
continue;
|
|
102
|
}
|
109
|
}
|
|
103
|
- if (StringUtils.isNotEmpty(permission) && StringUtils.isNotEmpty(role.getPermissions())
|
|
|
|
104
|
- && !StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
|
110
|
+ if (!StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission)))
|
|
105
|
{
|
111
|
{
|
|
106
|
continue;
|
112
|
continue;
|
|
107
|
}
|
113
|
}
|
|
@@ -113,9 +119,15 @@ public class DataScopeAspect |
|
@@ -113,9 +119,15 @@ public class DataScopeAspect |
|
113
|
}
|
119
|
}
|
|
114
|
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
120
|
else if (DATA_SCOPE_CUSTOM.equals(dataScope))
|
|
115
|
{
|
121
|
{
|
|
116
|
- sqlString.append(StringUtils.format(
|
|
|
|
117
|
- " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
|
|
|
|
118
|
- role.getRoleId()));
|
122
|
+ if (scopeCustomIds.size() > 1)
|
|
|
|
123
|
+ {
|
|
|
|
124
|
+ // 多个自定数据权限使用in查询,避免多次拼接。
|
|
|
|
125
|
+ sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id in ({}) ) ", deptAlias, String.join(",", scopeCustomIds)));
|
|
|
|
126
|
+ }
|
|
|
|
127
|
+ else
|
|
|
|
128
|
+ {
|
|
|
|
129
|
+ sqlString.append(StringUtils.format(" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, role.getRoleId()));
|
|
|
|
130
|
+ }
|
|
119
|
}
|
131
|
}
|
|
120
|
else if (DATA_SCOPE_DEPT.equals(dataScope))
|
132
|
else if (DATA_SCOPE_DEPT.equals(dataScope))
|
|
121
|
{
|
133
|
{
|
|
@@ -123,9 +135,7 @@ public class DataScopeAspect |
|
@@ -123,9 +135,7 @@ public class DataScopeAspect |
|
123
|
}
|
135
|
}
|
|
124
|
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
|
136
|
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
|
|
125
|
{
|
137
|
{
|
|
126
|
- sqlString.append(StringUtils.format(
|
|
|
|
127
|
- " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
|
|
|
|
128
|
- deptAlias, user.getDeptId(), user.getDeptId()));
|
138
|
+ 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()));
|
|
129
|
}
|
139
|
}
|
|
130
|
else if (DATA_SCOPE_SELF.equals(dataScope))
|
140
|
else if (DATA_SCOPE_SELF.equals(dataScope))
|
|
131
|
{
|
141
|
{
|