From 4686861ad2bed9e854b2facf5375bfe17472ee6b Mon Sep 17 00:00:00 2001 From: Loki <654612@qq.com> Date: Wed, 24 Aug 2022 11:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=86=E5=A4=87=E6=96=B0=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=88=87=E9=9D=A2=20=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=B8=80=E4=BA=9B=E6=AF=94=E5=A6=82=E4=B8=83?= =?UTF-8?q?=E7=89=9B=EF=BC=8C=E9=BB=98=E8=AE=A4=E8=BD=AE=E6=92=AD=EF=BC=8C?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E8=AE=BE=E7=BD=AE=E7=AD=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/yixiang/aspect/TenantInitAspect.java | 29 +++++++++++++++++++ .../src/main/java/dubbo/config/OutFilter.java | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 zsw-bxg/src/main/java/co/yixiang/aspect/TenantInitAspect.java diff --git a/zsw-bxg/src/main/java/co/yixiang/aspect/TenantInitAspect.java b/zsw-bxg/src/main/java/co/yixiang/aspect/TenantInitAspect.java new file mode 100644 index 00000000..7e8bd52a --- /dev/null +++ b/zsw-bxg/src/main/java/co/yixiang/aspect/TenantInitAspect.java @@ -0,0 +1,29 @@ +package co.yixiang.aspect; + +import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; + +/** + * 如果有新租户需要创建 ,则需要调用这个方法执行一些操作,初始化一些数据 + * 如动态图设计。前端可以不用,后端这个功能依然保持,七牛初始化配置。 + * + */ +@Aspect +@Component +@Slf4j +public class TenantInitAspect { + + @Pointcut("execution(* cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper.insert(..))") + public void tenantInit(){} + + @AfterReturning(value = "tenantInit()",returning = "tenant") + public void afterTenantInit(JoinPoint point, TenantDO tenant){ + log.info("新租户被加入,准备初始化...{}",tenant); + } + +} diff --git a/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/OutFilter.java b/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/OutFilter.java index c39d4e59..c37d1835 100644 --- a/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/OutFilter.java +++ b/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/OutFilter.java @@ -1,6 +1,7 @@ package dubbo.config; import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.*; @@ -9,7 +10,7 @@ import org.apache.dubbo.rpc.*; public class OutFilter implements Filter { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - Long tenantId = 11L; + Long tenantId = TenantContextHolder.getTenantId(); if(ObjectUtil.isNotEmpty(tenantId)){ invocation.setAttachment("tenantId",tenantId.toString()); }