diff --git a/yudao-server/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter b/yudao-server/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter new file mode 100644 index 00000000..602c6b49 --- /dev/null +++ b/yudao-server/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter @@ -0,0 +1,2 @@ +tenantInFilter=dubbo.config.Infilter +tenantOutFilter=dubbo.config.OutFilter \ No newline at end of file diff --git a/zsw-farm/zsw-farm-api/pom.xml b/zsw-farm/zsw-farm-api/pom.xml index 48825903..4fd99b58 100644 --- a/zsw-farm/zsw-farm-api/pom.xml +++ b/zsw-farm/zsw-farm-api/pom.xml @@ -43,6 +43,33 @@ aspectjrt 1.9.5 + + + + org.apache.dubbo + dubbo-spring-boot-starter + 3.0.9 + + + + + com.alibaba.nacos + nacos-client + 2.1.0 + + + + cn.iocoder.boot + yudao-module-system-impl + ${revision} + + + + cn.iocoder.boot + zsw-spi + ${revision} + + diff --git a/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/Infilter.java b/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/Infilter.java new file mode 100644 index 00000000..fd6e2759 --- /dev/null +++ b/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/Infilter.java @@ -0,0 +1,28 @@ +package dubbo.config; + +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import cn.iocoder.yudao.framework.common.exception.ServiceException; +import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.rpc.*; + +@Slf4j +@Activate(group = CommonConstants.PROVIDER) +public class Infilter implements Filter{ + + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { + String tenantId = invocation.getAttachment("tenantId"); + if (ObjectUtil.isNotEmpty(tenantId)){ + TenantContextHolder.setTenantId(Long.valueOf(tenantId)); + }else{ + throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR); + } + + return invoker.invoke(invocation); + } +} 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 new file mode 100644 index 00000000..a8a62b3a --- /dev/null +++ b/zsw-farm/zsw-farm-api/src/main/java/dubbo/config/OutFilter.java @@ -0,0 +1,16 @@ +package dubbo.config; + +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.*; + +@Activate(group = CommonConstants.CONSUMER) +public class OutFilter implements Filter { + @Override + public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { + Long tenantId = TenantContextHolder.getTenantId(); + invocation.setAttachment("tenantId",tenantId.toString()); + return invoker.invoke(invocation); + } +} diff --git a/zsw-farm/zsw-farm-impl/pom.xml b/zsw-farm/zsw-farm-impl/pom.xml index 7014bc76..d190e6fc 100644 --- a/zsw-farm/zsw-farm-impl/pom.xml +++ b/zsw-farm/zsw-farm-impl/pom.xml @@ -53,32 +53,9 @@ cn.iocoder.boot yudao-spring-boot-starter-excel - - cn.iocoder.boot - yudao-module-system-impl - 1.6.2-snapshot - compile - - - cn.iocoder.boot - zsw-spi - 1.6.2-snapshot - compile - - - - org.apache.dubbo - dubbo-spring-boot-starter - 3.0.9 - - - - com.alibaba.nacos - nacos-client - 2.1.0 - +