From 8055e86f328210518437b260679e8dc918505abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=91=E7=BF=94?= <971366405@qq.com> Date: Thu, 5 Dec 2024 11:37:21 +0800 Subject: [PATCH] =?UTF-8?q?perf(core):=20=E4=BC=98=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9D=83=E9=99=90=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 合并判断条件,简化代码结构 - 提高超级管理员和未登录用户的处理效率 --- .../boot/core/handler/MyDataPermissionHandler.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/youlai/boot/core/handler/MyDataPermissionHandler.java b/src/main/java/com/youlai/boot/core/handler/MyDataPermissionHandler.java index 48486a6b..227bb9f1 100644 --- a/src/main/java/com/youlai/boot/core/handler/MyDataPermissionHandler.java +++ b/src/main/java/com/youlai/boot/core/handler/MyDataPermissionHandler.java @@ -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);