mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-06 20:38:35 +00:00
add 集成 dubbo 实现高性能 rpc 远程调用
update 回滚到 dubbo2.7.8 add 增加 dubbo 日志打印过滤器 update 优化代码 dubbo 用法
This commit is contained in:
@@ -14,6 +14,26 @@ server:
|
|||||||
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
|
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
|
||||||
worker: 256
|
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:
|
spring:
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
@@ -135,6 +155,10 @@ management:
|
|||||||
|
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
|
level:
|
||||||
|
org.springframework: warn
|
||||||
|
org.apache.dubbo: warn
|
||||||
|
com.alibaba.nacos: warn
|
||||||
config: classpath:logback.xml
|
config: classpath:logback.xml
|
||||||
|
|
||||||
# redisson 缓存配置
|
# redisson 缓存配置
|
||||||
|
7
pom.xml
7
pom.xml
@@ -41,6 +41,7 @@
|
|||||||
<hutool.version>5.7.16</hutool.version>
|
<hutool.version>5.7.16</hutool.version>
|
||||||
<redisson.version>3.16.7</redisson.version>
|
<redisson.version>3.16.7</redisson.version>
|
||||||
<lock4j.version>2.2.1</lock4j.version>
|
<lock4j.version>2.2.1</lock4j.version>
|
||||||
|
<dubbo.version>3.0.4</dubbo.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
@@ -280,6 +281,12 @@
|
|||||||
<version>${ruoyi.version}</version>
|
<version>${ruoyi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
<version>${ruoyi.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 系统接口 -->
|
<!-- 系统接口 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
|
@@ -1,28 +1,20 @@
|
|||||||
package com.ruoyi.system.api;
|
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.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;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件服务
|
* 文件服务
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
|
|
||||||
public interface RemoteFileService {
|
public interface RemoteFileService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
*
|
*
|
||||||
* @param file 文件信息
|
* @param file 文件信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
SysFile upload(MultipartFile file);
|
||||||
R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +1,15 @@
|
|||||||
package com.ruoyi.system.api;
|
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.SysLogininfor;
|
||||||
import com.ruoyi.system.api.domain.SysOperLog;
|
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 {
|
public interface RemoteLogService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存系统日志
|
* 保存系统日志
|
||||||
*
|
*
|
||||||
@@ -25,8 +17,7 @@ public interface RemoteLogService {
|
|||||||
* @param source 请求来源
|
* @param source 请求来源
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/operlog")
|
Boolean saveLog(SysOperLog sysOperLog, String source);
|
||||||
R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存访问记录
|
* 保存访问记录
|
||||||
@@ -35,6 +26,5 @@ public interface RemoteLogService {
|
|||||||
* @param source 请求来源
|
* @param source 请求来源
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/logininfor")
|
Boolean saveLogininfor(SysLogininfor sysLogininfor, String source);
|
||||||
R<Boolean> saveLogininfor(@RequestBody SysLogininfor sysLogininfor, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
|
||||||
}
|
}
|
||||||
|
@@ -1,21 +1,15 @@
|
|||||||
package com.ruoyi.system.api;
|
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.domain.SysUser;
|
||||||
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
|
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
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 {
|
public interface RemoteUserService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户信息
|
* 通过用户名查询用户信息
|
||||||
*
|
*
|
||||||
@@ -23,8 +17,7 @@ public interface RemoteUserService {
|
|||||||
* @param source 请求来源
|
* @param source 请求来源
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@GetMapping("/user/info/{username}")
|
LoginUser getUserInfo(String username, String source);
|
||||||
R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册用户信息
|
* 注册用户信息
|
||||||
@@ -33,6 +26,5 @@ public interface RemoteUserService {
|
|||||||
* @param source 请求来源
|
* @param source 请求来源
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@PostMapping("/user/register")
|
Boolean registerUserInfo(SysUser sysUser, String source);
|
||||||
R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
|
||||||
}
|
}
|
||||||
|
@@ -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<RemoteFileService> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RemoteFileService create(Throwable throwable) {
|
|
||||||
log.error("文件服务调用失败:{}", throwable.getMessage());
|
|
||||||
return new RemoteFileService() {
|
|
||||||
@Override
|
|
||||||
public R<SysFile> upload(MultipartFile file) {
|
|
||||||
return R.fail("上传文件失败:" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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<RemoteLogService> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RemoteLogService create(Throwable throwable) {
|
|
||||||
log.error("日志服务调用失败:{}", throwable.getMessage());
|
|
||||||
return new RemoteLogService() {
|
|
||||||
@Override
|
|
||||||
public R<Boolean> saveLog(SysOperLog sysOperLog, String source) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source) {
|
|
||||||
return 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<RemoteUserService> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RemoteUserService create(Throwable throwable) {
|
|
||||||
log.error("用户服务调用失败:{}", throwable.getMessage());
|
|
||||||
return new RemoteUserService() {
|
|
||||||
@Override
|
|
||||||
public R<LoginUser> getUserInfo(String username, String source) {
|
|
||||||
return R.fail("获取用户失败:" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public R<Boolean> registerUserInfo(SysUser sysUser, String source) {
|
|
||||||
return R.fail("注册用户失败:" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,4 +1 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
|
||||||
com.ruoyi.system.api.factory.RemoteUserFallbackFactory,\
|
|
||||||
com.ruoyi.system.api.factory.RemoteLogFallbackFactory, \
|
|
||||||
com.ruoyi.system.api.factory.RemoteFileFallbackFactory
|
|
||||||
|
@@ -50,6 +50,11 @@
|
|||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-web</artifactId>
|
<artifactId>ruoyi-common-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package com.ruoyi.auth;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
@@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@EnableRyFeignClients
|
@EnableDubbo
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
public class RuoYiAuthApplication {
|
public class RuoYiAuthApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@@ -3,7 +3,6 @@ package com.ruoyi.auth.service;
|
|||||||
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
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.enums.UserStatus;
|
||||||
import com.ruoyi.common.core.exception.ServiceException;
|
import com.ruoyi.common.core.exception.ServiceException;
|
||||||
import com.ruoyi.common.core.utils.ServletUtils;
|
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.SysLogininfor;
|
||||||
import com.ruoyi.system.api.domain.SysUser;
|
import com.ruoyi.system.api.domain.SysUser;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
import com.ruoyi.system.api.model.LoginUser;
|
||||||
import lombok.RequiredArgsConstructor;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,12 +22,13 @@ import org.springframework.stereotype.Service;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
|
||||||
@Service
|
@Service
|
||||||
public class SysLoginService {
|
public class SysLoginService {
|
||||||
|
|
||||||
private final RemoteLogService remoteLogService;
|
@DubboReference
|
||||||
private final RemoteUserService remoteUserService;
|
private RemoteLogService remoteLogService;
|
||||||
|
@DubboReference
|
||||||
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
@@ -54,18 +52,13 @@ public class SysLoginService {
|
|||||||
throw new ServiceException("用户名不在指定范围");
|
throw new ServiceException("用户名不在指定范围");
|
||||||
}
|
}
|
||||||
// 查询用户信息
|
// 查询用户信息
|
||||||
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
LoginUser userInfo = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||||
|
|
||||||
if (R.FAIL == userResult.getCode()) {
|
if (StringUtils.isNull(userInfo)) {
|
||||||
throw new ServiceException(userResult.getMsg());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
|
||||||
recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||||
throw new ServiceException("登录用户:" + username + " 不存在");
|
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||||
}
|
}
|
||||||
LoginUser userInfo = userResult.getData();
|
SysUser user = userInfo.getSysUser();
|
||||||
SysUser user = userResult.getData().getSysUser();
|
|
||||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
||||||
recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||||
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
||||||
@@ -108,11 +101,8 @@ public class SysLoginService {
|
|||||||
sysUser.setUserName(username);
|
sysUser.setUserName(username);
|
||||||
sysUser.setNickName(username);
|
sysUser.setNickName(username);
|
||||||
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
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, "注册成功");
|
recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
<module>ruoyi-common-datascope</module>
|
<module>ruoyi-common-datascope</module>
|
||||||
<module>ruoyi-common-datasource</module>
|
<module>ruoyi-common-datasource</module>
|
||||||
<module>ruoyi-common-web</module>
|
<module>ruoyi-common-web</module>
|
||||||
|
<module>ruoyi-common-dubbo</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
|
@@ -1,126 +1,126 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-core核心模块
|
ruoyi-common-core核心模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- SpringCloud Openfeign -->
|
<!-- <!– SpringCloud Openfeign –>-->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
<!-- <artifactId>spring-cloud-starter-openfeign</artifactId>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- SpringCloud Loadbalancer -->
|
<!-- SpringCloud Loadbalancer -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Context Support -->
|
<!-- Spring Context Support -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context-support</artifactId>
|
<artifactId>spring-context-support</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Web -->
|
<!-- Spring Web -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Transmittable ThreadLocal -->
|
<!-- Transmittable ThreadLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>transmittable-thread-local</artifactId>
|
<artifactId>transmittable-thread-local</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Pagehelper -->
|
<!-- Pagehelper -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pagehelper</groupId>
|
<groupId>com.github.pagehelper</groupId>
|
||||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Hibernate Validator -->
|
<!-- Hibernate Validator -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Jackson -->
|
<!-- Jackson -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Jaxb -->
|
<!-- Jaxb -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Apache Lang3 -->
|
<!-- Apache Lang3 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Commons Io -->
|
<!-- Commons Io -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Commons Fileupload -->
|
<!-- Commons Fileupload -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-fileupload</groupId>
|
<groupId>commons-fileupload</groupId>
|
||||||
<artifactId>commons-fileupload</artifactId>
|
<artifactId>commons-fileupload</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- excel工具 -->
|
<!-- excel工具 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi-ooxml</artifactId>
|
<artifactId>poi-ooxml</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Java Servlet -->
|
<!-- Java Servlet -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger -->
|
<!-- Swagger -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>swagger-annotations</artifactId>
|
<artifactId>swagger-annotations</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
40
ruoyi-common/ruoyi-common-dubbo/pom.xml
Normal file
40
ruoyi-common/ruoyi-common-dubbo/pom.xml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common</artifactId>
|
||||||
|
<version>0.1.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
|
||||||
|
<description>
|
||||||
|
ruoyi-common-dubbo
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
dubboRequestFilter=com.ruoyi.common.dubbo.filter.DubboRequestFilter
|
@@ -0,0 +1 @@
|
|||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
|
@@ -22,6 +22,11 @@
|
|||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-security</artifactId>
|
<artifactId>ruoyi-common-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@@ -3,8 +3,7 @@ package com.ruoyi.common.log.service;
|
|||||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
import com.ruoyi.system.api.RemoteLogService;
|
import com.ruoyi.system.api.RemoteLogService;
|
||||||
import com.ruoyi.system.api.domain.SysOperLog;
|
import com.ruoyi.system.api.domain.SysOperLog;
|
||||||
import lombok.RequiredArgsConstructor;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -13,11 +12,11 @@ import org.springframework.stereotype.Service;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
|
||||||
@Service
|
@Service
|
||||||
public class AsyncLogService {
|
public class AsyncLogService {
|
||||||
|
|
||||||
private final RemoteLogService remoteLogService;
|
@DubboReference
|
||||||
|
private RemoteLogService remoteLogService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存系统日志记录
|
* 保存系统日志记录
|
||||||
|
@@ -34,6 +34,12 @@
|
|||||||
<artifactId>ruoyi-common-redis</artifactId>
|
<artifactId>ruoyi-common-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
package com.ruoyi.common.security.annotation;
|
package com.ruoyi.common.security.annotation;
|
||||||
|
|
||||||
import com.ruoyi.common.security.feign.FeignAutoConfiguration;
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
@@ -18,8 +16,6 @@ import java.lang.annotation.*;
|
|||||||
@MapperScan("com.ruoyi.**.mapper")
|
@MapperScan("com.ruoyi.**.mapper")
|
||||||
// 开启线程异步执行
|
// 开启线程异步执行
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
// 自动加载类
|
|
||||||
@Import({FeignAutoConfiguration.class})
|
|
||||||
public @interface EnableCustomConfig {
|
public @interface EnableCustomConfig {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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 {};
|
|
||||||
}
|
|
@@ -0,0 +1,14 @@
|
|||||||
|
package com.ruoyi.common.security.feign;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Feign 配置注册
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
**/
|
||||||
|
//@Configuration
|
||||||
|
//public class DubboAutoConfiguration {
|
||||||
|
// @Bean
|
||||||
|
// public Filter requestInterceptor() {
|
||||||
|
// return new DubboRequestFilter();
|
||||||
|
// }
|
||||||
|
//}
|
@@ -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<String, String> 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;
|
||||||
|
// }
|
||||||
|
//}
|
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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<String, String> 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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -63,6 +63,10 @@
|
|||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-redis</artifactId>
|
<artifactId>ruoyi-common-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Swagger -->
|
<!-- Swagger -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.gateway;
|
package com.ruoyi.gateway;
|
||||||
|
|
||||||
|
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
@@ -9,6 +10,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@EnableDubbo
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
public class RuoYiGatewayApplication {
|
public class RuoYiGatewayApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@@ -20,6 +20,7 @@ public class SentinelFallbackHandler implements WebExceptionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
|
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
if (exchange.getResponse().isCommitted()) {
|
if (exchange.getResponse().isCommitted()) {
|
||||||
return Mono.error(ex);
|
return Mono.error(ex);
|
||||||
}
|
}
|
||||||
|
@@ -66,6 +66,11 @@
|
|||||||
<artifactId>ruoyi-common-swagger</artifactId>
|
<artifactId>ruoyi-common-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-web</artifactId>
|
<artifactId>ruoyi-common-web</artifactId>
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.file;
|
package com.ruoyi.file;
|
||||||
|
|
||||||
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
@@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@EnableDubbo
|
||||||
@EnableCustomSwagger2
|
@EnableCustomSwagger2
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
public class RuoYiFileApplication {
|
public class RuoYiFileApplication {
|
||||||
|
@@ -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("上传文件失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,8 @@
|
|||||||
package com.ruoyi.gen;
|
package com.ruoyi.gen;
|
||||||
|
|
||||||
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
||||||
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
|
||||||
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
*/
|
*/
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
@EnableCustomSwagger2
|
@EnableCustomSwagger2
|
||||||
@EnableRyFeignClients
|
@EnableDubbo
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class RuoYiGenApplication {
|
public class RuoYiGenApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@@ -83,6 +83,11 @@
|
|||||||
<artifactId>ruoyi-common-web</artifactId>
|
<artifactId>ruoyi-common-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-dubbo</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package com.ruoyi.system;
|
package com.ruoyi.system;
|
||||||
|
|
||||||
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
||||||
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
|
||||||
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
*/
|
*/
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
@EnableCustomSwagger2
|
@EnableCustomSwagger2
|
||||||
@EnableRyFeignClients
|
@EnableDubbo
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class RuoYiSystemApplication {
|
public class RuoYiSystemApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package com.ruoyi.system.controller;
|
package com.ruoyi.system.controller;
|
||||||
|
|
||||||
import com.ruoyi.common.core.constant.UserConstants;
|
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.utils.StringUtils;
|
||||||
import com.ruoyi.common.core.web.controller.BaseController;
|
import com.ruoyi.common.core.web.controller.BaseController;
|
||||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
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.api.model.LoginUser;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -33,7 +33,9 @@ public class SysProfileController extends BaseController {
|
|||||||
|
|
||||||
private final ISysUserService userService;
|
private final ISysUserService userService;
|
||||||
private final TokenService tokenService;
|
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 {
|
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
R<SysFile> fileResult = remoteFileService.upload(file);
|
SysFile sysFile = remoteFileService.upload(file);
|
||||||
if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData())) {
|
if (StringUtils.isNull(sysFile)) {
|
||||||
return AjaxResult.error("文件服务异常,请联系管理员");
|
return AjaxResult.error("文件服务异常,请联系管理员");
|
||||||
}
|
}
|
||||||
String url = fileResult.getData().getUrl();
|
String url = sysFile.getUrl();
|
||||||
if (userService.updateUserAvatar(loginUser.getUsername(), url)) {
|
if (userService.updateUserAvatar(loginUser.getUsername(), url)) {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
ajax.put("imgUrl", url);
|
ajax.put("imgUrl", url);
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -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<String> roles = permissionService.getRolePermission(sysUser.getUserId());
|
||||||
|
// 权限集合
|
||||||
|
Set<String> 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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user