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,4 +21,12 @@ import java.lang.annotation.*; | ||
| 21 | @Retention(RetentionPolicy.RUNTIME) | 21 | @Retention(RetentionPolicy.RUNTIME) |
| 22 | @Inherited | 22 | @Inherited |
| 23 | public @interface TenantIgnore { | 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 | package cn.iocoder.yudao.framework.tenant.core.aop; | 1 | package cn.iocoder.yudao.framework.tenant.core.aop; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; | ||
| 3 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; | 4 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 4 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | 5 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 5 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
| @@ -24,7 +25,12 @@ public class TenantIgnoreAspect { | @@ -24,7 +25,12 @@ public class TenantIgnoreAspect { | ||
| 24 | public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable { | 25 | public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable { |
| 25 | Boolean oldIgnore = TenantContextHolder.isIgnore(); | 26 | Boolean oldIgnore = TenantContextHolder.isIgnore(); |
| 26 | try { | 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 | return joinPoint.proceed(); | 35 | return joinPoint.proceed(); |
| 30 | } finally { | 36 | } finally { |