fix 修复 数据权限对union语句不兼容问题

This commit is contained in:
疯狂的狮子Li 2026-08-24 11:48:56 +08:00
parent 2933badb91
commit 629e344af5
2 changed files with 12 additions and 5 deletions

View File

@ -26,14 +26,19 @@ public class DataPermissionAdvice implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {
Object target = invocation.getThis(); Object target = invocation.getThis();
Method method = invocation.getMethod(); Method method = invocation.getMethod();
DataPermission previousPermission = DataPermissionHelper.getPermission();
// 设置权限注解 // 设置权限注解
DataPermissionHelper.setPermission(getDataPermissionAnnotation(target, method)); DataPermissionHelper.setPermission(getDataPermissionAnnotation(target, method));
try { try {
// 执行代理方法 // 执行代理方法
return invocation.proceed(); return invocation.proceed();
} finally { } finally {
// 清除权限注解 // 恢复上一层权限上下文兼容嵌套 Mapper 调用
DataPermissionHelper.removePermission(); if (previousPermission == null) {
DataPermissionHelper.removePermission();
} else {
DataPermissionHelper.setPermission(previousPermission);
}
} }
} }

View File

@ -71,13 +71,17 @@ public class PlusDataPermissionHandler {
*/ */
public Expression getSqlSegment(Expression where, boolean isSelect) { public Expression getSqlSegment(Expression where, boolean isSelect) {
try { try {
DataPermission dataPermission = getDataPermission();
if (dataPermission == null) {
throw new ServiceException("数据权限上下文缺失,请检查 @DataPermission 注解处理生命周期");
}
LoginUser currentUser = currentUser(); LoginUser currentUser = currentUser();
// 如果是超级管理员或租户管理员则不过滤数据 // 如果是超级管理员或租户管理员则不过滤数据
if (LoginHelper.isSuperAdmin()) { if (LoginHelper.isSuperAdmin()) {
return where; return where;
} }
// 构造数据过滤条件的 SQL 片段 // 构造数据过滤条件的 SQL 片段
String dataFilterSql = buildDataFilter(getDataPermission(), currentUser, isSelect); String dataFilterSql = buildDataFilter(dataPermission, currentUser, isSelect);
if (StringUtils.isBlank(dataFilterSql)) { if (StringUtils.isBlank(dataFilterSql)) {
return where; return where;
} }
@ -91,8 +95,6 @@ public class PlusDataPermissionHandler {
} }
} catch (JSQLParserException e) { } catch (JSQLParserException e) {
throw new ServiceException("数据权限解析异常 => " + e.getMessage()); throw new ServiceException("数据权限解析异常 => " + e.getMessage());
} finally {
DataPermissionHelper.removePermission();
} }
} }