From bc6c88d89d5f7333868ec6d79b1a970222ddefa3 Mon Sep 17 00:00:00 2001
From: Loki <654612@qq.com>
Date: Tue, 12 Jul 2022 10:25:44 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=87=BA=E5=85=A5=E6=8B=A6?=
=?UTF-8?q?=E6=88=AA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../dubbo/com.alibaba.dubbo.rpc.Filter | 2 ++
zsw-farm/zsw-farm-api/pom.xml | 27 ++++++++++++++++++
.../src/main/java/dubbo/config/Infilter.java | 28 +++++++++++++++++++
.../src/main/java/dubbo/config/OutFilter.java | 16 +++++++++++
zsw-farm/zsw-farm-impl/pom.xml | 25 +----------------
5 files changed, 74 insertions(+), 24 deletions(-)
create mode 100644 yudao-server/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter
create mode 100644 zsw-farm/zsw-farm-api/src/main/java/dubbo/config/Infilter.java
create mode 100644 zsw-farm/zsw-farm-api/src/main/java/dubbo/config/OutFilter.java
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
-
+