From 4c20bf7137da851c1e6b7e583e000f25dcbdd603 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?=
<15040126243@163.com>
Date: Tue, 4 Jan 2022 20:53:33 +0800
Subject: [PATCH] =?UTF-8?q?add=20=E9=9B=86=E6=88=90=20dubbo=20=E5=AE=9E?=
=?UTF-8?q?=E7=8E=B0=E9=AB=98=E6=80=A7=E8=83=BD=20rpc=20=E8=BF=9C=E7=A8=8B?=
=?UTF-8?q?=E8=B0=83=E7=94=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
update 回滚到 dubbo2.7.8
add 增加 dubbo 日志打印过滤器
update 优化代码 dubbo 用法
---
config/application.yml | 24 ++
pom.xml | 7 +
.../ruoyi/system/api/RemoteFileService.java | 14 +-
.../ruoyi/system/api/RemoteLogService.java | 18 +-
.../ruoyi/system/api/RemoteUserService.java | 16 +-
.../factory/RemoteFileFallbackFactory.java | 30 ---
.../api/factory/RemoteLogFallbackFactory.java | 36 ---
.../factory/RemoteUserFallbackFactory.java | 35 ---
.../main/resources/META-INF/spring.factories | 5 +-
ruoyi-auth/pom.xml | 5 +
.../com/ruoyi/auth/RuoYiAuthApplication.java | 4 +-
.../ruoyi/auth/service/SysLoginService.java | 28 +-
ruoyi-common/pom.xml | 1 +
ruoyi-common/ruoyi-common-core/pom.xml | 252 +++++++++---------
ruoyi-common/ruoyi-common-dubbo/pom.xml | 40 +++
.../dubbo/filter/DubboRequestFilter.java | 34 +++
.../dubbo/org.apache.dubbo.rpc.Filter | 1 +
.../main/resources/META-INF/spring.factories | 1 +
ruoyi-common/ruoyi-common-log/pom.xml | 5 +
.../common/log/service/AsyncLogService.java | 7 +-
ruoyi-common/ruoyi-common-security/pom.xml | 6 +
.../annotation/EnableCustomConfig.java | 4 -
.../annotation/EnableRyFeignClients.java | 27 --
.../feign/DubboAutoConfiguration.java | 14 +
.../security/feign/DubboRequestFilter.java | 49 ++++
.../feign/FeignAutoConfiguration.java | 18 --
.../feign/FeignRequestInterceptor.java | 44 ---
ruoyi-gateway/pom.xml | 4 +
.../gateway/RuoYiGatewayApplication.java | 2 +
.../handler/SentinelFallbackHandler.java | 1 +
ruoyi-modules/ruoyi-file/pom.xml | 5 +
.../com/ruoyi/file/RuoYiFileApplication.java | 2 +
.../file/dubbo/RemoteFileServiceImpl.java | 44 +++
.../com/ruoyi/gen/RuoYiGenApplication.java | 4 +-
ruoyi-modules/ruoyi-system/pom.xml | 5 +
.../ruoyi/system/RuoYiSystemApplication.java | 4 +-
.../controller/SysProfileController.java | 12 +-
.../system/dubbo/RemoteLogServiceImpl.java | 35 +++
.../system/dubbo/RemoteUserServiceImpl.java | 61 +++++
39 files changed, 509 insertions(+), 395 deletions(-)
delete mode 100644 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java
delete mode 100644 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java
delete mode 100644 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java
create mode 100644 ruoyi-common/ruoyi-common-dubbo/pom.xml
create mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/com/ruoyi/common/dubbo/filter/DubboRequestFilter.java
create mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
create mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring.factories
delete mode 100644 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableRyFeignClients.java
create mode 100644 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboAutoConfiguration.java
create mode 100644 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboRequestFilter.java
delete mode 100644 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignAutoConfiguration.java
delete mode 100644 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignRequestInterceptor.java
create mode 100644 ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java
create mode 100644 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteLogServiceImpl.java
create mode 100644 ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteUserServiceImpl.java
diff --git a/config/application.yml b/config/application.yml
index ee42cfe0..df49a451 100644
--- a/config/application.yml
+++ b/config/application.yml
@@ -14,6 +14,26 @@ server:
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
worker: 256
+dubbo:
+ application:
+ logger: slf4j
+ protocol:
+ # 使用dubbo协议通信
+ name: dubbo
+ # dubbo 协议端口(-1表示自增端口,从20880开始)
+ port: -1
+ # 挂载到 Spring Cloud 注册中心
+ registry:
+ address: nacos://${spring.cloud.nacos.server-addr}
+ group: DUBBO_GROUP
+ consumer:
+ check: false
+ scan:
+ base-packages: com.ruoyi
+ cloud:
+ # 规避警告 无其他作用 后续升级3.X删除
+ subscribed-services: ${dubbo.application.name}
+
spring:
main:
allow-bean-definition-overriding: true
@@ -135,6 +155,10 @@ management:
# 日志配置
logging:
+ level:
+ org.springframework: warn
+ org.apache.dubbo: warn
+ com.alibaba.nacos: warn
config: classpath:logback.xml
# redisson 缓存配置
diff --git a/pom.xml b/pom.xml
index 91e47f72..92d59892 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,6 +41,7 @@
5.7.16
3.16.7
2.2.1
+ 3.0.4
@@ -280,6 +281,12 @@
${ruoyi.version}
+
+ com.ruoyi
+ ruoyi-common-dubbo
+ ${ruoyi.version}
+
+
com.ruoyi
diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java
index f5ecce10..69ff5efc 100644
--- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java
+++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java
@@ -1,28 +1,20 @@
package com.ruoyi.system.api;
-import com.ruoyi.common.core.constant.ServiceNameConstants;
-import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysFile;
-import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
-import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
/**
* 文件服务
*
- * @author ruoyi
+ * @author Lion Li
*/
-@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService {
+
/**
* 上传文件
*
* @param file 文件信息
* @return 结果
*/
- @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
- R upload(@RequestPart(value = "file") MultipartFile file);
+ SysFile upload(MultipartFile file);
}
diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteLogService.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteLogService.java
index 0a9b22a4..a11acbbd 100644
--- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteLogService.java
+++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteLogService.java
@@ -1,23 +1,15 @@
package com.ruoyi.system.api;
-import com.ruoyi.common.core.constant.SecurityConstants;
-import com.ruoyi.common.core.constant.ServiceNameConstants;
-import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysOperLog;
-import com.ruoyi.system.api.factory.RemoteLogFallbackFactory;
-import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestHeader;
/**
* 日志服务
*
- * @author ruoyi
+ * @author Lion Li
*/
-@FeignClient(contextId = "remoteLogService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteLogFallbackFactory.class)
public interface RemoteLogService {
+
/**
* 保存系统日志
*
@@ -25,8 +17,7 @@ public interface RemoteLogService {
* @param source 请求来源
* @return 结果
*/
- @PostMapping("/operlog")
- R saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+ Boolean saveLog(SysOperLog sysOperLog, String source);
/**
* 保存访问记录
@@ -35,6 +26,5 @@ public interface RemoteLogService {
* @param source 请求来源
* @return 结果
*/
- @PostMapping("/logininfor")
- R saveLogininfor(@RequestBody SysLogininfor sysLogininfor, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+ Boolean saveLogininfor(SysLogininfor sysLogininfor, String source);
}
diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java
index 5342a2e4..5d0fe8af 100644
--- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java
+++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteUserService.java
@@ -1,21 +1,15 @@
package com.ruoyi.system.api;
-import com.ruoyi.common.core.constant.SecurityConstants;
-import com.ruoyi.common.core.constant.ServiceNameConstants;
-import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysUser;
-import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
import com.ruoyi.system.api.model.LoginUser;
-import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.*;
/**
* 用户服务
*
- * @author ruoyi
+ * @author Lion Li
*/
-@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService {
+
/**
* 通过用户名查询用户信息
*
@@ -23,8 +17,7 @@ public interface RemoteUserService {
* @param source 请求来源
* @return 结果
*/
- @GetMapping("/user/info/{username}")
- R getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+ LoginUser getUserInfo(String username, String source);
/**
* 注册用户信息
@@ -33,6 +26,5 @@ public interface RemoteUserService {
* @param source 请求来源
* @return 结果
*/
- @PostMapping("/user/register")
- R registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+ Boolean registerUserInfo(SysUser sysUser, String source);
}
diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java
deleted file mode 100644
index dd968482..00000000
--- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.ruoyi.system.api.factory;
-
-import com.ruoyi.common.core.domain.R;
-import com.ruoyi.system.api.RemoteFileService;
-import com.ruoyi.system.api.domain.SysFile;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cloud.openfeign.FallbackFactory;
-import org.springframework.stereotype.Component;
-import org.springframework.web.multipart.MultipartFile;
-
-/**
- * 文件服务降级处理
- *
- * @author ruoyi
- */
-@Slf4j
-@Component
-public class RemoteFileFallbackFactory implements FallbackFactory {
-
- @Override
- public RemoteFileService create(Throwable throwable) {
- log.error("文件服务调用失败:{}", throwable.getMessage());
- return new RemoteFileService() {
- @Override
- public R upload(MultipartFile file) {
- return R.fail("上传文件失败:" + throwable.getMessage());
- }
- };
- }
-}
diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java
deleted file mode 100644
index 80db0249..00000000
--- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.ruoyi.system.api.factory;
-
-import com.ruoyi.common.core.domain.R;
-import com.ruoyi.system.api.RemoteLogService;
-import com.ruoyi.system.api.domain.SysLogininfor;
-import com.ruoyi.system.api.domain.SysOperLog;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cloud.openfeign.FallbackFactory;
-import org.springframework.stereotype.Component;
-
-/**
- * 日志服务降级处理
- *
- * @author ruoyi
- */
-@Slf4j
-@Component
-public class RemoteLogFallbackFactory implements FallbackFactory {
-
- @Override
- public RemoteLogService create(Throwable throwable) {
- log.error("日志服务调用失败:{}", throwable.getMessage());
- return new RemoteLogService() {
- @Override
- public R saveLog(SysOperLog sysOperLog, String source) {
- return null;
- }
-
- @Override
- public R saveLogininfor(SysLogininfor sysLogininfor, String source) {
- return null;
- }
- };
-
- }
-}
diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java
deleted file mode 100644
index 883f33b0..00000000
--- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.ruoyi.system.api.factory;
-
-import com.ruoyi.common.core.domain.R;
-import com.ruoyi.system.api.RemoteUserService;
-import com.ruoyi.system.api.domain.SysUser;
-import com.ruoyi.system.api.model.LoginUser;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cloud.openfeign.FallbackFactory;
-import org.springframework.stereotype.Component;
-
-/**
- * 用户服务降级处理
- *
- * @author ruoyi
- */
-@Slf4j
-@Component
-public class RemoteUserFallbackFactory implements FallbackFactory {
-
- @Override
- public RemoteUserService create(Throwable throwable) {
- log.error("用户服务调用失败:{}", throwable.getMessage());
- return new RemoteUserService() {
- @Override
- public R getUserInfo(String username, String source) {
- return R.fail("获取用户失败:" + throwable.getMessage());
- }
-
- @Override
- public R registerUserInfo(SysUser sysUser, String source) {
- return R.fail("注册用户失败:" + throwable.getMessage());
- }
- };
- }
-}
diff --git a/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories b/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories
index 19bdae5d..61102dd3 100644
--- a/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories
+++ b/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories
@@ -1,4 +1 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
- com.ruoyi.system.api.factory.RemoteUserFallbackFactory,\
- com.ruoyi.system.api.factory.RemoteLogFallbackFactory, \
- com.ruoyi.system.api.factory.RemoteFileFallbackFactory
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=
diff --git a/ruoyi-auth/pom.xml b/ruoyi-auth/pom.xml
index 521f9b29..d77e2171 100644
--- a/ruoyi-auth/pom.xml
+++ b/ruoyi-auth/pom.xml
@@ -50,6 +50,11 @@
com.ruoyi
ruoyi-common-web
+
+
+ com.ruoyi
+ ruoyi-common-dubbo
+
diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/RuoYiAuthApplication.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/RuoYiAuthApplication.java
index 11b66406..46f77acf 100644
--- a/ruoyi-auth/src/main/java/com/ruoyi/auth/RuoYiAuthApplication.java
+++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/RuoYiAuthApplication.java
@@ -1,6 +1,6 @@
package com.ruoyi.auth;
-import com.ruoyi.common.security.annotation.EnableRyFeignClients;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
*
* @author ruoyi
*/
-@EnableRyFeignClients
+@EnableDubbo
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class RuoYiAuthApplication {
public static void main(String[] args) {
diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
index 969cc550..f2253cfb 100644
--- a/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
+++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/service/SysLoginService.java
@@ -3,7 +3,6 @@ package com.ruoyi.auth.service;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.UserConstants;
-import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.UserStatus;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.ServletUtils;
@@ -15,9 +14,7 @@ import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
-import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
+import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
/**
@@ -25,12 +22,13 @@ import org.springframework.stereotype.Service;
*
* @author ruoyi
*/
-@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Service
public class SysLoginService {
- private final RemoteLogService remoteLogService;
- private final RemoteUserService remoteUserService;
+ @DubboReference
+ private RemoteLogService remoteLogService;
+ @DubboReference
+ private RemoteUserService remoteUserService;
/**
* 登录
@@ -54,18 +52,13 @@ public class SysLoginService {
throw new ServiceException("用户名不在指定范围");
}
// 查询用户信息
- R userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
+ LoginUser userInfo = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
- if (R.FAIL == userResult.getCode()) {
- throw new ServiceException(userResult.getMsg());
- }
-
- if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
+ if (StringUtils.isNull(userInfo)) {
recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
throw new ServiceException("登录用户:" + username + " 不存在");
}
- LoginUser userInfo = userResult.getData();
- SysUser user = userResult.getData().getSysUser();
+ SysUser user = userInfo.getSysUser();
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
@@ -108,11 +101,8 @@ public class SysLoginService {
sysUser.setUserName(username);
sysUser.setNickName(username);
sysUser.setPassword(SecurityUtils.encryptPassword(password));
- R> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
+ remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
- if (R.FAIL == registerResult.getCode()) {
- throw new ServiceException(registerResult.getMsg());
- }
recordLogininfor(username, Constants.REGISTER, "注册成功");
}
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index 4dcbb5c4..bf15aa38 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -17,6 +17,7 @@
ruoyi-common-datascope
ruoyi-common-datasource
ruoyi-common-web
+ ruoyi-common-dubbo
ruoyi-common
diff --git a/ruoyi-common/ruoyi-common-core/pom.xml b/ruoyi-common/ruoyi-common-core/pom.xml
index 924236f3..402e4636 100644
--- a/ruoyi-common/ruoyi-common-core/pom.xml
+++ b/ruoyi-common/ruoyi-common-core/pom.xml
@@ -1,126 +1,126 @@
-
-
-
- com.ruoyi
- ruoyi-common
- 0.1.0
-
- 4.0.0
-
- ruoyi-common-core
-
-
- ruoyi-common-core核心模块
-
-
-
-
-
-
- org.springframework.cloud
- spring-cloud-starter-openfeign
-
-
-
-
- org.springframework.cloud
- spring-cloud-starter-loadbalancer
-
-
-
-
- org.springframework
- spring-context-support
-
-
-
-
- org.springframework
- spring-web
-
-
-
-
- com.alibaba
- transmittable-thread-local
-
-
-
-
- com.github.pagehelper
- pagehelper-spring-boot-starter
-
-
-
-
- org.springframework.boot
- spring-boot-starter-validation
-
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
-
-
- com.fasterxml.jackson.datatype
- jackson-datatype-jsr310
-
-
-
-
- javax.xml.bind
- jaxb-api
-
-
-
-
- org.apache.commons
- commons-lang3
-
-
-
-
- commons-io
- commons-io
-
-
-
-
- commons-fileupload
- commons-fileupload
-
-
-
-
- org.apache.poi
- poi-ooxml
-
-
-
-
- javax.servlet
- javax.servlet-api
-
-
-
-
- io.swagger
- swagger-annotations
-
-
-
- org.projectlombok
- lombok
-
-
-
- cn.hutool
- hutool-all
-
-
-
-
-
+
+
+
+ com.ruoyi
+ ruoyi-common
+ 0.1.0
+
+ 4.0.0
+
+ ruoyi-common-core
+
+
+ ruoyi-common-core核心模块
+
+
+
+
+
+
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+
+
+ org.springframework
+ spring-context-support
+
+
+
+
+ org.springframework
+ spring-web
+
+
+
+
+ com.alibaba
+ transmittable-thread-local
+
+
+
+
+ com.github.pagehelper
+ pagehelper-spring-boot-starter
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-jsr310
+
+
+
+
+ javax.xml.bind
+ jaxb-api
+
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+
+ commons-io
+ commons-io
+
+
+
+
+ commons-fileupload
+ commons-fileupload
+
+
+
+
+ org.apache.poi
+ poi-ooxml
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+
+
+
+
+ io.swagger
+ swagger-annotations
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ cn.hutool
+ hutool-all
+
+
+
+
+
diff --git a/ruoyi-common/ruoyi-common-dubbo/pom.xml b/ruoyi-common/ruoyi-common-dubbo/pom.xml
new file mode 100644
index 00000000..feaa3df3
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-dubbo/pom.xml
@@ -0,0 +1,40 @@
+
+
+
+ com.ruoyi
+ ruoyi-common
+ 0.1.0
+
+ 4.0.0
+
+ ruoyi-common-dubbo
+
+
+ ruoyi-common-dubbo
+
+
+
+
+ com.ruoyi
+ ruoyi-common-core
+ provided
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-dubbo
+
+
+
+ com.alibaba.csp
+ sentinel-apache-dubbo-adapter
+
+
+
+ org.projectlombok
+ lombok
+
+
+
diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/com/ruoyi/common/dubbo/filter/DubboRequestFilter.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/com/ruoyi/common/dubbo/filter/DubboRequestFilter.java
new file mode 100644
index 00000000..85c00b7b
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-dubbo/src/main/java/com/ruoyi/common/dubbo/filter/DubboRequestFilter.java
@@ -0,0 +1,34 @@
+package com.ruoyi.common.dubbo.filter;
+
+import com.ruoyi.common.core.utils.JsonUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.rpc.*;
+import org.apache.dubbo.rpc.service.GenericService;
+
+@Slf4j
+@Activate(group = { CommonConstants.PROVIDER, CommonConstants.CONSUMER })
+public class DubboRequestFilter implements Filter {
+
+ @Override
+ public Result invoke(Invoker> invoker, Invocation invocation) throws RpcException {
+ //打印入参日志
+ log.info("DUBBO - 服务入参: InterfaceName=[{}],MethodName=[{}],Parameter=[{}]", invocation.getInvoker().getInterface().getName(), invocation.getMethodName(), invocation.getArguments());
+ //开始时间
+ long startTime = System.currentTimeMillis();
+ //执行接口调用逻辑
+ Result result = invoker.invoke(invocation);
+ //调用耗时
+ long elapsed = System.currentTimeMillis() - startTime;
+ //如果发生异常 则打印异常日志
+ if (result.hasException() && invoker.getInterface().equals(GenericService.class)) {
+ log.error("DUBBO - 执行异常: ", result.getException());
+ } else {
+ //打印响应日志
+ log.info("DUBBO - 服务响应: InterfaceName=[{}],MethodName=[{}],SpendTime=[{}ms],Response=[{}]", invocation.getInvoker().getInterface().getName(), invocation.getMethodName(), elapsed, JsonUtils.toJsonString(new Object[]{result.getValue()}));
+ }
+ return result;
+ }
+
+}
diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
new file mode 100644
index 00000000..ba392c95
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.Filter
@@ -0,0 +1 @@
+dubboRequestFilter=com.ruoyi.common.dubbo.filter.DubboRequestFilter
\ No newline at end of file
diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring.factories b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring.factories
new file mode 100644
index 00000000..485802b1
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-dubbo/src/main/resources/META-INF/spring.factories
@@ -0,0 +1 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=
\ No newline at end of file
diff --git a/ruoyi-common/ruoyi-common-log/pom.xml b/ruoyi-common/ruoyi-common-log/pom.xml
index 9983cc50..7f976d03 100644
--- a/ruoyi-common/ruoyi-common-log/pom.xml
+++ b/ruoyi-common/ruoyi-common-log/pom.xml
@@ -22,6 +22,11 @@
com.ruoyi
ruoyi-common-security
+
+
+ com.ruoyi
+ ruoyi-common-dubbo
+
\ No newline at end of file
diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java
index 3050d10b..771eb2f4 100644
--- a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java
+++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/service/AsyncLogService.java
@@ -3,8 +3,7 @@ package com.ruoyi.common.log.service;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.system.api.RemoteLogService;
import com.ruoyi.system.api.domain.SysOperLog;
-import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@@ -13,11 +12,11 @@ import org.springframework.stereotype.Service;
*
* @author ruoyi
*/
-@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Service
public class AsyncLogService {
- private final RemoteLogService remoteLogService;
+ @DubboReference
+ private RemoteLogService remoteLogService;
/**
* 保存系统日志记录
diff --git a/ruoyi-common/ruoyi-common-security/pom.xml b/ruoyi-common/ruoyi-common-security/pom.xml
index ab21ec45..006e8369 100644
--- a/ruoyi-common/ruoyi-common-security/pom.xml
+++ b/ruoyi-common/ruoyi-common-security/pom.xml
@@ -34,6 +34,12 @@
ruoyi-common-redis
+
+ com.ruoyi
+ ruoyi-common-dubbo
+ provided
+
+
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java
index e8a702e5..e58089ee 100644
--- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java
+++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableCustomConfig.java
@@ -1,9 +1,7 @@
package com.ruoyi.common.security.annotation;
-import com.ruoyi.common.security.feign.FeignAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
-import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import java.lang.annotation.*;
@@ -18,8 +16,6 @@ import java.lang.annotation.*;
@MapperScan("com.ruoyi.**.mapper")
// 开启线程异步执行
@EnableAsync
-// 自动加载类
-@Import({FeignAutoConfiguration.class})
public @interface EnableCustomConfig {
}
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableRyFeignClients.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableRyFeignClients.java
deleted file mode 100644
index f7580d0e..00000000
--- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/annotation/EnableRyFeignClients.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.ruoyi.common.security.annotation;
-
-import org.springframework.cloud.openfeign.EnableFeignClients;
-
-import java.lang.annotation.*;
-
-/**
- * 自定义feign注解
- * 添加basePackages路径
- *
- * @author ruoyi
- */
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@EnableFeignClients
-public @interface EnableRyFeignClients {
- String[] value() default {};
-
- String[] basePackages() default {"com.ruoyi"};
-
- Class>[] basePackageClasses() default {};
-
- Class>[] defaultConfiguration() default {};
-
- Class>[] clients() default {};
-}
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboAutoConfiguration.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboAutoConfiguration.java
new file mode 100644
index 00000000..8acc23f7
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboAutoConfiguration.java
@@ -0,0 +1,14 @@
+package com.ruoyi.common.security.feign;
+
+/**
+ * Feign 配置注册
+ *
+ * @author ruoyi
+ **/
+//@Configuration
+//public class DubboAutoConfiguration {
+// @Bean
+// public Filter requestInterceptor() {
+// return new DubboRequestFilter();
+// }
+//}
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboRequestFilter.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboRequestFilter.java
new file mode 100644
index 00000000..56fdfdd1
--- /dev/null
+++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/DubboRequestFilter.java
@@ -0,0 +1,49 @@
+//package com.ruoyi.common.security.feign;
+//
+//import com.ruoyi.common.core.constant.SecurityConstants;
+//import com.ruoyi.common.core.utils.ServletUtils;
+//import com.ruoyi.common.core.utils.StringUtils;
+//import com.ruoyi.common.core.utils.ip.IpUtils;
+//import org.apache.dubbo.common.constants.CommonConstants;
+//import org.apache.dubbo.common.extension.Activate;
+//import org.apache.dubbo.rpc.*;
+//import org.springframework.stereotype.Component;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import java.util.Map;
+//
+///**
+// * feign 请求拦截器
+// *
+// * @author ruoyi
+// */
+//@Activate(group = {CommonConstants.CONSUMER}, order = -10000)
+//@Component
+//public class DubboRequestFilter implements Filter {
+// @Override
+// public Result invoke(Invoker> invoker, Invocation invocation) throws RpcException {
+// //执行接口调用逻辑
+// Result result = invoker.invoke(invocation);
+// HttpServletRequest httpServletRequest = ServletUtils.getRequest();
+// if (httpServletRequest != null) {
+// Map headers = ServletUtils.getHeaders(httpServletRequest);
+// // 传递用户信息请求头,防止丢失
+// String userId = headers.get(SecurityConstants.DETAILS_USER_ID);
+// if (StringUtils.isNotEmpty(userId)) {
+// RpcContext.getServerContext().setAttachment(SecurityConstants.DETAILS_USER_ID, userId);
+// }
+// String userName = headers.get(SecurityConstants.DETAILS_USERNAME);
+// if (StringUtils.isNotEmpty(userName)) {
+// RpcContext.getServerContext().setAttachment(SecurityConstants.DETAILS_USERNAME, userName);
+// }
+// String authentication = headers.get(SecurityConstants.AUTHORIZATION_HEADER);
+// if (StringUtils.isNotEmpty(authentication)) {
+// RpcContext.getServerContext().setAttachment(SecurityConstants.AUTHORIZATION_HEADER, authentication);
+// }
+//
+// // 配置客户端IP
+// RpcContext.getServerContext().setAttachment("X-Forwarded-For", IpUtils.getIpAddr(ServletUtils.getRequest()));
+// }
+// return result;
+// }
+//}
\ No newline at end of file
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignAutoConfiguration.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignAutoConfiguration.java
deleted file mode 100644
index a81918c8..00000000
--- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignAutoConfiguration.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.ruoyi.common.security.feign;
-
-import feign.RequestInterceptor;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Feign 配置注册
- *
- * @author ruoyi
- **/
-@Configuration
-public class FeignAutoConfiguration {
- @Bean
- public RequestInterceptor requestInterceptor() {
- return new FeignRequestInterceptor();
- }
-}
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignRequestInterceptor.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignRequestInterceptor.java
deleted file mode 100644
index 87e76f35..00000000
--- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/feign/FeignRequestInterceptor.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.ruoyi.common.security.feign;
-
-import com.ruoyi.common.core.constant.SecurityConstants;
-import com.ruoyi.common.core.utils.ServletUtils;
-import com.ruoyi.common.core.utils.StringUtils;
-import com.ruoyi.common.core.utils.ip.IpUtils;
-import feign.RequestInterceptor;
-import feign.RequestTemplate;
-import org.springframework.stereotype.Component;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.Map;
-
-/**
- * feign 请求拦截器
- *
- * @author ruoyi
- */
-@Component
-public class FeignRequestInterceptor implements RequestInterceptor {
- @Override
- public void apply(RequestTemplate requestTemplate) {
- HttpServletRequest httpServletRequest = ServletUtils.getRequest();
- if (StringUtils.isNotNull(httpServletRequest)) {
- Map headers = ServletUtils.getHeaders(httpServletRequest);
- // 传递用户信息请求头,防止丢失
- String userId = headers.get(SecurityConstants.DETAILS_USER_ID);
- if (StringUtils.isNotEmpty(userId)) {
- requestTemplate.header(SecurityConstants.DETAILS_USER_ID, userId);
- }
- String userName = headers.get(SecurityConstants.DETAILS_USERNAME);
- if (StringUtils.isNotEmpty(userName)) {
- requestTemplate.header(SecurityConstants.DETAILS_USERNAME, userName);
- }
- String authentication = headers.get(SecurityConstants.AUTHORIZATION_HEADER);
- if (StringUtils.isNotEmpty(authentication)) {
- requestTemplate.header(SecurityConstants.AUTHORIZATION_HEADER, authentication);
- }
-
- // 配置客户端IP
- requestTemplate.header("X-Forwarded-For", IpUtils.getIpAddr(ServletUtils.getRequest()));
- }
- }
-}
\ No newline at end of file
diff --git a/ruoyi-gateway/pom.xml b/ruoyi-gateway/pom.xml
index 9bc260fa..2113b3d4 100644
--- a/ruoyi-gateway/pom.xml
+++ b/ruoyi-gateway/pom.xml
@@ -63,6 +63,10 @@
com.ruoyi
ruoyi-common-redis
+
+ com.ruoyi
+ ruoyi-common-dubbo
+
diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java
index 86cf9246..056cea86 100644
--- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java
+++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java
@@ -1,5 +1,6 @@
package com.ruoyi.gateway;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -9,6 +10,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
*
* @author ruoyi
*/
+@EnableDubbo
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class RuoYiGatewayApplication {
public static void main(String[] args) {
diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java
index acf5ca9e..8b5595f4 100644
--- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java
+++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java
@@ -20,6 +20,7 @@ public class SentinelFallbackHandler implements WebExceptionHandler {
@Override
public Mono handle(ServerWebExchange exchange, Throwable ex) {
+ ex.printStackTrace();
if (exchange.getResponse().isCommitted()) {
return Mono.error(ex);
}
diff --git a/ruoyi-modules/ruoyi-file/pom.xml b/ruoyi-modules/ruoyi-file/pom.xml
index e6d9b097..50a75648 100644
--- a/ruoyi-modules/ruoyi-file/pom.xml
+++ b/ruoyi-modules/ruoyi-file/pom.xml
@@ -66,6 +66,11 @@
ruoyi-common-swagger
+
+ com.ruoyi
+ ruoyi-common-dubbo
+
+
com.ruoyi
ruoyi-common-web
diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java
index 509d5617..ae199a2d 100644
--- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java
+++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/RuoYiFileApplication.java
@@ -1,6 +1,7 @@
package com.ruoyi.file;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
*
* @author ruoyi
*/
+@EnableDubbo
@EnableCustomSwagger2
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class RuoYiFileApplication {
diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java
new file mode 100644
index 00000000..a5748202
--- /dev/null
+++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/dubbo/RemoteFileServiceImpl.java
@@ -0,0 +1,44 @@
+package com.ruoyi.file.dubbo;
+
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.core.utils.file.FileUtils;
+import com.ruoyi.file.service.ISysFileService;
+import com.ruoyi.system.api.RemoteFileService;
+import com.ruoyi.system.api.domain.SysFile;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 文件请求处理
+ *
+ * @author ruoyi
+ */
+@Slf4j
+@Service
+@DubboService
+public class RemoteFileServiceImpl implements RemoteFileService {
+
+ @Autowired
+ private ISysFileService sysFileService;
+
+ /**
+ * 文件上传请求
+ */
+ @Override
+ public SysFile upload(MultipartFile file) {
+ try {
+ // 上传并返回访问地址
+ String url = sysFileService.uploadFile(file);
+ SysFile sysFile = new SysFile();
+ sysFile.setName(FileUtils.getName(url));
+ sysFile.setUrl(url);
+ return sysFile;
+ } catch (Exception e) {
+ log.error("上传文件失败", e);
+ throw new ServiceException("上传文件失败");
+ }
+ }
+}
\ No newline at end of file
diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java
index c31ff769..0ec6385f 100644
--- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java
+++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java
@@ -1,8 +1,8 @@
package com.ruoyi.gen;
import com.ruoyi.common.security.annotation.EnableCustomConfig;
-import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -13,7 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/
@EnableCustomConfig
@EnableCustomSwagger2
-@EnableRyFeignClients
+@EnableDubbo
@SpringBootApplication
public class RuoYiGenApplication {
public static void main(String[] args) {
diff --git a/ruoyi-modules/ruoyi-system/pom.xml b/ruoyi-modules/ruoyi-system/pom.xml
index 7dd2d7b9..cb283d29 100644
--- a/ruoyi-modules/ruoyi-system/pom.xml
+++ b/ruoyi-modules/ruoyi-system/pom.xml
@@ -83,6 +83,11 @@
ruoyi-common-web
+
+ com.ruoyi
+ ruoyi-common-dubbo
+
+
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java
index 568226e3..fb828545 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java
@@ -1,8 +1,8 @@
package com.ruoyi.system;
import com.ruoyi.common.security.annotation.EnableCustomConfig;
-import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -13,7 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*/
@EnableCustomConfig
@EnableCustomSwagger2
-@EnableRyFeignClients
+@EnableDubbo
@SpringBootApplication
public class RuoYiSystemApplication {
public static void main(String[] args) {
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java
index b74b597d..5e021bbb 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysProfileController.java
@@ -1,7 +1,6 @@
package com.ruoyi.system.controller;
import com.ruoyi.common.core.constant.UserConstants;
-import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -15,6 +14,7 @@ import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
+import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -33,7 +33,9 @@ public class SysProfileController extends BaseController {
private final ISysUserService userService;
private final TokenService tokenService;
- private final RemoteFileService remoteFileService;
+
+ @DubboReference
+ private RemoteFileService remoteFileService;
/**
* 个人信息
@@ -111,11 +113,11 @@ public class SysProfileController extends BaseController {
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
if (!file.isEmpty()) {
LoginUser loginUser = SecurityUtils.getLoginUser();
- R fileResult = remoteFileService.upload(file);
- if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData())) {
+ SysFile sysFile = remoteFileService.upload(file);
+ if (StringUtils.isNull(sysFile)) {
return AjaxResult.error("文件服务异常,请联系管理员");
}
- String url = fileResult.getData().getUrl();
+ String url = sysFile.getUrl();
if (userService.updateUserAvatar(loginUser.getUsername(), url)) {
AjaxResult ajax = AjaxResult.success();
ajax.put("imgUrl", url);
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteLogServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteLogServiceImpl.java
new file mode 100644
index 00000000..3fe49833
--- /dev/null
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteLogServiceImpl.java
@@ -0,0 +1,35 @@
+package com.ruoyi.system.dubbo;
+
+import com.ruoyi.system.api.RemoteLogService;
+import com.ruoyi.system.api.domain.SysLogininfor;
+import com.ruoyi.system.api.domain.SysOperLog;
+import com.ruoyi.system.service.ISysLogininforService;
+import com.ruoyi.system.service.ISysOperLogService;
+import lombok.RequiredArgsConstructor;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * 操作日志记录
+ *
+ * @author Lion Li
+ */
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@Service
+@DubboService
+public class RemoteLogServiceImpl implements RemoteLogService {
+
+ private final ISysOperLogService operLogService;
+ private final ISysLogininforService logininforService;
+
+ @Override
+ public Boolean saveLog(SysOperLog sysOperLog, String source){
+ return operLogService.insertOperlog(sysOperLog) > 0;
+ }
+
+ @Override
+ public Boolean saveLogininfor(SysLogininfor sysLogininfor, String source){
+ return logininforService.insertLogininfor(sysLogininfor) > 0;
+ }
+}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteUserServiceImpl.java
new file mode 100644
index 00000000..ac1beba1
--- /dev/null
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/dubbo/RemoteUserServiceImpl.java
@@ -0,0 +1,61 @@
+package com.ruoyi.system.dubbo;
+
+import com.ruoyi.common.core.constant.UserConstants;
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.system.api.RemoteUserService;
+import com.ruoyi.system.api.domain.SysUser;
+import com.ruoyi.system.api.model.LoginUser;
+import com.ruoyi.system.service.ISysConfigService;
+import com.ruoyi.system.service.ISysPermissionService;
+import com.ruoyi.system.service.ISysUserService;
+import lombok.RequiredArgsConstructor;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Set;
+
+/**
+ * 操作日志记录
+ *
+ * @author Lion Li
+ */
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@Service
+@DubboService
+public class RemoteUserServiceImpl implements RemoteUserService {
+
+ private final ISysUserService userService;
+ private final ISysPermissionService permissionService;
+ private final ISysConfigService configService;
+
+ @Override
+ public LoginUser getUserInfo(String username, String source) {
+ SysUser sysUser = userService.selectUserByUserName(username);
+ if (StringUtils.isNull(sysUser)) {
+ throw new ServiceException("用户名或密码错误");
+ }
+ // 角色集合
+ Set roles = permissionService.getRolePermission(sysUser.getUserId());
+ // 权限集合
+ Set permissions = permissionService.getMenuPermission(sysUser.getUserId());
+ LoginUser sysUserVo = new LoginUser();
+ sysUserVo.setSysUser(sysUser);
+ sysUserVo.setRoles(roles);
+ sysUserVo.setPermissions(permissions);
+ return sysUserVo;
+ }
+
+ @Override
+ public Boolean registerUserInfo(SysUser sysUser, String source) {
+ String username = sysUser.getUserName();
+ if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
+ throw new ServiceException("当前系统没有开启注册功能");
+ }
+ if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) {
+ throw new ServiceException("保存用户'" + username + "'失败,注册账号已存在");
+ }
+ return userService.registerUser(sysUser);
+ }
+}