数据权限健壮性处理
This commit is contained in:
1 parent
8d659cff85
commit
e5c3a8f5d2
3 files changed
+19
-7
No files matched your search
+2
-2
@@ -30,8 +30,8 @@ public interface DataScopeHandle {
|
||||
/**
|
||||
* 计算用户数据权限
|
||||
*
|
||||
* @param deptList
|
||||
* @return
|
||||
* @param deptList 部门ID,如果为空表示没有任何数据权限。
|
||||
* @return 返回true表示无需进行数据过滤处理,返回false表示需要进行数据过滤
|
||||
*/
|
||||
Boolean calcScope(List<Integer> deptList);
|
||||
}
|
||||
+7
-2
@@ -78,8 +78,13 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements In
|
||||
if (CollUtil.isEmpty(deptIds) && dataScopeHandle.calcScope(deptIds)) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
String join = CollectionUtil.join(deptIds, ",");
|
||||
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
|
||||
|
||||
if(deptIds.isEmpty()){
|
||||
originalSql = "select * from (" + originalSql + ") temp_data_scope where 1 = 2";
|
||||
}else{
|
||||
String join = CollectionUtil.join(deptIds, ",");
|
||||
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
|
||||
}
|
||||
metaObject.setValue("delegate.boundSql.sql", originalSql);
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
+10
-3
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.data.datascope;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDeptRelation;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
@@ -57,10 +58,16 @@ public class PigxDefaultDatascopeHandle implements DataScopeHandle {
|
||||
.filter(authority -> authority.startsWith(SecurityConstants.ROLE))
|
||||
.map(authority -> authority.split(StrUtil.UNDERLINE)[1])
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 当前用户的角色为空
|
||||
if(CollectionUtil.isEmpty(roleIdList)){
|
||||
return false;
|
||||
}
|
||||
SysRole role = dataScopeService.getRoleList(roleIdList).getData().stream()
|
||||
.min(Comparator.comparingInt(SysRole::getDsType)).get();
|
||||
|
||||
.min(Comparator.comparingInt(SysRole::getDsType)).orElse(null);
|
||||
// 角色有可能已经删除了
|
||||
if(role == null){
|
||||
return false;
|
||||
}
|
||||
Integer dsType = role.getDsType();
|
||||
// 查询全部
|
||||
if (DataScopeTypeEnum.ALL.getType() == dsType) {
|
||||
|
||||
Reference in new issue
Block a user