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()); }