From 1c0909d970736d3bc00a2e06afb6eef5d244d330 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 5 May 2025 11:33:39 +0800 Subject: [PATCH] =?UTF-8?q?reactor=EF=BC=9A@TenantIgnore=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20enable=20=E5=B1=9E=E6=80=A7=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=98=AF=E5=90=A6=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/framework/tenant/core/aop/TenantIgnore.java | 8 ++++++++ .../framework/tenant/core/aop/TenantIgnoreAspect.java | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnore.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnore.java index a0b477421f..7ed9ade7fe 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnore.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnore.java @@ -21,4 +21,12 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Inherited public @interface TenantIgnore { + + /** + * 是否开启忽略租户,默认为 true 开启 + * + * 支持 Spring EL 表达式,如果返回 true 则满足条件,进行租户的忽略 + */ + String enable() default "true"; + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnoreAspect.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnoreAspect.java index b7d0fa3624..91514d50cd 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnoreAspect.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnoreAspect.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.tenant.core.aop; +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import lombok.extern.slf4j.Slf4j; @@ -24,7 +25,12 @@ public class TenantIgnoreAspect { public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable { Boolean oldIgnore = TenantContextHolder.isIgnore(); try { - TenantContextHolder.setIgnore(true); + // 计算条件,满足的情况下,才进行忽略 + Object enable = SpringExpressionUtils.parseExpression(tenantIgnore.enable()); + if (Boolean.TRUE.equals(enable)) { + TenantContextHolder.setIgnore(true); + } + // 执行逻辑 return joinPoint.proceed(); } finally {