From e5c3a8f5d25ae49df96fd628fe29fd7a8275f2c0 Mon Sep 17 00:00:00 2001 From: chenjun Date: Sat, 23 May 2020 23:36:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pigx/common/data/datascope/DataScopeHandle.java | 4 ++-- .../common/data/datascope/DataScopeInterceptor.java | 9 +++++++-- .../data/datascope/PigxDefaultDatascopeHandle.java | 13 ++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeHandle.java b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeHandle.java index 011607099..bdcd56dc7 100644 --- a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeHandle.java +++ b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeHandle.java @@ -30,8 +30,8 @@ public interface DataScopeHandle { /** * 计算用户数据权限 * - * @param deptList - * @return + * @param deptList 部门ID,如果为空表示没有任何数据权限。 + * @return 返回true表示无需进行数据过滤处理,返回false表示需要进行数据过滤 */ Boolean calcScope(List deptList); } diff --git a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeInterceptor.java b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeInterceptor.java index 7b0b262d6..379d11e9d 100644 --- a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeInterceptor.java +++ b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/DataScopeInterceptor.java @@ -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(); } diff --git a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/PigxDefaultDatascopeHandle.java b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/PigxDefaultDatascopeHandle.java index 2a1191256..4c942cd4a 100644 --- a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/PigxDefaultDatascopeHandle.java +++ b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/datascope/PigxDefaultDatascopeHandle.java @@ -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) {