Commit 1c0909d970736d3bc00a2e06afb6eef5d244d330
1 parent
70cbb82c
reactor:@TenantIgnore 增加 enable 属性,用于是否开启
Showing
2 changed files
with
15 additions
and
1 deletions
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.*; |
| 21 | 21 | @Retention(RetentionPolicy.RUNTIME) |
| 22 | 22 | @Inherited |
| 23 | 23 | public @interface TenantIgnore { |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 是否开启忽略租户,默认为 true 开启 | |
| 27 | + * | |
| 28 | + * 支持 Spring EL 表达式,如果返回 true 则满足条件,进行租户的忽略 | |
| 29 | + */ | |
| 30 | + String enable() default "true"; | |
| 31 | + | |
| 24 | 32 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/aop/TenantIgnoreAspect.java
| 1 | 1 | package cn.iocoder.yudao.framework.tenant.core.aop; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; | |
| 3 | 4 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 4 | 5 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 5 | 6 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -24,7 +25,12 @@ public class TenantIgnoreAspect { |
| 24 | 25 | public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable { |
| 25 | 26 | Boolean oldIgnore = TenantContextHolder.isIgnore(); |
| 26 | 27 | try { |
| 27 | - TenantContextHolder.setIgnore(true); | |
| 28 | + // 计算条件,满足的情况下,才进行忽略 | |
| 29 | + Object enable = SpringExpressionUtils.parseExpression(tenantIgnore.enable()); | |
| 30 | + if (Boolean.TRUE.equals(enable)) { | |
| 31 | + TenantContextHolder.setIgnore(true); | |
| 32 | + } | |
| 33 | + | |
| 28 | 34 | // 执行逻辑 |
| 29 | 35 | return joinPoint.proceed(); |
| 30 | 36 | } finally { | ... | ... |