reactor:@TenantIgnore 增加 enable 属性,用于是否开启

This commit is contained in:
YunaiV 2025-05-05 11:33:39 +08:00
parent 70cbb82c84
commit 1c0909d970
2 changed files with 15 additions and 1 deletions

View File

@ -21,4 +21,12 @@ import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited @Inherited
public @interface TenantIgnore { public @interface TenantIgnore {
/**
* 是否开启忽略租户默认为 true 开启
*
* 支持 Spring EL 表达式如果返回 true 则满足条件进行租户的忽略
*/
String enable() default "true";
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.framework.tenant.core.aop; 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.context.TenantContextHolder;
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -24,7 +25,12 @@ public class TenantIgnoreAspect {
public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable { public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable {
Boolean oldIgnore = TenantContextHolder.isIgnore(); Boolean oldIgnore = TenantContextHolder.isIgnore();
try { try {
TenantContextHolder.setIgnore(true); // 计算条件满足的情况下才进行忽略
Object enable = SpringExpressionUtils.parseExpression(tenantIgnore.enable());
if (Boolean.TRUE.equals(enable)) {
TenantContextHolder.setIgnore(true);
}
// 执行逻辑 // 执行逻辑
return joinPoint.proceed(); return joinPoint.proceed();
} finally { } finally {