Browse Source

增加出入拦截

zyh
Loki 3 years ago
parent
commit
bc6c88d89d
  1. 2
      yudao-server/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter
  2. 27
      zsw-farm/zsw-farm-api/pom.xml
  3. 28
      zsw-farm/zsw-farm-api/src/main/java/dubbo/config/Infilter.java
  4. 16
      zsw-farm/zsw-farm-api/src/main/java/dubbo/config/OutFilter.java
  5. 25
      zsw-farm/zsw-farm-impl/pom.xml

2
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

27
zsw-farm/zsw-farm-api/pom.xml

@ -43,6 +43,33 @@
<artifactId>aspectjrt</artifactId>
<version>1.9.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-spring-boot-starter -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>3.0.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.nacos/nacos-client -->
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-impl</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>zsw-spi</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>

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

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

25
zsw-farm/zsw-farm-impl/pom.xml

@ -53,32 +53,9 @@
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-excel</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-impl</artifactId>
<version>1.6.2-snapshot</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>zsw-spi</artifactId>
<version>1.6.2-snapshot</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-spring-boot-starter -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>3.0.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba.nacos/nacos-client -->
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>

Loading…
Cancel
Save