perf(core): 优化数据权限处理逻辑

- 合并判断条件,简化代码结构
- 提高超级管理员和未登录用户的处理效率
This commit is contained in:
胡少翔
2024-12-05 11:37:21 +08:00
parent 13cd408a97
commit 8055e86f32

View File

@@ -33,16 +33,10 @@ public class MyDataPermissionHandler implements DataPermissionHandler {
@Override
@SneakyThrows
public Expression getSqlSegment(Expression where, String mappedStatementId) {
// 如果是超级管理员,直接返回
if(SecurityUtils.isRoot()){
// 如果是未登录或者是定时任务执行的SQL或者是超级管理员,直接返回
if(SecurityUtils.getUserId() == null || SecurityUtils.isRoot()){
return where;
}
// 如果是未登录或者是定时任务执行的SQL直接返回
Long userId = SecurityUtils.getUserId();
if(userId == null){
return where;
}
// 获取当前用户的数据权限
Integer dataScope = SecurityUtils.getDataScope();
DataScopeEnum dataScopeEnum = IBaseEnum.getEnumByValue(dataScope, DataScopeEnum.class);