Compare commits
No commits in common. "dev" and "master" have entirely different histories.
|
@ -16,12 +16,6 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.muyu</groupId>-->
|
|
||||||
<!-- <artifactId>cloud-common-saas</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
@ -40,7 +34,6 @@
|
||||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- SpringBoot Web -->
|
<!-- SpringBoot Web -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -65,50 +58,6 @@
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos Config -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Sentinel -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Mysql Connector -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common DataSource -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-datasource</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common DataScope -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-datascope</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common Log -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-log</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package com.muyu.auth;
|
package com.muyu.auth;
|
||||||
|
|
||||||
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure;
|
|
||||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
|
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@ -13,18 +10,10 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
@EnableCustomConfig
|
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication(
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
exclude = {
|
|
||||||
DataSourceAutoConfiguration.class,
|
|
||||||
DruidDataSourceAutoConfigure.class,
|
|
||||||
DynamicDataSourceAutoConfiguration.class
|
|
||||||
}
|
|
||||||
)
|
|
||||||
public class CloudAuthApplication {
|
public class CloudAuthApplication {
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
SpringApplication.run(CloudAuthApplication.class, args);
|
SpringApplication.run(CloudAuthApplication.class, args);
|
||||||
System.out.println("CloudAuth 模块启动成功!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,7 @@ import com.muyu.common.security.auth.AuthUtil;
|
||||||
import com.muyu.common.security.service.TokenService;
|
import com.muyu.common.security.service.TokenService;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
@ -29,20 +25,16 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
public class TokenController {
|
public class TokenController {
|
||||||
|
@Autowired
|
||||||
@Resource
|
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
||||||
private SysLoginService sysLoginService;
|
private SysLoginService sysLoginService;
|
||||||
|
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public Result<?> login (@RequestBody LoginBody form) {
|
public Result<?> login (@RequestBody LoginBody form) {
|
||||||
// 用户登录
|
// 用户登录
|
||||||
|
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||||
LoginUser userInfo = sysLoginService.login(form);
|
|
||||||
|
|
||||||
// 获取登录token
|
// 获取登录token
|
||||||
return Result.success(tokenService.createToken(userInfo));
|
return Result.success(tokenService.createToken(userInfo));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,11 @@
|
||||||
package com.muyu.auth.form;
|
package com.muyu.auth.form;
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录对象
|
* 用户登录对象
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
|
||||||
public class LoginBody {
|
public class LoginBody {
|
||||||
|
|
||||||
private String firmCode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名
|
* 用户名
|
||||||
*/
|
*/
|
||||||
|
@ -26,8 +16,6 @@ public class LoginBody {
|
||||||
*/
|
*/
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getUsername () {
|
public String getUsername () {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
@ -36,5 +24,11 @@ public class LoginBody {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPassword () {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword (String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.auth.service;
|
package com.muyu.auth.service;
|
||||||
|
|
||||||
import com.muyu.auth.form.LoginBody;
|
|
||||||
import com.muyu.common.core.constant.CacheConstants;
|
import com.muyu.common.core.constant.CacheConstants;
|
||||||
import com.muyu.common.core.constant.Constants;
|
import com.muyu.common.core.constant.Constants;
|
||||||
import com.muyu.common.core.constant.SecurityConstants;
|
import com.muyu.common.core.constant.SecurityConstants;
|
||||||
|
@ -13,15 +12,12 @@ import com.muyu.common.core.utils.StringUtils;
|
||||||
import com.muyu.common.core.utils.ip.IpUtils;
|
import com.muyu.common.core.utils.ip.IpUtils;
|
||||||
import com.muyu.common.redis.service.RedisService;
|
import com.muyu.common.redis.service.RedisService;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
|
||||||
import com.muyu.common.system.domain.SysUser;
|
|
||||||
import com.muyu.common.system.remote.RemoteSaasService;
|
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
import com.muyu.common.system.remote.RemoteUserService;
|
||||||
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录校验方法
|
* 登录校验方法
|
||||||
*
|
*
|
||||||
|
@ -29,30 +25,24 @@ import javax.annotation.Resource;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SysLoginService {
|
public class SysLoginService {
|
||||||
@Resource
|
@Autowired
|
||||||
private RemoteUserService remoteUserService;
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private SysPasswordService passwordService;
|
private SysPasswordService passwordService;
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private SysRecordLogService recordLogService;
|
private SysRecordLogService recordLogService;
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RemoteSaasService remoteSaasService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
*/
|
*/
|
||||||
public LoginUser login (LoginBody form) {
|
public LoginUser login (String username, String password) {
|
||||||
String firmCode = form.getFirmCode();
|
|
||||||
String username = form.getUsername();
|
|
||||||
String password = form.getPassword();
|
|
||||||
// 用户名或密码为空 错误
|
// 用户名或密码为空 错误
|
||||||
if (StringUtils.isAnyBlank(firmCode, username, password)) {
|
if (StringUtils.isAnyBlank(username, password)) {
|
||||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
||||||
throw new ServiceException("用户/密码必须填写");
|
throw new ServiceException("用户/密码必须填写");
|
||||||
}
|
}
|
||||||
|
@ -75,7 +65,8 @@ public class SysLoginService {
|
||||||
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
||||||
}
|
}
|
||||||
// 查询用户信息
|
// 查询用户信息
|
||||||
Result<LoginUser> userResult = remoteUserService.getUserInfo(firmCode, username, SecurityConstants.INNER);
|
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||||
|
|
||||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
||||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||||
throw new ServiceException("登录用户:" + username + " 不存在");
|
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||||
|
@ -85,8 +76,8 @@ public class SysLoginService {
|
||||||
throw new ServiceException(userResult.getMsg());
|
throw new ServiceException(userResult.getMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginUser loginUser = userResult.getData();
|
LoginUser userInfo = userResult.getData();
|
||||||
SysUser user = loginUser.getSysUser();
|
SysUser user = userResult.getData().getSysUser();
|
||||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
||||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||||
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
||||||
|
@ -97,8 +88,7 @@ public class SysLoginService {
|
||||||
}
|
}
|
||||||
passwordService.validate(user, password);
|
passwordService.validate(user, password);
|
||||||
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||||
|
return userInfo;
|
||||||
return loginUser;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logout (String loginName) {
|
public void logout (String loginName) {
|
||||||
|
|
|
@ -6,11 +6,7 @@ import com.muyu.common.core.exception.ServiceException;
|
||||||
import com.muyu.common.redis.service.RedisService;
|
import com.muyu.common.redis.service.RedisService;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -22,22 +18,14 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SysPasswordService {
|
public class SysPasswordService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
private int maxRetryCount = CacheConstants.PASSWORD_MAX_RETRY_COUNT;
|
private int maxRetryCount = CacheConstants.PASSWORD_MAX_RETRY_COUNT;
|
||||||
|
|
||||||
private Long lockTime = CacheConstants.PASSWORD_LOCK_TIME;
|
private Long lockTime = CacheConstants.PASSWORD_LOCK_TIME;
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
||||||
private SysRecordLogService recordLogService;
|
private SysRecordLogService recordLogService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,11 +6,7 @@ import com.muyu.common.core.utils.StringUtils;
|
||||||
import com.muyu.common.core.utils.ip.IpUtils;
|
import com.muyu.common.core.utils.ip.IpUtils;
|
||||||
import com.muyu.common.system.remote.RemoteLogService;
|
import com.muyu.common.system.remote.RemoteLogService;
|
||||||
import com.muyu.common.system.domain.SysLogininfor;
|
import com.muyu.common.system.domain.SysLogininfor;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,11 +16,7 @@ import org.springframework.stereotype.Component;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SysRecordLogService {
|
public class SysRecordLogService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
||||||
private RemoteLogService remoteLogService;
|
private RemoteLogService remoteLogService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,10 +4,10 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.116.173.119:8848
|
addr: nacos.muyu.icu:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: oneone
|
namespace: muyu-cloud
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
@ -22,26 +22,26 @@ spring:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: ${nacos.addr}
|
server-addr: ${nacos.addr}
|
||||||
# nacos用户名
|
# nacos用户名
|
||||||
# username: ${nacos.user-name}
|
username: ${nacos.user-name}
|
||||||
# # nacos密码
|
# nacos密码
|
||||||
# password: ${nacos.password}
|
password: ${nacos.password}
|
||||||
# 命名空间
|
# 命名空间
|
||||||
namespace: ${nacos.namespace}
|
namespace: ${nacos.namespace}
|
||||||
config:
|
config:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: ${nacos.addr}
|
server-addr: ${nacos.addr}
|
||||||
# nacos用户名
|
# nacos用户名
|
||||||
# username: ${nacos.user-name}
|
username: ${nacos.user-name}
|
||||||
# # nacos密码
|
# nacos密码
|
||||||
# password: ${nacos.password}
|
password: ${nacos.password}
|
||||||
# 命名空间
|
# 命名空间
|
||||||
namespace: ${nacos.namespace}
|
namespace: ${nacos.namespace}
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
# 系统环境Config共享配置
|
|
||||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
||||||
# 系统共享配置
|
# 系统共享配置
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# 系统环境Config共享配置
|
||||||
|
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>cloud-common-cache</artifactId>
|
|
||||||
<description>
|
|
||||||
cloud-common-cache 缓存基准
|
|
||||||
</description>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<!-- 基础缓存模块 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.muyu.common.cache;
|
|
||||||
|
|
||||||
import com.muyu.common.cache.decoration.DecorationKey;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 原子序列缓存基准
|
|
||||||
* @Date 2024-4-1 下午 08:07
|
|
||||||
*/
|
|
||||||
public interface AtomicSequenceCache<K> extends DecorationKey<K> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取存储的值
|
|
||||||
* @param key 键
|
|
||||||
* @return 值
|
|
||||||
*/
|
|
||||||
public Long get(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自增
|
|
||||||
*/
|
|
||||||
public Long increment(K key);
|
|
||||||
/**
|
|
||||||
* 自减
|
|
||||||
*/
|
|
||||||
public Long decrement(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 增加数值
|
|
||||||
*/
|
|
||||||
public Long increment(K key, Long number);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 减少数值
|
|
||||||
*/
|
|
||||||
public Long decrement(K key, Long number);
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package com.muyu.common.cache;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据转换接口
|
|
||||||
* @param <K> 数据键
|
|
||||||
* @param <V> 数据值
|
|
||||||
*/
|
|
||||||
public interface BasicCacheData <K,V>{
|
|
||||||
|
|
||||||
public V apply(K key);
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package com.muyu.common.cache;
|
|
||||||
|
|
||||||
import com.muyu.common.cache.decoration.DecorationKey;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 缓存接口基类
|
|
||||||
* @Date 2024-3-26 下午 03:25
|
|
||||||
*/
|
|
||||||
public interface Cache <K, V> extends DecorationKey<K> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过Key获取value值
|
|
||||||
* @param key 键
|
|
||||||
* @return 值
|
|
||||||
*/
|
|
||||||
public V get(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存添加/修改
|
|
||||||
* @param key 键
|
|
||||||
* @param value 值
|
|
||||||
*/
|
|
||||||
public void put(K key, V value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过键删除
|
|
||||||
* @param key 键
|
|
||||||
*/
|
|
||||||
public void remove(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新缓存时间
|
|
||||||
* @param key 键
|
|
||||||
*/
|
|
||||||
public void refreshTime (K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新缓存数据
|
|
||||||
* @param key 键
|
|
||||||
*/
|
|
||||||
public void refreshData (K key);
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
package com.muyu.common.cache;
|
|
||||||
|
|
||||||
import com.muyu.common.cache.decoration.DecorationKey;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: Hash缓存基准
|
|
||||||
* @Date 2024-3-29 下午 03:16
|
|
||||||
*/
|
|
||||||
public interface HashCache <K, HK, HV> extends DecorationKey<K> {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码
|
|
||||||
* @param hashKey ID
|
|
||||||
* @return 键
|
|
||||||
*/
|
|
||||||
public String encodeHashKey(HK hashKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解码
|
|
||||||
* @param redisHashKey 数据库键
|
|
||||||
* @return ID
|
|
||||||
*/
|
|
||||||
public HK decodeHashKey(String redisHashKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过Key获取所有的map
|
|
||||||
* @param key 数据库键
|
|
||||||
* @return 所有集合Map
|
|
||||||
*/
|
|
||||||
public Map<HK, HV> get(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过键和hashKey获取数据库hashValue
|
|
||||||
* @param key 键
|
|
||||||
* @param hashKey hash键
|
|
||||||
* @return hash值
|
|
||||||
*/
|
|
||||||
public HV get(K key, HK hashKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过键和hashKey获取数据库hashValue
|
|
||||||
* @param key 键
|
|
||||||
* @param hashKeyList hash键集合
|
|
||||||
* @return hash值
|
|
||||||
*/
|
|
||||||
public List<HV> get(K key, HK... hashKeyList);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取hash值集合
|
|
||||||
* @param key 键
|
|
||||||
* @return hash值集合
|
|
||||||
*/
|
|
||||||
public List<HV> getToList(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储数据
|
|
||||||
* @param key redis键
|
|
||||||
* @param map hashMap集合
|
|
||||||
*/
|
|
||||||
public void put(K key, Map<HK, HV> map);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储数据
|
|
||||||
* @param key redis键
|
|
||||||
* @param dataList 数据值
|
|
||||||
* @param hashKey hash键
|
|
||||||
*/
|
|
||||||
public void put(K key, List<HV> dataList, Function<HV, HK> hashKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储数据
|
|
||||||
* @param key redis键
|
|
||||||
* @param hashKey hash键
|
|
||||||
* @param hashValue hash值
|
|
||||||
*/
|
|
||||||
public void put(K key, HK hashKey, HV hashValue);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过redis键删除
|
|
||||||
* @param key hash键
|
|
||||||
*/
|
|
||||||
public void remove(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过redis键和hash键删除
|
|
||||||
* @param key redis键
|
|
||||||
* @param hashKey hash键
|
|
||||||
*/
|
|
||||||
public void remove(K key, HK hashKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断redis中hashKey是否存在
|
|
||||||
* @param key redis键
|
|
||||||
* @param hashKey hash键
|
|
||||||
*/
|
|
||||||
public boolean hasKey(K key, HK hashKey);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
package com.muyu.common.cache.abs;
|
|
||||||
|
|
||||||
import com.muyu.common.cache.AtomicSequenceCache;
|
|
||||||
import com.muyu.common.redis.service.RedisService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 原子序列缓存抽象类
|
|
||||||
* @Date 2024-4-1 下午 08:33
|
|
||||||
*/
|
|
||||||
public abstract class AtomicSequenceCacheAbs<K> implements AtomicSequenceCache<K> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取存储的值
|
|
||||||
* @param key 键
|
|
||||||
* @return 值
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long get (K key) {
|
|
||||||
Long cacheValue = this.redisService.getCacheObject(encode(key));
|
|
||||||
if (cacheValue == null){
|
|
||||||
Long data = getData(key);
|
|
||||||
cacheValue = data == null ? 0L : data;
|
|
||||||
this.redisService.setCacheObject(encode(key), cacheValue);
|
|
||||||
}
|
|
||||||
return cacheValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自增
|
|
||||||
* @param key
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long increment (K key) {
|
|
||||||
return this.increment(key, 1L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自减
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long decrement (K key) {
|
|
||||||
return this.decrement(key, 1L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 增加数值
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* @param number
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long increment (K key, Long number) {
|
|
||||||
Long numberValue = redisService.getCacheObject(encode(key));
|
|
||||||
if (numberValue == null){
|
|
||||||
Long data = getData(key);
|
|
||||||
data = data == null ? 0L : data;
|
|
||||||
redisService.setCacheObject(encode(key), data);
|
|
||||||
}
|
|
||||||
return redisService.increment(encode(key), number);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 减少数值
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* @param number
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Long decrement (K key, Long number) {
|
|
||||||
Long numberValue = redisService.getCacheObject(encode(key));
|
|
||||||
if (numberValue == null){
|
|
||||||
Long data = getData(key);
|
|
||||||
data = data == null ? 0L : data;
|
|
||||||
redisService.setCacheObject(encode(key), data);
|
|
||||||
}
|
|
||||||
return redisService.decrement(encode(key), number);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码
|
|
||||||
*
|
|
||||||
* @param key ID
|
|
||||||
*
|
|
||||||
* @return 键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String encode (K key) {
|
|
||||||
return keyPre() + key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Long getData(K key);
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
package com.muyu.common.cache.abs;
|
|
||||||
|
|
||||||
import com.muyu.common.cache.Cache;
|
|
||||||
import com.muyu.common.redis.service.RedisService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 缓存抽象类
|
|
||||||
* @Date 2024-3-27 下午 03:10
|
|
||||||
*/
|
|
||||||
public abstract class CacheAbs<K, V> implements Cache<K, V> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码
|
|
||||||
* @param key ID
|
|
||||||
* @return 键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String encode (K key) {
|
|
||||||
return keyPre() + key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过Key获取value值
|
|
||||||
* @param key 键
|
|
||||||
* @return 值
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public V get (K key) {
|
|
||||||
V value = redisService.getCacheObject(encode(key));
|
|
||||||
if (value == null){
|
|
||||||
value = getData(key);
|
|
||||||
if (value == null){
|
|
||||||
value = defaultValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.put(key, value);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存添加/修改
|
|
||||||
* @param key 键
|
|
||||||
* @param value 值
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void put (K key, V value) {
|
|
||||||
this.redisService.setCacheObject(encode(key), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过键删除
|
|
||||||
* @param key 键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void remove (K key) {
|
|
||||||
this.redisService.deleteObject(encode(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新缓存
|
|
||||||
* @param key 键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void refreshTime (K key) {
|
|
||||||
this.redisService.expire(encode(key), 60, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新缓存数据
|
|
||||||
*
|
|
||||||
* @param key 键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void refreshData (K key) {
|
|
||||||
this.put(key, getData(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从数据库获取数据
|
|
||||||
* @param key ID
|
|
||||||
* @return 缓存对象
|
|
||||||
*/
|
|
||||||
public abstract V getData(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认值
|
|
||||||
*/
|
|
||||||
public abstract V defaultValue();
|
|
||||||
}
|
|
|
@ -1,223 +0,0 @@
|
||||||
package com.muyu.common.cache.abs;
|
|
||||||
|
|
||||||
import com.muyu.common.cache.HashCache;
|
|
||||||
import com.muyu.common.redis.service.RedisService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: hash缓存抽象类
|
|
||||||
* @Date 2024-3-29 下午 07:40
|
|
||||||
*/
|
|
||||||
public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码
|
|
||||||
*
|
|
||||||
* @param key ID
|
|
||||||
*
|
|
||||||
* @return 键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String encode (K key) {
|
|
||||||
return keyPre() + key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码
|
|
||||||
* @param hashKey ID
|
|
||||||
* @return 键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String encodeHashKey (HK hashKey) {
|
|
||||||
return hashKey.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过Key获取所有的map
|
|
||||||
* @param key 数据库键
|
|
||||||
* @return 所有集合Map
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Map<HK, HV> get (K key) {
|
|
||||||
// 获取为null的情况
|
|
||||||
Map<String, HV> cacheMap = redisService.getCacheMap(encode(key));
|
|
||||||
if (cacheMap == null || cacheMap.isEmpty()){
|
|
||||||
Map<HK, HV> dataMap = getData(key);
|
|
||||||
if (dataMap != null && !dataMap.isEmpty()){
|
|
||||||
cacheMap = encodeMap(dataMap);
|
|
||||||
}else {
|
|
||||||
cacheMap = encodeMap(defaultValue());
|
|
||||||
}
|
|
||||||
redisService.setCacheMap(encode(key), cacheMap);
|
|
||||||
}
|
|
||||||
return decodeMap(cacheMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过键和hashKey获取数据库hashValue
|
|
||||||
*
|
|
||||||
* @param key 键
|
|
||||||
* @param hashKey hash键
|
|
||||||
*
|
|
||||||
* @return hash值
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public HV get (K key, HK hashKey) {
|
|
||||||
HV hashValue = redisService.getCacheMapValue(encode(key), encodeHashKey(hashKey));
|
|
||||||
if (hashValue == null){
|
|
||||||
HV dataValue = getData(key, hashKey);
|
|
||||||
hashValue = dataValue != null ? dataValue : defaultHashValue();
|
|
||||||
put(key, hashKey, hashValue);
|
|
||||||
}
|
|
||||||
return hashValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过键和hashKey获取数据库hashValue
|
|
||||||
*
|
|
||||||
* @param key 键
|
|
||||||
* @param hashKeyList hash键集合
|
|
||||||
*
|
|
||||||
* @return hash值
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<HV> get (K key, HK... hashKeyList) {
|
|
||||||
List<String> encodeHashKeyList = Arrays.stream(hashKeyList).map(this::encodeHashKey).toList();
|
|
||||||
return redisService.getMultiCacheMapValue(encode(key), encodeHashKeyList);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取hash值集合
|
|
||||||
*
|
|
||||||
* @param key 键
|
|
||||||
*
|
|
||||||
* @return hash值集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<HV> getToList (K key) {
|
|
||||||
Map<HK, HV> hkhvMap = get(key);
|
|
||||||
return hkhvMap.values().stream().toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储数据
|
|
||||||
*
|
|
||||||
* @param key redis键
|
|
||||||
* @param map hashMap集合
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void put (K key, Map<HK, HV> map) {
|
|
||||||
redisService.setCacheMap(encode(key), encodeMap(map));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储数据
|
|
||||||
*
|
|
||||||
* @param key redis键
|
|
||||||
* @param dataList 数据值
|
|
||||||
* @param hashKey hash键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void put (K key, List<HV> dataList, Function<HV, HK> hashKey) {
|
|
||||||
Map<HK, HV> dataMap = new HashMap<>();
|
|
||||||
dataList.forEach((data) -> dataMap.put(hashKey.apply(data), data));
|
|
||||||
redisService.setCacheMap(encode(key), encodeMap(dataMap));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储数据
|
|
||||||
*
|
|
||||||
* @param key redis键
|
|
||||||
* @param hashKey hash键
|
|
||||||
* @param hashValue hash值
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void put (K key, HK hashKey, HV hashValue) {
|
|
||||||
redisService.setCacheMapValue(encode(key), encodeHashKey(hashKey), hashValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过redis键删除
|
|
||||||
*
|
|
||||||
* @param key hash键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void remove (K key) {
|
|
||||||
redisService.deleteObject(encode(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过redis键和hash键删除
|
|
||||||
*
|
|
||||||
* @param key redis键
|
|
||||||
* @param hashKey hash键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void remove (K key, HK hashKey) {
|
|
||||||
redisService.deleteCacheMapValue(encode(key), encodeHashKey(hashKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断redis中hashKey是否存在
|
|
||||||
*
|
|
||||||
* @param key redis键
|
|
||||||
* @param hashKey hash键
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean hasKey (K key, HK hashKey) {
|
|
||||||
return redisService.hashKey(encode(key), encodeHashKey(hashKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 原始数据转编码数据
|
|
||||||
* @param dataMap 原始数据
|
|
||||||
* @return 编码数据
|
|
||||||
*/
|
|
||||||
private Map<String, HV> encodeMap(Map<HK, HV> dataMap){
|
|
||||||
Map<String, HV> encodeDataMap = new HashMap<>();
|
|
||||||
dataMap.forEach((hashKey, HashValue) -> encodeDataMap.put(encodeHashKey(hashKey), HashValue));
|
|
||||||
return encodeDataMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码数据转原始数据
|
|
||||||
* @param encodeDataMap 编码数据
|
|
||||||
* @return 原始数据
|
|
||||||
*/
|
|
||||||
private Map<HK, HV> decodeMap(Map<String, HV> encodeDataMap){
|
|
||||||
Map<HK, HV> dataMap = new HashMap<>();
|
|
||||||
encodeDataMap.forEach((hashKey, hashValue) -> dataMap.put(decodeHashKey(hashKey), hashValue));
|
|
||||||
return dataMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过键获取所有的hash数据
|
|
||||||
* @param key 键
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public abstract Map<HK, HV> getData(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过缓存键和hash键获取hash值
|
|
||||||
* @param key 缓存键
|
|
||||||
* @param hashKey hash键
|
|
||||||
* @return hash值
|
|
||||||
*/
|
|
||||||
public abstract HV getData(K key, HK hashKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认值
|
|
||||||
*/
|
|
||||||
public abstract Map<HK, HV> defaultValue();
|
|
||||||
public abstract HV defaultHashValue();
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.muyu.common.cache.decoration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 装饰Key
|
|
||||||
* @Date 2024-3-29 下午 03:19
|
|
||||||
*/
|
|
||||||
public interface DecorationKey <K>{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* key前缀
|
|
||||||
* @return key前缀
|
|
||||||
*/
|
|
||||||
public String keyPre();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编码
|
|
||||||
* @param key ID
|
|
||||||
* @return 键
|
|
||||||
*/
|
|
||||||
public String encode(K key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解码
|
|
||||||
* @param redisKey 数据库键
|
|
||||||
* @return ID
|
|
||||||
*/
|
|
||||||
public K decode(String redisKey);
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>cloud-common-caffeine</artifactId>
|
|
||||||
<description>
|
|
||||||
cloud-common-caffeine caffeine缓存模块
|
|
||||||
</description>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
|
||||||
<artifactId>caffeine</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,49 +0,0 @@
|
||||||
package com.muyu.common.caffeine.bean;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.caffeine.enums.CacheNameEnums;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
||||||
import org.springframework.cache.CacheManager;
|
|
||||||
import org.springframework.cache.caffeine.CaffeineCache;
|
|
||||||
import org.springframework.cache.support.SimpleCacheManager;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Caffeine管理器
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: CaffeineCacheConfig
|
|
||||||
* @Description: Caffeine管理器
|
|
||||||
* @CreatedDate: 2024/9/26 上午11:52
|
|
||||||
* @FilePath: com.muyu.common.caffeine.config
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
public class CaffeineManager {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建缓存管理器
|
|
||||||
* @return 缓存管理器实例
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public CacheManager cacheManager() {
|
|
||||||
SimpleCacheManager cacheManager = new SimpleCacheManager();
|
|
||||||
List<String> cacheNames = CacheNameEnums.getCodes();
|
|
||||||
cacheManager.setCaches(cacheNames.stream()
|
|
||||||
.map(name -> new CaffeineCache(
|
|
||||||
name,
|
|
||||||
Caffeine.newBuilder()
|
|
||||||
.recordStats()
|
|
||||||
.build()))
|
|
||||||
.toList());
|
|
||||||
log.info("缓存管理器初始化完成,缓存分区:{}", cacheNames);
|
|
||||||
return cacheManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.muyu.common.caffeine.constents;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Caffeine常量
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: CaffeineContent
|
|
||||||
* @Description: Caffeine常量
|
|
||||||
* @CreatedDate: 2024/9/26 下午12:06
|
|
||||||
* @FilePath: com.muyu.common.caffeine.constents
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class CaffeineContent {
|
|
||||||
|
|
||||||
public static final String CAR_VIN_KEY = "car:vin";
|
|
||||||
|
|
||||||
public static final String VIN = "vin";
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
package com.muyu.common.caffeine.enums;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存分区枚举
|
|
||||||
*
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: CacheNameEnums
|
|
||||||
* @Description: 缓存分区枚举
|
|
||||||
* @CreatedDate: 2024/10/2 上午9:17
|
|
||||||
* @FilePath: com.muyu.common.caffeine.enums
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public enum CacheNameEnums {
|
|
||||||
STORAGE("storage", "持久化"),
|
|
||||||
FAULT("fault", "故障"),
|
|
||||||
FENCE("fence", "围栏"),
|
|
||||||
WARMING("warming", "预警"),
|
|
||||||
REALTIME("realTime", "实时信息"),
|
|
||||||
START("start", "状态表示");
|
|
||||||
|
|
||||||
private final String code;
|
|
||||||
private final String info;
|
|
||||||
|
|
||||||
CacheNameEnums(String code, String info) {
|
|
||||||
this.code = code;
|
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 鉴别参数是否是枚举的值
|
|
||||||
*
|
|
||||||
* @param code 需鉴别参数
|
|
||||||
* @return 如果存在返回结果turn, 否则返回false
|
|
||||||
*/
|
|
||||||
public static boolean isCode(String code) {
|
|
||||||
return Arrays.stream(values())
|
|
||||||
.map(CacheNameEnums::getCode)
|
|
||||||
.anyMatch(c -> c.equals(code));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取枚举Value
|
|
||||||
* @param code 编码
|
|
||||||
* @return Value
|
|
||||||
*/
|
|
||||||
public static String getInfo(String code) {
|
|
||||||
return Arrays.stream(values())
|
|
||||||
.filter(c -> c.getCode().equals(code))
|
|
||||||
.map(CacheNameEnums::getInfo)
|
|
||||||
.findFirst()
|
|
||||||
.orElse("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有code
|
|
||||||
* @return code集合
|
|
||||||
*/
|
|
||||||
public static List<String> getCodes() {
|
|
||||||
return Arrays.stream(values())
|
|
||||||
.map(CacheNameEnums::getCode)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
package com.muyu.common.caffeine.utils;
|
|
||||||
|
|
||||||
import com.github.yulichang.toolkit.SpringContentUtils;
|
|
||||||
import com.muyu.common.caffeine.enums.CacheNameEnums;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
import org.springframework.cache.Cache;
|
|
||||||
import org.springframework.cache.CacheManager;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存工具类
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: CacheUtils
|
|
||||||
* @Description: 缓存工具类
|
|
||||||
* @CreatedDate: 2024/10/9 下午4:21
|
|
||||||
* @FilePath: com.muyu.data.processing.utils
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class CacheUtils {
|
|
||||||
private static CacheManager cacheManager = SpringContentUtils.getBean(CacheManager.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取缓存分区
|
|
||||||
* @param cacheName 缓存分区名称
|
|
||||||
* @return 缓存实例
|
|
||||||
*/
|
|
||||||
public Cache getCache(String cacheName) {
|
|
||||||
Cache cache = cacheManager.getCache(cacheName);
|
|
||||||
if (cache == null){
|
|
||||||
throw new RuntimeException("缓存分区: "+cacheName+" 不存在");
|
|
||||||
}
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除缓存 - 根据缓存分区名称
|
|
||||||
* @param cacheName 缓存分区名称
|
|
||||||
*/
|
|
||||||
public void delCache(String cacheName) {
|
|
||||||
getCache(cacheName).invalidate();
|
|
||||||
log.info("缓存清除成功:分区-{}", cacheName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除缓存 - 根据键值
|
|
||||||
* @param key
|
|
||||||
*/
|
|
||||||
public void delCacheValueAll(String key) {
|
|
||||||
CacheNameEnums.getCodes().forEach(cacheName -> delCacheValue(cacheName, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置缓存值
|
|
||||||
* @param cacheName 缓存分区名称
|
|
||||||
* @param key 键
|
|
||||||
* @param value 值
|
|
||||||
*/
|
|
||||||
public void setCacheValue(String cacheName, String key, Object value) {
|
|
||||||
getCache(cacheName).put(key, value);
|
|
||||||
log.info("缓存存储成功:分区-{}, 键-{}, 值-{}", cacheName, key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断缓存是否存在
|
|
||||||
* @param cacheName 缓存分区名称
|
|
||||||
* @param key 键
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public Boolean hasKey(String cacheName, String key) {
|
|
||||||
return ObjectUtils.isNotEmpty(getCache(cacheName).get(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取缓存值(不限定类型)
|
|
||||||
* @param cacheName 缓存分区名称
|
|
||||||
* @param key 键
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public Object getCacheValue(String cacheName, String key) {
|
|
||||||
return getCache(cacheName).get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取缓存值(限定类型)
|
|
||||||
* @param cacheName 缓存分区名称
|
|
||||||
* @param key 键
|
|
||||||
* @param type 返回值类型
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public <T> T getCacheValue(String cacheName, String key, Class<T> type) {
|
|
||||||
return getCache(cacheName).get(key, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除缓存
|
|
||||||
* @param cacheName 缓存分区名称
|
|
||||||
* @param key 键
|
|
||||||
*/
|
|
||||||
public void delCacheValue(String cacheName, String key) {
|
|
||||||
getCache(cacheName).retrieve(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
com.muyu.common.caffeine.bean.CaffeineManager
|
|
|
@ -17,12 +17,6 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.yulichang</groupId>
|
|
||||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
|
||||||
<version>1.4.11</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringCloud Openfeign -->
|
<!-- SpringCloud Openfeign -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
@ -170,13 +164,6 @@
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.paho</groupId>
|
|
||||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
|
||||||
<version>1.2.2</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -21,132 +21,132 @@ public @interface Excel {
|
||||||
/**
|
/**
|
||||||
* 导出时在excel中排序
|
* 导出时在excel中排序
|
||||||
*/
|
*/
|
||||||
public int sort() default Integer.MAX_VALUE;
|
public int sort () default Integer.MAX_VALUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出到Excel中的名字.
|
* 导出到Excel中的名字.
|
||||||
*/
|
*/
|
||||||
public String name() default "";
|
public String name () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日期格式, 如: yyyy-MM-dd
|
* 日期格式, 如: yyyy-MM-dd
|
||||||
*/
|
*/
|
||||||
public String dateFormat() default "";
|
public String dateFormat () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
|
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
|
||||||
*/
|
*/
|
||||||
public String readConverterExp() default "";
|
public String readConverterExp () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分隔符,读取字符串组内容
|
* 分隔符,读取字符串组内容
|
||||||
*/
|
*/
|
||||||
public String separator() default ",";
|
public String separator () default ",";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
|
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
|
||||||
*/
|
*/
|
||||||
public int scale() default -1;
|
public int scale () default -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
|
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
|
||||||
*/
|
*/
|
||||||
public int roundingMode() default BigDecimal.ROUND_HALF_EVEN;
|
public int roundingMode () default BigDecimal.ROUND_HALF_EVEN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出时在excel中每个列的高度
|
* 导出时在excel中每个列的高度
|
||||||
*/
|
*/
|
||||||
public double height() default 14;
|
public double height () default 14;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出时在excel中每个列的宽度
|
* 导出时在excel中每个列的宽度
|
||||||
*/
|
*/
|
||||||
public double width() default 16;
|
public double width () default 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文字后缀,如% 90 变成90%
|
* 文字后缀,如% 90 变成90%
|
||||||
*/
|
*/
|
||||||
public String suffix() default "";
|
public String suffix () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当值为空时,字段的默认值
|
* 当值为空时,字段的默认值
|
||||||
*/
|
*/
|
||||||
public String defaultValue() default "";
|
public String defaultValue () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提示信息
|
* 提示信息
|
||||||
*/
|
*/
|
||||||
public String prompt() default "";
|
public String prompt () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置只能选择不能输入的列内容.
|
* 设置只能选择不能输入的列内容.
|
||||||
*/
|
*/
|
||||||
public String[] combo() default {};
|
public String[] combo () default {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否需要纵向合并单元格,应对需求:含有list集合单元格)
|
* 是否需要纵向合并单元格,应对需求:含有list集合单元格)
|
||||||
*/
|
*/
|
||||||
public boolean needMerge() default false;
|
public boolean needMerge () default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
|
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
|
||||||
*/
|
*/
|
||||||
public boolean isExport() default true;
|
public boolean isExport () default true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 另一个类中的属性名称,支持多级获取,以小数点隔开
|
* 另一个类中的属性名称,支持多级获取,以小数点隔开
|
||||||
*/
|
*/
|
||||||
public String targetAttr() default "";
|
public String targetAttr () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否自动统计数据,在最后追加一行统计数据总和
|
* 是否自动统计数据,在最后追加一行统计数据总和
|
||||||
*/
|
*/
|
||||||
public boolean isStatistics() default false;
|
public boolean isStatistics () default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出类型(0数字 1字符串)
|
* 导出类型(0数字 1字符串)
|
||||||
*/
|
*/
|
||||||
public ColumnType cellType() default ColumnType.STRING;
|
public ColumnType cellType () default ColumnType.STRING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出列头背景颜色
|
* 导出列头背景颜色
|
||||||
*/
|
*/
|
||||||
public IndexedColors headerBackgroundColor() default IndexedColors.GREY_50_PERCENT;
|
public IndexedColors headerBackgroundColor () default IndexedColors.GREY_50_PERCENT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出列头字体颜色
|
* 导出列头字体颜色
|
||||||
*/
|
*/
|
||||||
public IndexedColors headerColor() default IndexedColors.WHITE;
|
public IndexedColors headerColor () default IndexedColors.WHITE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出单元格背景颜色
|
* 导出单元格背景颜色
|
||||||
*/
|
*/
|
||||||
public IndexedColors backgroundColor() default IndexedColors.WHITE;
|
public IndexedColors backgroundColor () default IndexedColors.WHITE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出单元格字体颜色
|
* 导出单元格字体颜色
|
||||||
*/
|
*/
|
||||||
public IndexedColors color() default IndexedColors.BLACK;
|
public IndexedColors color () default IndexedColors.BLACK;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出字段对齐方式
|
* 导出字段对齐方式
|
||||||
*/
|
*/
|
||||||
public HorizontalAlignment align() default HorizontalAlignment.CENTER;
|
public HorizontalAlignment align () default HorizontalAlignment.CENTER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义数据处理器
|
* 自定义数据处理器
|
||||||
*/
|
*/
|
||||||
public Class<?> handler() default ExcelHandlerAdapter.class;
|
public Class<?> handler () default ExcelHandlerAdapter.class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义数据处理器参数
|
* 自定义数据处理器参数
|
||||||
*/
|
*/
|
||||||
public String[] args() default {};
|
public String[] args () default {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
* 字段类型(0:导出导入;1:仅导出;2:仅导入)
|
||||||
*/
|
*/
|
||||||
Type type() default Type.ALL;
|
Type type () default Type.ALL;
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
ALL(0), EXPORT(1), IMPORT(2);
|
ALL(0), EXPORT(1), IMPORT(2);
|
||||||
|
|
|
@ -13,5 +13,5 @@ import java.lang.annotation.Target;
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Excels {
|
public @interface Excels {
|
||||||
Excel[] value();
|
Excel[] value ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,4 @@ public class SecurityConstants {
|
||||||
* 角色权限
|
* 角色权限
|
||||||
*/
|
*/
|
||||||
public static final String ROLE_PERMISSION = "role_permission";
|
public static final String ROLE_PERMISSION = "role_permission";
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SAAS请求头的key
|
|
||||||
*/
|
|
||||||
public static final String SAAS_KEY = "ent-code";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,4 @@ public class ServiceNameConstants {
|
||||||
* 文件服务的serviceid
|
* 文件服务的serviceid
|
||||||
*/
|
*/
|
||||||
public static final String FILE_SERVICE = "cloud-file";
|
public static final String FILE_SERVICE = "cloud-file";
|
||||||
|
|
||||||
public static final String CAR_SERVICE = "cloud-car";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 智能车联服务
|
|
||||||
*/
|
|
||||||
public static final String SMART_SERVICE = "cloud-smart-car";
|
|
||||||
|
|
||||||
public static final String ENT_SERVICE = "cloud-ent";
|
|
||||||
|
|
||||||
public static final String SAAS_SERVICE = "cloud-system-saas";
|
|
||||||
|
|
||||||
public static final String DATA_SERVICE = "cloud-data-processing";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,14 +80,4 @@ public class SecurityContextHolder {
|
||||||
public static void remove () {
|
public static void remove () {
|
||||||
THREAD_LOCAL.remove();
|
THREAD_LOCAL.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getSaasKey() {
|
|
||||||
return get(SecurityConstants.SAAS_KEY);
|
|
||||||
}
|
|
||||||
public static void setSaasKey(String saasKey) {
|
|
||||||
set(SecurityConstants.SAAS_KEY,saasKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
package com.muyu.common.core.domain.properties;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
* @ Tool:IntelliJ IDEA
|
|
||||||
* @ Author:CHX
|
|
||||||
* @ Date:2024-09-26-22:13
|
|
||||||
* @ Version:1.0
|
|
||||||
* @ Description:Mqtt的配置
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class MqttPropertie {
|
|
||||||
/**
|
|
||||||
* 节点
|
|
||||||
*/
|
|
||||||
private String broker;
|
|
||||||
/**
|
|
||||||
* 主题
|
|
||||||
*/
|
|
||||||
private String topic;
|
|
||||||
/**
|
|
||||||
* 用户名
|
|
||||||
*/
|
|
||||||
private String userName;
|
|
||||||
/**
|
|
||||||
* 密码
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
/**
|
|
||||||
* 客户端id
|
|
||||||
*/
|
|
||||||
private String clientId;
|
|
||||||
/**
|
|
||||||
* 上报级别
|
|
||||||
*/
|
|
||||||
private int qos = 0;
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package com.muyu.common.core.enums;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 类型枚举
|
|
||||||
*
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: ClassType
|
|
||||||
* @Description: 类型枚举
|
|
||||||
* @CreatedDate: 2024/9/29 上午9:28
|
|
||||||
* @FilePath: com.muyu.common.core.enums
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public enum ClassType {
|
|
||||||
BYTE("byte", byte.class),
|
|
||||||
SHORT("short", short.class),
|
|
||||||
INT("int", int.class),
|
|
||||||
LONG("long", long.class),
|
|
||||||
FLOAT("float", float.class),
|
|
||||||
DOUBLE("double", double.class),
|
|
||||||
BOOLEAN("boolean", boolean.class),
|
|
||||||
CHAR("char", char.class),
|
|
||||||
STRING("String", String.class),
|
|
||||||
SET("Set", Set.class),
|
|
||||||
MAP("Map", Map.class),
|
|
||||||
LIST("List", List.class);
|
|
||||||
|
|
||||||
private final String code;
|
|
||||||
private final Class<?> info;
|
|
||||||
|
|
||||||
ClassType(String code, Class<?> info) {
|
|
||||||
this.code = code;
|
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 鉴别参数是否是枚举的值
|
|
||||||
*
|
|
||||||
* @param code 需鉴别参数
|
|
||||||
* @return 如果存在返回结果turn, 否则返回false
|
|
||||||
*/
|
|
||||||
public static boolean isCode(String code) {
|
|
||||||
return Arrays.stream(values())
|
|
||||||
.map(ClassType::getCode)
|
|
||||||
.anyMatch(c -> c.equals(code));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Class<?> getInfo(String code) {
|
|
||||||
return Arrays.stream(values())
|
|
||||||
.filter(c -> c.getCode().equals(code))
|
|
||||||
.findFirst()
|
|
||||||
.map(ClassType::getInfo)
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ package com.muyu.common.core.exception;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
public class ServiceException extends RuntimeException {
|
public final class ServiceException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +21,7 @@ public class ServiceException extends RuntimeException {
|
||||||
/**
|
/**
|
||||||
* 错误明细,内部调试错误
|
* 错误明细,内部调试错误
|
||||||
* <p>
|
* <p>
|
||||||
* 和 {CommonResult#getDetailMessage()} 一致的设计
|
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
|
||||||
*/
|
*/
|
||||||
private String detailMessage;
|
private String detailMessage;
|
||||||
|
|
||||||
|
|
|
@ -162,17 +162,4 @@ public class JwtUtils {
|
||||||
public static String getValue (Claims claims, String key) {
|
public static String getValue (Claims claims, String key) {
|
||||||
return Convert.toStr(claims.get(key), "");
|
return Convert.toStr(claims.get(key), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据身份信息获取SAASKey
|
|
||||||
*
|
|
||||||
* @param claims 身份信息
|
|
||||||
*
|
|
||||||
* @return saas_key
|
|
||||||
*/
|
|
||||||
public static String getSaasKey(Claims claims) {
|
|
||||||
return getValue(claims, SecurityConstants.SAAS_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
|
||||||
*
|
*
|
||||||
* @return Object 一个以所给名字注册的bean的实例
|
* @return Object 一个以所给名字注册的bean的实例
|
||||||
*
|
*
|
||||||
* @throws BeansException
|
* @throws org.springframework.beans.BeansException
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T getBean (String name) throws BeansException {
|
public static <T> T getBean (String name) throws BeansException {
|
||||||
|
@ -40,7 +40,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
* @throws BeansException
|
* @throws org.springframework.beans.BeansException
|
||||||
*/
|
*/
|
||||||
public static <T> T getBean (Class<T> clz) throws BeansException {
|
public static <T> T getBean (Class<T> clz) throws BeansException {
|
||||||
T result = (T) beanFactory.getBean(clz);
|
T result = (T) beanFactory.getBean(clz);
|
||||||
|
@ -65,7 +65,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*
|
*
|
||||||
* @throws NoSuchBeanDefinitionException
|
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||||
*/
|
*/
|
||||||
public static boolean isSingleton (String name) throws NoSuchBeanDefinitionException {
|
public static boolean isSingleton (String name) throws NoSuchBeanDefinitionException {
|
||||||
return beanFactory.isSingleton(name);
|
return beanFactory.isSingleton(name);
|
||||||
|
@ -76,7 +76,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
|
||||||
*
|
*
|
||||||
* @return Class 注册对象的类型
|
* @return Class 注册对象的类型
|
||||||
*
|
*
|
||||||
* @throws NoSuchBeanDefinitionException
|
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||||
*/
|
*/
|
||||||
public static Class<?> getType (String name) throws NoSuchBeanDefinitionException {
|
public static Class<?> getType (String name) throws NoSuchBeanDefinitionException {
|
||||||
return beanFactory.getType(name);
|
return beanFactory.getType(name);
|
||||||
|
@ -89,7 +89,7 @@ public final class SpringUtils implements BeanFactoryPostProcessor {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
* @throws NoSuchBeanDefinitionException
|
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||||
*/
|
*/
|
||||||
public static String[] getAliases (String name) throws NoSuchBeanDefinitionException {
|
public static String[] getAliases (String name) throws NoSuchBeanDefinitionException {
|
||||||
return beanFactory.getAliases(name);
|
return beanFactory.getAliases(name);
|
||||||
|
|
|
@ -58,8 +58,7 @@ public class IpUtils {
|
||||||
ip = request.getRemoteAddr();
|
ip = request.getRemoteAddr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip);
|
||||||
return "0:0:0:0:0:0:0:1".equals(ip) ? "106.54.193.225" : getMultistageReverseProxyIp(ip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,10 +70,7 @@ public class IpUtils {
|
||||||
*/
|
*/
|
||||||
public static boolean internalIp (String ip) {
|
public static boolean internalIp (String ip) {
|
||||||
byte[] addr = textToNumericFormatV4(ip);
|
byte[] addr = textToNumericFormatV4(ip);
|
||||||
|
return internalIp(addr) || "127.0.0.1".equals(ip);
|
||||||
return internalIp(addr) || "106.54.193.225".equals(ip);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,8 +197,7 @@ public class IpUtils {
|
||||||
return InetAddress.getLocalHost().getHostAddress();
|
return InetAddress.getLocalHost().getHostAddress();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
}
|
}
|
||||||
|
return "127.0.0.1";
|
||||||
return "106.54.193.225";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,11 +17,11 @@ import java.lang.annotation.Target;
|
||||||
@Target(value = {ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
|
@Target(value = {ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
|
||||||
@Constraint(validatedBy = {XssValidator.class})
|
@Constraint(validatedBy = {XssValidator.class})
|
||||||
public @interface Xss {
|
public @interface Xss {
|
||||||
String message()
|
String message ()
|
||||||
|
|
||||||
default "不允许任何脚本运行";
|
default "不允许任何脚本运行";
|
||||||
|
|
||||||
Class<?>[] groups() default {};
|
Class<?>[] groups () default {};
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default {};
|
Class<? extends Payload>[] payload () default {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,15 +14,15 @@ public @interface DataScope {
|
||||||
/**
|
/**
|
||||||
* 部门表的别名
|
* 部门表的别名
|
||||||
*/
|
*/
|
||||||
public String deptAlias() default "";
|
public String deptAlias () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户表的别名
|
* 用户表的别名
|
||||||
*/
|
*/
|
||||||
public String userAlias() default "";
|
public String userAlias () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限字符(用于多个角色匹配符合要求的权限)默认根据权限注解@RequiresPermissions获取,多个权限用逗号分隔开来
|
* 权限字符(用于多个角色匹配符合要求的权限)默认根据权限注解@RequiresPermissions获取,多个权限用逗号分隔开来
|
||||||
*/
|
*/
|
||||||
public String permission() default "";
|
public String permission () default "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>cloud-common-iotdb</artifactId>
|
|
||||||
<description>
|
|
||||||
cloud-common-iotdb 时序数据库模块
|
|
||||||
</description>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.iotdb</groupId>
|
|
||||||
<artifactId>iotdb-session</artifactId>
|
|
||||||
<version>1.3.2</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,53 +0,0 @@
|
||||||
package com.muyu.common.iotdb.config;
|
|
||||||
|
|
||||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
|
||||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
|
||||||
import org.apache.iotdb.session.Session;
|
|
||||||
import org.apache.iotdb.session.pool.SessionPool;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时序数据库配置
|
|
||||||
*
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: IotDBConfig
|
|
||||||
* @Description: 时序数据库配置
|
|
||||||
* @CreatedDate: 2024/9/29 下午9:30
|
|
||||||
* @FilePath: com.muyu.data.processing.config
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class IotDBSessionConfig {
|
|
||||||
|
|
||||||
@Value("${spring.iotdb.ip}")
|
|
||||||
private String ip;
|
|
||||||
|
|
||||||
@Value("${spring.iotdb.port}")
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
@Value("${spring.iotdb.user}")
|
|
||||||
private String user;
|
|
||||||
|
|
||||||
@Value("${spring.iotdb.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Value("${spring.iotdb.fetchSize}")
|
|
||||||
private int fetchSize;
|
|
||||||
|
|
||||||
private static SessionPool sessionPool;
|
|
||||||
@Bean
|
|
||||||
public SessionPool getSessionPool(){
|
|
||||||
if (sessionPool == null) {
|
|
||||||
sessionPool = new SessionPool(ip, port, user, password, fetchSize);
|
|
||||||
try {
|
|
||||||
sessionPool.setTimeZone("+08:00");
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sessionPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
com.muyu.common.iotdb.config.IotDBSessionConfig
|
|
|
@ -1,37 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
|
||||||
<description>
|
|
||||||
cloud-common-kafka kafka中间件模块
|
|
||||||
</description>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.kafka</groupId>
|
|
||||||
<artifactId>kafka-clients</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,54 +0,0 @@
|
||||||
package com.muyu.common.kafka.config;
|
|
||||||
|
|
||||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
|
||||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
||||||
import org.apache.kafka.common.serialization.Deserializer;
|
|
||||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.SpringBootConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* kafka 消息的消费者 配置类
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class KafkaConsumerConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public KafkaConsumer kafkaConsumer() {
|
|
||||||
Map<String, Object> configs = new HashMap<>();
|
|
||||||
//kafka服务端的IP和端口,格式:(ip:port)
|
|
||||||
configs.put("bootstrap.servers", "47.116.173.119:9092");
|
|
||||||
//开启consumer的偏移量(offset)自动提交到Kafka
|
|
||||||
configs.put("enable.auto.commit", true);
|
|
||||||
//consumer的偏移量(offset) 自动提交的时间间隔,单位毫秒
|
|
||||||
configs.put("auto.commit.interval", 5000);
|
|
||||||
//在Kafka中没有初始化偏移量或者当前偏移量不存在情况
|
|
||||||
//earliest, 在偏移量无效的情况下, 自动重置为最早的偏移量
|
|
||||||
//latest, 在偏移量无效的情况下, 自动重置为最新的偏移量
|
|
||||||
//none, 在偏移量无效的情况下, 抛出异常.
|
|
||||||
configs.put("auto.offset.reset", "latest");
|
|
||||||
//请求阻塞的最大时间(毫秒)
|
|
||||||
configs.put("fetch.max.wait", 500);
|
|
||||||
//请求应答的最小字节数
|
|
||||||
configs.put("fetch.min.size", 1);
|
|
||||||
//心跳间隔时间(毫秒)
|
|
||||||
configs.put("heartbeat-interval", 3000);
|
|
||||||
//一次调用poll返回的最大记录条数
|
|
||||||
configs.put("max.poll.records", 500);
|
|
||||||
//指定消费组
|
|
||||||
configs.put("group.id", KafkaConstants.KafkaGrop);
|
|
||||||
//指定key使用的反序列化类
|
|
||||||
Deserializer keyDeserializer = new StringDeserializer();
|
|
||||||
//指定value使用的反序列化类
|
|
||||||
Deserializer valueDeserializer = new StringDeserializer();
|
|
||||||
//创建Kafka消费者
|
|
||||||
KafkaConsumer kafkaConsumer = new KafkaConsumer(configs, keyDeserializer, valueDeserializer);
|
|
||||||
return kafkaConsumer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package com.muyu.common.kafka.config;
|
|
||||||
|
|
||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
|
||||||
import org.apache.kafka.common.serialization.Serializer;
|
|
||||||
import org.apache.kafka.common.serialization.StringSerializer;
|
|
||||||
import org.springframework.boot.SpringBootConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* kafka 消息的生产者 配置类
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class KafkaProviderConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public KafkaProducer kafkaProducer() {
|
|
||||||
Map<String, Object> configs = new HashMap<>();
|
|
||||||
//#kafka服务端的IP和端口,格式:(ip:port)
|
|
||||||
configs.put("bootstrap.servers", "47.116.173.119:9092");
|
|
||||||
//客户端发送服务端失败的重试次数
|
|
||||||
configs.put("retries", 2);
|
|
||||||
//多个记录被发送到同一个分区时,生产者将尝试将记录一起批处理成更少的请求.
|
|
||||||
//此设置有助于提高客户端和服务器的性能,配置控制默认批量大小(以字节为单位)
|
|
||||||
configs.put("batch.size", 16384);
|
|
||||||
//生产者可用于缓冲等待发送到服务器的记录的总内存字节数(以字节为单位)
|
|
||||||
configs.put("buffer-memory", 33554432);
|
|
||||||
//生产者producer要求leader节点在考虑完成请求之前收到的确认数,用于控制发送记录在服务端的持久化
|
|
||||||
//acks=0,设置为0,则生产者producer将不会等待来自服务器的任何确认.该记录将立即添加到套接字(socket)缓冲区并视为已发送.在这种情况下,无法保证服务器已收到记录,并且重试配置(retries)将不会生效(因为客户端通常不会知道任何故障),每条记录返回的偏移量始终设置为-1.
|
|
||||||
//acks=1,设置为1,leader节点会把记录写入本地日志,不需要等待所有follower节点完全确认就会立即应答producer.在这种情况下,在follower节点复制前,leader节点确认记录后立即失败的话,记录将会丢失.
|
|
||||||
//acks=all,acks=-1,leader节点将等待所有同步复制副本完成再确认记录,这保证了只要至少有一个同步复制副本存活,记录就不会丢失.
|
|
||||||
configs.put("acks", "-1");
|
|
||||||
//指定key使用的序列化类
|
|
||||||
Serializer keySerializer = new StringSerializer();
|
|
||||||
//指定value使用的序列化类
|
|
||||||
Serializer valueSerializer = new StringSerializer();
|
|
||||||
//创建Kafka生产者
|
|
||||||
KafkaProducer kafkaProducer = new KafkaProducer(configs, keySerializer, valueSerializer);
|
|
||||||
return kafkaProducer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package com.muyu.common.kafka.constants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @date: 2024/7/10
|
|
||||||
* @Description: kafka常量
|
|
||||||
* @Version 1.0.0
|
|
||||||
*/
|
|
||||||
public class KafkaConstants {
|
|
||||||
|
|
||||||
public final static String KafkaTopic = "kafka_topic2";
|
|
||||||
|
|
||||||
public final static String KafkaGrop = "kafka_grop2";
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
com.muyu.common.kafka.config.KafkaConsumerConfig
|
|
||||||
com.muyu.common.kafka.config.KafkaProviderConfig
|
|
|
@ -17,30 +17,30 @@ public @interface Log {
|
||||||
/**
|
/**
|
||||||
* 模块
|
* 模块
|
||||||
*/
|
*/
|
||||||
public String title() default "";
|
public String title () default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能
|
* 功能
|
||||||
*/
|
*/
|
||||||
public BusinessType businessType() default BusinessType.OTHER;
|
public BusinessType businessType () default BusinessType.OTHER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作人类别
|
* 操作人类别
|
||||||
*/
|
*/
|
||||||
public OperatorType operatorType() default OperatorType.MANAGE;
|
public OperatorType operatorType () default OperatorType.MANAGE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否保存请求的参数
|
* 是否保存请求的参数
|
||||||
*/
|
*/
|
||||||
public boolean isSaveRequestData() default true;
|
public boolean isSaveRequestData () default true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否保存响应的参数
|
* 是否保存响应的参数
|
||||||
*/
|
*/
|
||||||
public boolean isSaveResponseData() default true;
|
public boolean isSaveResponseData () default true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排除指定的请求参数
|
* 排除指定的请求参数
|
||||||
*/
|
*/
|
||||||
public String[] excludeParamNames() default {};
|
public String[] excludeParamNames () default {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,7 @@ import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.core.NamedThreadLocal;
|
import org.springframework.core.NamedThreadLocal;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -52,11 +48,7 @@ public class LogAspect {
|
||||||
*/
|
*/
|
||||||
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
||||||
private AsyncLogService asyncLogService;
|
private AsyncLogService asyncLogService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,7 +82,7 @@ public class LogAspect {
|
||||||
|
|
||||||
protected void handleLog (final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) {
|
protected void handleLog (final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) {
|
||||||
try {
|
try {
|
||||||
// *=数据库日志==*//
|
// *========数据库日志=========*//
|
||||||
SysOperLog operLog = new SysOperLog();
|
SysOperLog operLog = new SysOperLog();
|
||||||
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
||||||
// 请求的地址
|
// 请求的地址
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.muyu.common.log.service;
|
||||||
import com.muyu.common.core.constant.SecurityConstants;
|
import com.muyu.common.core.constant.SecurityConstants;
|
||||||
import com.muyu.common.system.remote.RemoteLogService;
|
import com.muyu.common.system.remote.RemoteLogService;
|
||||||
import com.muyu.common.system.domain.SysOperLog;
|
import com.muyu.common.system.domain.SysOperLog;
|
||||||
import javax.annotation.Resource;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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;
|
||||||
|
|
|
@ -10,9 +10,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>cloud-common-rabbit</artifactId>
|
<artifactId>cloud-common-rabbit</artifactId>
|
||||||
<description>
|
|
||||||
cloud-common-rabbit rabbit中间件模块
|
|
||||||
</description>
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.common.rabbit.config;
|
package com.muyu.common.rabbit;
|
||||||
|
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer;
|
|
||||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -9,30 +8,21 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
* @Description rabbitMQ的监听器配置
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RabbitListenerConfig implements RabbitListenerConfigurer {
|
public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// 设置为信任所有类型的反序列化,确保消息能够正确反序列化
|
|
||||||
System.setProperty("spring.amqp.deserialization.trust.all", "true");
|
System.setProperty("spring.amqp.deserialization.trust.all", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//以下配置RabbitMQ消息服务
|
||||||
* RabbitMQ连接工厂,用于创建连接
|
|
||||||
*/
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ConnectionFactory connectionFactory;
|
public ConnectionFactory connectionFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建处理器方法工厂的bean
|
* 处理器方法工厂
|
||||||
*
|
* @return
|
||||||
* @return DefaultMessageHandlerMethodFactory 实例,用于处理消息的转换和方法调用
|
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public DefaultMessageHandlerMethodFactory handlerMethodFactory() {
|
public DefaultMessageHandlerMethodFactory handlerMethodFactory() {
|
||||||
|
@ -42,14 +32,8 @@ public class RabbitListenerConfig implements RabbitListenerConfigurer {
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置RabbitMQ监听器的消息处理方法工厂。
|
|
||||||
*
|
|
||||||
* @param rabbitListenerEndpointRegistrar 实例,用于注册监听器的配置
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void configureRabbitListeners(RabbitListenerEndpointRegistrar rabbitListenerEndpointRegistrar) {
|
public void configureRabbitListeners(RabbitListenerEndpointRegistrar rabbitListenerEndpointRegistrar) {
|
||||||
// 注册自定义的消息处理方法工厂
|
|
||||||
rabbitListenerEndpointRegistrar.setMessageHandlerMethodFactory(handlerMethodFactory());
|
rabbitListenerEndpointRegistrar.setMessageHandlerMethodFactory(handlerMethodFactory());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
package com.muyu.common.rabbit.callback;
|
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
* @Description 消息发送到broker确认回调
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class ConfirmCallback implements RabbitTemplate.ConfirmCallback {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RabbitTemplate rabbitTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化
|
|
||||||
*/
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
this.rabbitTemplate.setConfirmCallback(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 回调确认方法(消息发送之后 消息无论发送成功还是失败都会执行这个回调方法)
|
|
||||||
* @param correlationData 回调的相关数据
|
|
||||||
* @param ack 确认结果(true表示消息已经被broker接收,false表示消息未被broker接收)
|
|
||||||
* @param cause 失败原因(当ack为false时,表示拒绝接收消息的原因;当ack为true时,该值为空)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
|
||||||
if (ack) {
|
|
||||||
log.info("消息发送到broker成功!");
|
|
||||||
} else {
|
|
||||||
log.info("消息发送到broker失败,失败原因:{}", cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package com.muyu.common.rabbit.callback;
|
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.amqp.core.ReturnedMessage;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
* @Description 消息发送失败时回调
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class ReturnsCallback implements RabbitTemplate.ReturnsCallback {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RabbitTemplate rabbitTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化
|
|
||||||
*/
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
rabbitTemplate.setReturnsCallback(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息发送到队列失败时执行
|
|
||||||
* @param returnedMessage 返回的消息和元数据
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
|
||||||
log.info("消息:{}被交换机:{}回退!回退原因:{}", returnedMessage.getMessage().toString(),
|
|
||||||
returnedMessage.getExchange(), returnedMessage.getReplyText());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
||||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
* @Description RabbitMQ连接和管理功能配置
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class RabbitAdminConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RabbitMQ服务器的主机地址
|
|
||||||
*/
|
|
||||||
@Value("${spring.rabbitmq.host}")
|
|
||||||
private String host;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RabbitMQ的用户名
|
|
||||||
*/
|
|
||||||
@Value("${spring.rabbitmq.username}")
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RabbitMQ的密码
|
|
||||||
*/
|
|
||||||
@Value("${spring.rabbitmq.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RabbitMQ的虚拟主机
|
|
||||||
*/
|
|
||||||
@Value("${spring.rabbitmq.virtualhost}")
|
|
||||||
private String virtualhost;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建并初始化RabbitAdmin实例
|
|
||||||
*
|
|
||||||
* @return RabbitAdmin 实例
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public RabbitAdmin rabbitAdmin() {
|
|
||||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory());
|
|
||||||
rabbitAdmin.setAutoStartup(true);
|
|
||||||
return rabbitAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建RabbitMQ连接工厂
|
|
||||||
*
|
|
||||||
* @return ConnectionFactory 实例
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public ConnectionFactory connectionFactory() {
|
|
||||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
|
||||||
connectionFactory.setAddresses(host);
|
|
||||||
connectionFactory.setUsername(username);
|
|
||||||
connectionFactory.setPassword(password);
|
|
||||||
connectionFactory.setVirtualHost(virtualhost);
|
|
||||||
|
|
||||||
// 配置发送确认回调时,次配置必须配置,否则即使在RabbitTemplate配置了ConfirmCallback也不会生效
|
|
||||||
connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
|
|
||||||
connectionFactory.setPublisherReturns(true);
|
|
||||||
return connectionFactory;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
|
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|
||||||
import org.springframework.amqp.support.converter.MessageConverter;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
* @Description rabbitMQ消息转换器配置
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class RabbitMQMessageConverterConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息转换配置
|
|
||||||
*
|
|
||||||
* @return 消息转换器
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public MessageConverter jsonMessageConverter() {
|
|
||||||
return new Jackson2JsonMessageConverter();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,129 +0,0 @@
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.amqp.core.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
* @ Tool:IntelliJ IDEA
|
|
||||||
* @ Author:CHX
|
|
||||||
* @ Date:2024-10-04-15:13
|
|
||||||
* @ Version:1.0
|
|
||||||
* @ Description:rabbitmq配置类
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
@Configuration
|
|
||||||
public class RabbitmqConfig {
|
|
||||||
// 日志
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RabbitmqConfig.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 队列
|
|
||||||
*/
|
|
||||||
public static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
|
|
||||||
/**
|
|
||||||
* 队列
|
|
||||||
*/
|
|
||||||
public static final String QUEUE_INFORM_SMS = "queue_inform_sms";
|
|
||||||
/**
|
|
||||||
* 队列
|
|
||||||
*/
|
|
||||||
public static final String QUEUE_INFORM_SEND = "queue_inform_send";
|
|
||||||
/**
|
|
||||||
* 交换机
|
|
||||||
*/
|
|
||||||
public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";
|
|
||||||
/**
|
|
||||||
* 路由key
|
|
||||||
*/
|
|
||||||
public static final String ROUTINGKEY_EMAIL = "inform.#.email.#";
|
|
||||||
/**
|
|
||||||
* 路由key
|
|
||||||
*/
|
|
||||||
public static final String ROUTINGKEY_SMS = "inform.#.sms.#";
|
|
||||||
/**
|
|
||||||
* 路由key
|
|
||||||
*/
|
|
||||||
public static final String ROUTINGKEY_SEND = "inform.#.send.#";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 声明交换机,做持久化
|
|
||||||
*/
|
|
||||||
@Bean(EXCHANGE_TOPICS_INFORM)
|
|
||||||
public Exchange exchangeTopicsInform() {
|
|
||||||
try {
|
|
||||||
Exchange exchange = ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
|
|
||||||
log.info("创建的交换机为: {}", EXCHANGE_TOPICS_INFORM);
|
|
||||||
return exchange;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("创建该: {} 交换机失败", EXCHANGE_TOPICS_INFORM, e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 声明QUEUE_INFORM_EMAIL队列
|
|
||||||
@Bean(QUEUE_INFORM_EMAIL)
|
|
||||||
public Queue queueInformEmail() {
|
|
||||||
try {
|
|
||||||
Queue queue = new Queue(QUEUE_INFORM_EMAIL);
|
|
||||||
log.info("创建的队列为: {}", QUEUE_INFORM_EMAIL);
|
|
||||||
return queue;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("创建该: {} 队列失败", QUEUE_INFORM_EMAIL, e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 声明QUEUE_INFORM_SMS队列
|
|
||||||
@Bean(QUEUE_INFORM_SMS)
|
|
||||||
public Queue queueInformSms() {
|
|
||||||
try {
|
|
||||||
Queue queue = new Queue(QUEUE_INFORM_SMS);
|
|
||||||
log.info("创建的队列为: {}", QUEUE_INFORM_SMS);
|
|
||||||
return queue;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("创建该: {} 队列失败", QUEUE_INFORM_SMS, e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 声明QUEUE_INFORM_SEND队列
|
|
||||||
@Bean(QUEUE_INFORM_SEND)
|
|
||||||
public Queue queueInformSend() {
|
|
||||||
try {
|
|
||||||
Queue queue = new Queue(QUEUE_INFORM_SEND);
|
|
||||||
log.info("创建的队列为: {}", QUEUE_INFORM_SEND);
|
|
||||||
return queue;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("创建该: {} 队列失败", QUEUE_INFORM_SEND, e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//ROUTINGKEY_EMAIL队列绑定交换机,指定routingKey
|
|
||||||
@Bean
|
|
||||||
public Binding bindingQueueInformEmail(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue,
|
|
||||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
|
||||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
|
|
||||||
}
|
|
||||||
|
|
||||||
//ROUTINGKEY_SMS队列绑定交换机,指定routingKey
|
|
||||||
@Bean
|
|
||||||
public Binding bindingRoutingKeySms(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
|
|
||||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
|
||||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
|
|
||||||
}
|
|
||||||
|
|
||||||
//ROUTINGKEY_SEND队列绑定交换机,指定routingKey
|
|
||||||
@Bean
|
|
||||||
public Binding bindingRoutingKeySend(@Qualifier(QUEUE_INFORM_SEND) Queue queue,
|
|
||||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
|
||||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SEND).noargs();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.muyu.common.rabbit.constants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* rabbit常量
|
|
||||||
*
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @date: 2024/7/10
|
|
||||||
* @Description: rabbit常量
|
|
||||||
* @Version 1.0.0
|
|
||||||
*/
|
|
||||||
public class RabbitConstants {
|
|
||||||
|
|
||||||
public final static String GO_ONLINE_QUEUE = "GoOnline";
|
|
||||||
|
|
||||||
public final static String DOWNLINE_QUEUE = "Downline";
|
|
||||||
public final static String FORM_QUEUE = "queue_inform_sms";
|
|
||||||
}
|
|
|
@ -1,3 +1 @@
|
||||||
com.muyu.common.rabbit.config.RabbitListenerConfig
|
com.muyu.common.rabbit.RabbitListenerConfigurer
|
||||||
com.muyu.common.rabbit.config.RabbitAdminConfig
|
|
||||||
com.muyu.common.rabbit.config.RabbitMQMessageConverterConfig
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.common.redis.service;
|
package com.muyu.common.redis.service;
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.BoundSetOperations;
|
import org.springframework.data.redis.core.BoundSetOperations;
|
||||||
import org.springframework.data.redis.core.HashOperations;
|
import org.springframework.data.redis.core.HashOperations;
|
||||||
|
@ -8,7 +7,6 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.core.ValueOperations;
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -20,8 +18,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||||
@Component
|
@Component
|
||||||
public class RedisService {
|
public class RedisService {
|
||||||
|
@Autowired
|
||||||
@Resource
|
|
||||||
public RedisTemplate redisTemplate;
|
public RedisTemplate redisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,7 +229,7 @@ public class RedisService {
|
||||||
*
|
*
|
||||||
* @return Hash对象集合
|
* @return Hash对象集合
|
||||||
*/
|
*/
|
||||||
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<String> hKeys) {
|
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
|
||||||
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,33 +255,4 @@ public class RedisService {
|
||||||
public Collection<String> keys (final String pattern) {
|
public Collection<String> keys (final String pattern) {
|
||||||
return redisTemplate.keys(pattern);
|
return redisTemplate.keys(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断redis中hashKey是否存在
|
|
||||||
* @param key redis键
|
|
||||||
* @param hashKey hash键
|
|
||||||
*/
|
|
||||||
public boolean hashKey(final String key, final String hashKey){
|
|
||||||
return this.redisTemplate.opsForHash().hasKey(key, hashKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 减少序列值
|
|
||||||
* @param key key
|
|
||||||
* @param number 值
|
|
||||||
* @return 操作后的值
|
|
||||||
*/
|
|
||||||
public Long decrement (final String key, Long number) {
|
|
||||||
return redisTemplate.opsForValue().decrement(key,number);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 增加序列值
|
|
||||||
* @param key key
|
|
||||||
* @param number 值
|
|
||||||
* @return 操作后的值
|
|
||||||
*/
|
|
||||||
public Long increment (final String key, Long number) {
|
|
||||||
return redisTemplate.opsForValue().increment(key,number);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>cloud-common-saas</artifactId>
|
|
||||||
<description>
|
|
||||||
cloud-common-saas saas数据源切换模块
|
|
||||||
</description>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- 多数据源依赖 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-datasource</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 鉴权依赖 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-security</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,107 +0,0 @@
|
||||||
package com.muyu.cloud.common.many.datasource;
|
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
|
||||||
import com.muyu.cloud.common.saas.domain.model.EntInfo;
|
|
||||||
import com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory;
|
|
||||||
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
|
|
||||||
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
|
||||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.core.utils.SpringUtils;
|
|
||||||
import com.muyu.common.system.domain.SysEnt;
|
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
|
|
||||||
import org.springframework.boot.ApplicationArguments;
|
|
||||||
import org.springframework.boot.ApplicationRunner;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: DongZeLiang
|
|
||||||
* @date: 2024/6/3
|
|
||||||
* @Description: 多数据源
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
@AutoConfiguration(before = {MybatisPlusAutoConfiguration.class, MybatisAutoConfiguration.class})
|
|
||||||
@Component
|
|
||||||
public class ManyDataSource implements ApplicationRunner{
|
|
||||||
|
|
||||||
|
|
||||||
private List<EntInfo> dataSourceInfoList(){
|
|
||||||
RemoteUserService remoteUserService = SpringUtils.getBean(RemoteUserService.class);
|
|
||||||
Result<List<SysEnt>> listResult = remoteUserService.list(new SysEnt());
|
|
||||||
if (listResult==null){
|
|
||||||
throw new SaaSException("saas远调数据源错误");
|
|
||||||
}
|
|
||||||
List<SysEnt> data = listResult.getData();
|
|
||||||
System.out.println(data);
|
|
||||||
if (listResult.getCode() == Result.SUCCESS && data !=null){
|
|
||||||
List<EntInfo> list = new ArrayList<>();
|
|
||||||
for (SysEnt row : data) {
|
|
||||||
list.add(
|
|
||||||
EntInfo.builder()
|
|
||||||
.entCode(row.getEntCode())
|
|
||||||
.dbName(row.getDbName())
|
|
||||||
.ip(row.getIp())
|
|
||||||
.port(row.getPort())
|
|
||||||
.userName(row.getUserName())
|
|
||||||
.password(row.getPassword())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}else {
|
|
||||||
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(listResult));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
|
||||||
// 企业列表 企业CODE,端口,IP
|
|
||||||
Map<Object, Object> dataSourceMap = new HashMap<>();
|
|
||||||
Objects.requireNonNull(dataSourceInfoList())
|
|
||||||
.stream()
|
|
||||||
.map(DataSourceInfo::hostAndPortBuild)
|
|
||||||
.map(druidDataSourceFactory::create)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.forEach( druidDataSource -> {
|
|
||||||
dataSourceMap.put(druidDataSource.getName(), druidDataSource);
|
|
||||||
});
|
|
||||||
//设置动态数据源
|
|
||||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
|
||||||
// dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
|
|
||||||
dynamicDataSource.setTargetDataSources(dataSourceMap);
|
|
||||||
//将数据源信息备份在defineTargetDataSources中
|
|
||||||
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
|
||||||
log.info("动态数据源加载完成,持有key:{}",dynamicDataSource.getKeys());
|
|
||||||
return dynamicDataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(ApplicationArguments args) {
|
|
||||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
|
||||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
|
||||||
for (EntInfo entInfo : dataSourceInfoList()) {
|
|
||||||
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(entInfo);
|
|
||||||
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
|
||||||
dynamicDataSource.put(dataSourceInfo.getKey(), druidDataSource);
|
|
||||||
log.info("存储数据连接池为:key:{}",dataSourceInfo.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Bean
|
|
||||||
// public SqlSessionFactory sqlSessionFactory(DynamicDataSource dataSource) throws Exception {
|
|
||||||
// SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
|
|
||||||
// sessionFactory.setDataSource(dataSource);
|
|
||||||
// return sessionFactory.getObject();
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package com.muyu.cloud.common.many.datasource.constents;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 数据源常量
|
|
||||||
* @Date 2023-8-1 上午 11:02
|
|
||||||
*/
|
|
||||||
public class DatasourceContent {
|
|
||||||
|
|
||||||
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
|
||||||
|
|
||||||
public final static String USER_NAME = "root";
|
|
||||||
|
|
||||||
public final static String PASSWORD = "bawei2112A";
|
|
||||||
|
|
||||||
public final static String IP = "106.54.193.225";
|
|
||||||
|
|
||||||
public final static Integer PORT = 3306;
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package com.muyu.cloud.common.many.datasource.domain.model;
|
|
||||||
|
|
||||||
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
|
||||||
import com.muyu.cloud.common.saas.domain.model.EntInfo;
|
|
||||||
import com.muyu.common.core.utils.StringUtils;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author DongZl
|
|
||||||
* @description: 数据源实体类
|
|
||||||
* @Date 2023-8-1 上午 11:15
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class DataSourceInfo {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 键
|
|
||||||
*/
|
|
||||||
private String key;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地址
|
|
||||||
*/
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户名
|
|
||||||
*/
|
|
||||||
private String userName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 密码
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
|
|
||||||
// public static DataSourceInfo hostAndPortBuild(String key, String host, Integer port) {
|
|
||||||
// return DataSourceInfo.builder()
|
|
||||||
// .key(key)
|
|
||||||
// .url(StringUtils.format(DatasourceContent.DATASOURCE_URL, host, port, key))
|
|
||||||
// .password(DatasourceContent.PASSWORD)
|
|
||||||
// .userName(DatasourceContent.USER_NAME)
|
|
||||||
// .build();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static DataSourceInfo hostAndPortBuild(EntInfo entInfo) {
|
|
||||||
return DataSourceInfo.builder()
|
|
||||||
.key(entInfo.getEntCode())
|
|
||||||
.url(StringUtils.format(DatasourceContent.DATASOURCE_URL, entInfo.getIp(), entInfo.getPort(), entInfo.getDbName()))
|
|
||||||
.userName(entInfo.getUserName())
|
|
||||||
.password(entInfo.getPassword())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package com.muyu.cloud.common.many.datasource.factory;
|
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
|
||||||
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: DongZeLiang
|
|
||||||
* @date: 2024/6/3
|
|
||||||
* @Description: Druid工厂
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
@Component
|
|
||||||
public class DruidDataSourceFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 根据传递的数据源信息测试数据库连接
|
|
||||||
* @Author Dongzl
|
|
||||||
*/
|
|
||||||
public DruidDataSource create(DataSourceInfo dataSourceInfo) {
|
|
||||||
DruidDataSource druidDataSource = new DruidDataSource();
|
|
||||||
druidDataSource.setName(dataSourceInfo.getKey());
|
|
||||||
druidDataSource.setUrl(dataSourceInfo.getUrl());
|
|
||||||
druidDataSource.setConnectTimeout(10000);
|
|
||||||
druidDataSource.setMaxWait(60000);
|
|
||||||
druidDataSource.setUsername(dataSourceInfo.getUserName());
|
|
||||||
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
|
||||||
druidDataSource.setBreakAfterAcquireFailure(true);
|
|
||||||
druidDataSource.setConnectionErrorRetryAttempts(0);
|
|
||||||
try {
|
|
||||||
DruidPooledConnection connection = druidDataSource.getConnection(2000);
|
|
||||||
log.info("{} -> 数据源连接成功", dataSourceInfo.getKey());
|
|
||||||
connection.close();
|
|
||||||
return druidDataSource;
|
|
||||||
} catch (SQLException throwables) {
|
|
||||||
log.error("数据源 {} 连接失败,用户名:{},密码 {}, 原因:{}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword(), throwables);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package com.muyu.cloud.common.many.datasource.holder;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据源切换处理
|
|
||||||
*
|
|
||||||
* @author Dongzl
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class DynamicDataSourceHolder {
|
|
||||||
/**
|
|
||||||
* 保存动态数据源名称
|
|
||||||
*/
|
|
||||||
private static final ThreadLocal<String> DYNAMIC_DATASOURCE_KEY = new ThreadLocal<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置/切换数据源,决定当前线程使用哪个数据源
|
|
||||||
*/
|
|
||||||
public static void setDynamicDataSourceKey(String key){
|
|
||||||
log.info("数据源切换为:{}",key);
|
|
||||||
DYNAMIC_DATASOURCE_KEY.set(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取动态数据源名称,默认使用mater数据源
|
|
||||||
*/
|
|
||||||
public static String getDynamicDataSourceKey(){
|
|
||||||
String key = DYNAMIC_DATASOURCE_KEY.get();
|
|
||||||
Assert.notNull(key, "请携带数据标识");
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 移除当前数据源
|
|
||||||
*/
|
|
||||||
public static void removeDynamicDataSourceKey(){
|
|
||||||
log.info("移除数据源:{}",DYNAMIC_DATASOURCE_KEY.get());
|
|
||||||
DYNAMIC_DATASOURCE_KEY.remove();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package com.muyu.cloud.common.many.datasource.role;
|
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动态数据源
|
|
||||||
* 调用AddDefineDataSource组件的addDefineDynamicDataSource()方法,获取原来targetdatasources的map,并将新的数据源信息添加到map中,并替换targetdatasources中的map
|
|
||||||
* 切换数据源时可以使用@DataSource(value = "数据源名称"),或者DynamicDataSourceContextHolder.setContextKey("数据源名称")
|
|
||||||
* @author Dongzl
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
@Slf4j
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class DynamicDataSource extends AbstractRoutingDataSource {
|
|
||||||
/**
|
|
||||||
* 备份所有数据源信息 备份的是个 指针 !!!
|
|
||||||
*/
|
|
||||||
private Map<Object, Object> defineTargetDataSources;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判定键是否出站了
|
|
||||||
* @param key 键
|
|
||||||
* @return 存在结果 true存在 false不存在
|
|
||||||
*/
|
|
||||||
public boolean hashKey(String key){
|
|
||||||
return defineTargetDataSources.containsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加数据库
|
|
||||||
* @param key 键
|
|
||||||
* @param value 数据源
|
|
||||||
*/
|
|
||||||
public void put(String key, DruidDataSource value) {
|
|
||||||
if (value!=null) {
|
|
||||||
defineTargetDataSources.put(key, value);
|
|
||||||
this.afterPropertiesSet();
|
|
||||||
}else{
|
|
||||||
log.warn("Key为 {} 的数据源为空!",key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 决定当前线程使用哪个数据源
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected Object determineCurrentLookupKey() {
|
|
||||||
return DynamicDataSourceHolder.getDynamicDataSourceKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Object> getKeys() {
|
|
||||||
return defineTargetDataSources.keySet().stream().toList();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package com.muyu.cloud.common.saas.contents;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: DongZeLiang
|
|
||||||
* @date: 2024/6/3
|
|
||||||
* @Description: SAAS常量
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
public class SaaSConstant {
|
|
||||||
|
|
||||||
public final static String SAAS_KEY = "ent-code";
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package com.muyu.cloud.common.saas.domain.model;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: DongZeLiang
|
|
||||||
* @date: 2024/6/3
|
|
||||||
* @Description: 企业信息
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class EntInfo {
|
|
||||||
|
|
||||||
private String entCode;
|
|
||||||
|
|
||||||
private String ip;
|
|
||||||
|
|
||||||
private Integer port;
|
|
||||||
|
|
||||||
private String dbName;
|
|
||||||
|
|
||||||
private String userName;
|
|
||||||
|
|
||||||
private String password;
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.muyu.cloud.common.saas.exception;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.core.exception.ServiceException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: DongZeLiang
|
|
||||||
* @date: 2024/6/3
|
|
||||||
* @Description: SaaS异常类
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
public class SaaSException extends ServiceException {
|
|
||||||
|
|
||||||
public SaaSException (String message, Integer code) {
|
|
||||||
super(message, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SaaSException (String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 空构造方法,避免反序列化问题
|
|
||||||
*/
|
|
||||||
public SaaSException () {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package com.muyu.cloud.common.saas.interceptor;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.muyu.cloud.common.saas.contents.SaaSConstant;
|
|
||||||
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
|
|
||||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
|
||||||
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
|
||||||
import com.muyu.common.core.context.SecurityContextHolder;
|
|
||||||
import com.muyu.common.core.utils.ServletUtils;
|
|
||||||
import com.muyu.common.core.utils.SpringUtils;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: DongZeLiang
|
|
||||||
* @date: 2024/6/3
|
|
||||||
* @Description: SAAS拦截器
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
public class SaaSInterceptor implements AsyncHandlerInterceptor {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 之前
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String saasKey = ServletUtils.getHeader(request, SaaSConstant.SAAS_KEY);
|
|
||||||
log.info("访问路径:{},携带SaaSKey:{}",request.getRequestURI(),saasKey);
|
|
||||||
if (saasKey == null) {
|
|
||||||
throw new SaaSException("SaaS非法访问");
|
|
||||||
}else {
|
|
||||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
|
||||||
if (!dynamicDataSource.hashKey(saasKey)){
|
|
||||||
throw new SaaSException("SaaS非法访问");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DynamicDataSourceHolder.setDynamicDataSourceKey(saasKey);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 之后
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void afterConcurrentHandlingStarted (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
DynamicDataSourceHolder.removeDynamicDataSourceKey();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package com.muyu.cloud.common.saas.interceptor;
|
|
||||||
|
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拦截器配置
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
public class WebMvcSaaSConfig implements WebMvcConfigurer {
|
|
||||||
/**
|
|
||||||
* 不需要拦截的地址
|
|
||||||
*/
|
|
||||||
public static final String[] EXCLUDE_URLS = {"/user/info", "/login", "/logout", "/refresh", "/realTime/getCarRealTime"};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addInterceptors (InterceptorRegistry registry) {
|
|
||||||
registry.addInterceptor(getHeaderInterceptor())
|
|
||||||
.addPathPatterns("/**")
|
|
||||||
.excludePathPatterns(EXCLUDE_URLS)
|
|
||||||
.order(-10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义请求头拦截器
|
|
||||||
*/
|
|
||||||
public SaaSInterceptor getHeaderInterceptor () {
|
|
||||||
return new SaaSInterceptor();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
com.muyu.cloud.common.saas.interceptor.WebMvcSaaSConfig
|
|
||||||
com.muyu.cloud.common.many.datasource.ManyDataSource
|
|
||||||
com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory
|
|
|
@ -15,13 +15,13 @@ import java.lang.annotation.*;
|
||||||
@Documented
|
@Documented
|
||||||
@EnableFeignClients
|
@EnableFeignClients
|
||||||
public @interface EnableMyFeignClients {
|
public @interface EnableMyFeignClients {
|
||||||
String[] value() default {};
|
String[] value () default {};
|
||||||
|
|
||||||
String[] basePackages() default {"com.muyu"};
|
String[] basePackages () default {"com.muyu"};
|
||||||
|
|
||||||
Class<?>[] basePackageClasses() default {};
|
Class<?>[] basePackageClasses () default {};
|
||||||
|
|
||||||
Class<?>[] defaultConfiguration() default {};
|
Class<?>[] defaultConfiguration () default {};
|
||||||
|
|
||||||
Class<?>[] clients() default {};
|
Class<?>[] clients () default {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,5 @@ public @interface InnerAuth {
|
||||||
/**
|
/**
|
||||||
* 是否校验用户信息
|
* 是否校验用户信息
|
||||||
*/
|
*/
|
||||||
boolean isUser() default false;
|
boolean isUser () default false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@ public @interface RequiresPermissions {
|
||||||
/**
|
/**
|
||||||
* 需要校验的权限码
|
* 需要校验的权限码
|
||||||
*/
|
*/
|
||||||
String[] value() default {};
|
String[] value () default {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证模式:AND | OR,默认AND
|
* 验证模式:AND | OR,默认AND
|
||||||
*/
|
*/
|
||||||
Logical logical() default Logical.AND;
|
Logical logical () default Logical.AND;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@ public @interface RequiresRoles {
|
||||||
/**
|
/**
|
||||||
* 需要校验的角色标识
|
* 需要校验的角色标识
|
||||||
*/
|
*/
|
||||||
String[] value() default {};
|
String[] value () default {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证逻辑:AND | OR,默认AND
|
* 验证逻辑:AND | OR,默认AND
|
||||||
*/
|
*/
|
||||||
Logical logical() default Logical.AND;
|
Logical logical () default Logical.AND;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,6 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
SecurityContextHolder.setUserId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USER_ID));
|
SecurityContextHolder.setUserId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USER_ID));
|
||||||
|
|
||||||
SecurityContextHolder.setSaasKey(ServletUtils.getHeader(request, SecurityConstants.SAAS_KEY));
|
|
||||||
|
|
||||||
|
|
||||||
SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME));
|
SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME));
|
||||||
SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY));
|
SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY));
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import javax.annotation.Resource;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
@ -34,7 +34,7 @@ public class TokenService {
|
||||||
private final static long expireTime = CacheConstants.EXPIRATION;
|
private final static long expireTime = CacheConstants.EXPIRATION;
|
||||||
|
|
||||||
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
||||||
@Resource
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,11 +55,10 @@ public class TokenService {
|
||||||
claimsMap.put(SecurityConstants.USER_KEY, token);
|
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||||
claimsMap.put(SecurityConstants.SAAS_KEY,loginUser.getSysUser().getFirmCode());
|
|
||||||
// 接口返回信息
|
// 接口返回信息
|
||||||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||||
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
||||||
rspMap.put("ent_code", loginUser.getSysUser().getFirmCode());
|
|
||||||
rspMap.put("expires_in", expireTime);
|
rspMap.put("expires_in", expireTime);
|
||||||
return rspMap;
|
return rspMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,6 @@ public class SecurityUtils {
|
||||||
return SecurityContextHolder.getUserName();
|
return SecurityContextHolder.getUserName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getSaasKey () {
|
|
||||||
return SecurityContextHolder.getSaasKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户key
|
* 获取用户key
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,9 +25,5 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-core</artifactId>
|
<artifactId>cloud-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-modules-openbusiness-common</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -63,9 +63,4 @@ public class LoginUser implements Serializable {
|
||||||
*/
|
*/
|
||||||
private SysUser sysUser;
|
private SysUser sysUser;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,6 @@ public class SysDept extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private Long parentId;
|
private Long parentId;
|
||||||
|
|
||||||
|
|
||||||
private String firmCode;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 祖级列表
|
* 祖级列表
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
package com.muyu.common.system.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: DongZeLiang
|
|
||||||
* @date: 2024/6/3
|
|
||||||
* @Description: 企业信息
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@TableName("sys_ent")
|
|
||||||
public class SysEnt {
|
|
||||||
@TableId( type = IdType.AUTO)
|
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
private String entCode;
|
|
||||||
|
|
||||||
private String ip;
|
|
||||||
|
|
||||||
private Integer port;
|
|
||||||
|
|
||||||
private String dbName;
|
|
||||||
|
|
||||||
private String userName;
|
|
||||||
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
package com.muyu.common.system.domain;
|
|
||||||
|
|
||||||
import com.muyu.common.core.annotation.Excel;
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
|
||||||
import lombok.*;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业基础信息对象 sys_firm
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
* @date 2024-09-18
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
@SuperBuilder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@TableName("sys_firm")
|
|
||||||
public class SysFirm extends BaseEntity{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/** 自增主键 */
|
|
||||||
@TableId( type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/** 统一社会信用代码 */
|
|
||||||
@Excel(name = "统一社会信用代码")
|
|
||||||
private String firmCreditCode;
|
|
||||||
|
|
||||||
/** 企业编码 */
|
|
||||||
@Excel(name = "企业编码")
|
|
||||||
private String firmCode;
|
|
||||||
|
|
||||||
/** 企业名称 */
|
|
||||||
@Excel(name = "企业名称")
|
|
||||||
private String firmName;
|
|
||||||
|
|
||||||
/** 企业logs */
|
|
||||||
@Excel(name = "企业logs")
|
|
||||||
private String firmLogs;
|
|
||||||
|
|
||||||
/** 启用状态(1.开业 2.停业 3.休业) */
|
|
||||||
@Excel(name = "启用状态(1.开业 2.停业 3.休业)")
|
|
||||||
private String state;
|
|
||||||
|
|
||||||
@Excel(name = "会员等级")
|
|
||||||
private Long memberId;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
|
||||||
.append("id", getId())
|
|
||||||
.append("firmCreditCode", getFirmCreditCode())
|
|
||||||
.append("firmCode", getFirmCode())
|
|
||||||
.append("firmName", getFirmName())
|
|
||||||
.append("firmLogs", getFirmLogs())
|
|
||||||
.append("state", getState())
|
|
||||||
.append("createBy", getCreateBy())
|
|
||||||
.append("createTime", getCreateTime())
|
|
||||||
.append("updateBy", getUpdateBy())
|
|
||||||
.append("updateTime", getUpdateTime())
|
|
||||||
.append("remark", getRemark())
|
|
||||||
.append("memberId", getMemberId())
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.muyu.common.system.domain;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author WangXin
|
|
||||||
* @Data 2024/9/18
|
|
||||||
* @Description 企业用户
|
|
||||||
* @Version 1.0.0
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
@SuperBuilder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class SysFirmUser extends SysUser {
|
|
||||||
/**
|
|
||||||
* 用户数据库
|
|
||||||
*/
|
|
||||||
private String databaseName;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package com.muyu.common.system.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.muyu.common.core.annotation.Excel;
|
|
||||||
import lombok.*;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 会员表(SysMember)实体类
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
@SuperBuilder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@TableName("sys_member")
|
|
||||||
public class SysMember {
|
|
||||||
@TableId(type = IdType.AUTO)
|
|
||||||
private Long memberId;
|
|
||||||
@Excel(name = "会员等级")
|
|
||||||
private String memberName;
|
|
||||||
@Excel(name = "可添加车辆数量")
|
|
||||||
private Integer memberCarNum;
|
|
||||||
@Excel(name = "可添加报文模板数量")
|
|
||||||
private Integer memberCarType;
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,11 +36,6 @@ public class SysRole extends BaseEntity {
|
||||||
@Excel(name = "角色名称")
|
@Excel(name = "角色名称")
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
|
||||||
|
|
||||||
private String firmCode;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色权限
|
* 角色权限
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package com.muyu.common.system.domain;
|
package com.muyu.common.system.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.muyu.common.core.annotation.Excel;
|
import com.muyu.common.core.annotation.Excel;
|
||||||
import com.muyu.common.core.annotation.Excel.ColumnType;
|
import com.muyu.common.core.annotation.Excel.ColumnType;
|
||||||
import com.muyu.common.core.annotation.Excel.Type;
|
import com.muyu.common.core.annotation.Excel.Type;
|
||||||
|
@ -31,7 +28,6 @@ import java.util.List;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName("sys_user")
|
|
||||||
public class SysUser extends BaseEntity {
|
public class SysUser extends BaseEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ -39,11 +35,8 @@ public class SysUser extends BaseEntity {
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
|
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
|
||||||
@TableId(type = IdType.AUTO)
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
private Integer isAdmin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门ID
|
* 部门ID
|
||||||
*/
|
*/
|
||||||
|
@ -56,9 +49,6 @@ public class SysUser extends BaseEntity {
|
||||||
@Excel(name = "登录名称")
|
@Excel(name = "登录名称")
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
|
|
||||||
private String firmCode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户昵称
|
* 用户昵称
|
||||||
*/
|
*/
|
||||||
|
@ -145,8 +135,6 @@ public class SysUser extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private Long roleId;
|
private Long roleId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public SysUser (Long userId) {
|
public SysUser (Long userId) {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
@ -155,9 +143,8 @@ public class SysUser extends BaseEntity {
|
||||||
return userId != null && 1L == userId;
|
return userId != null && 1L == userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isAdmin () {
|
public boolean isAdmin () {
|
||||||
return isAdmin(this.userId) || (this.isAdmin != null && this.isAdmin == 1);
|
return isAdmin(this.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Xss(message = "用户昵称不能包含脚本字符")
|
@Xss(message = "用户昵称不能包含脚本字符")
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.muyu.common.system.domain;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户和岗位关联 sys_user_post
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class SysUserPost {
|
|
||||||
/**
|
|
||||||
* 用户ID
|
|
||||||
*/
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 岗位ID
|
|
||||||
*/
|
|
||||||
private Long postId;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package com.muyu.common.system.domain;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户和角色关联 sys_user_role
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class SysUserRole {
|
|
||||||
/**
|
|
||||||
* 用户ID
|
|
||||||
*/
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色ID
|
|
||||||
*/
|
|
||||||
private Long roleId;
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.muyu.common.system.remote;
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.system.remote.factory.RemoteDataFallbackFactory;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据处理服务
|
|
||||||
*
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: RemoteDataService
|
|
||||||
* @Description: 数据处理服务
|
|
||||||
* @CreatedDate: 2024/10/10 下午6:25
|
|
||||||
* @FilePath: com.muyu.common.system.remote
|
|
||||||
*/
|
|
||||||
|
|
||||||
@FeignClient(contextId = "remoteDataService", value = ServiceNameConstants.DATA_SERVICE, fallbackFactory = RemoteDataFallbackFactory.class)
|
|
||||||
public interface RemoteDataService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆实时数据订阅开关
|
|
||||||
* @param vin 车辆vin码
|
|
||||||
* @param status 开关状态
|
|
||||||
* @return 返回结果
|
|
||||||
*/
|
|
||||||
@GetMapping("/DataProcessing/carRealTimeStatus")
|
|
||||||
public Result<String> carRealTimeStatus(@RequestParam("vin") @NonNull String vin, @RequestParam("status") @NonNull Boolean status);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
package com.muyu.common.system.remote;
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.SecurityConstants;
|
|
||||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.system.domain.SysUser;
|
|
||||||
import com.muyu.common.system.remote.factory.RemoteSaasFallbackFactory;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestHeader;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件服务
|
|
||||||
*
|
|
||||||
* @author muyu
|
|
||||||
*/
|
|
||||||
@FeignClient(contextId = "remoteSaasService", value = ServiceNameConstants.SAAS_SERVICE, fallbackFactory = RemoteSaasFallbackFactory.class)
|
|
||||||
public interface RemoteSaasService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过用户名查询用户信息
|
|
||||||
*
|
|
||||||
* @param firmCode
|
|
||||||
* @param userName 用户名
|
|
||||||
* @param source 请求来源
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@GetMapping("/user/info")
|
|
||||||
public Result<SysUser> getUserInfo (@RequestParam("firmCode") String firmCode, @RequestParam("userName") String userName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,23 +3,12 @@ package com.muyu.common.system.remote;
|
||||||
import com.muyu.common.core.constant.SecurityConstants;
|
import com.muyu.common.core.constant.SecurityConstants;
|
||||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
import com.muyu.common.system.domain.*;
|
|
||||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户服务
|
* 用户服务
|
||||||
*
|
*
|
||||||
|
@ -27,8 +16,6 @@ import org.springframework.web.bind.annotation.*;
|
||||||
*/
|
*/
|
||||||
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
|
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
|
||||||
public interface RemoteUserService {
|
public interface RemoteUserService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户信息
|
* 通过用户名查询用户信息
|
||||||
*
|
*
|
||||||
|
@ -40,7 +27,6 @@ public interface RemoteUserService {
|
||||||
@GetMapping("/user/info/{username}")
|
@GetMapping("/user/info/{username}")
|
||||||
public Result<LoginUser> getUserInfo (@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
public Result<LoginUser> getUserInfo (@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册用户信息
|
* 注册用户信息
|
||||||
*
|
*
|
||||||
|
@ -51,77 +37,4 @@ public interface RemoteUserService {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/user/register")
|
@PostMapping("/user/register")
|
||||||
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/user/companyList")
|
|
||||||
public Result<List<SysUser>> companyList ();
|
|
||||||
|
|
||||||
@PostMapping("/ent/list")
|
|
||||||
public Result<List<SysEnt>> list (@RequestBody SysEnt sysEnt);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过用户名查询用户信息
|
|
||||||
*
|
|
||||||
* @param firmCode
|
|
||||||
* @param userName 用户名
|
|
||||||
* @param source 请求来源
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@GetMapping("/user/info")
|
|
||||||
public Result<LoginUser> getUserInfo (@RequestParam("firmCode") String firmCode, @RequestParam("userName") String userName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取角色数据权限
|
|
||||||
*
|
|
||||||
* @param user 用户
|
|
||||||
*
|
|
||||||
* @return 角色权限信息
|
|
||||||
*/
|
|
||||||
@PostMapping("/permission/getRole")
|
|
||||||
public Set<String> getRolePermission (@RequestBody SysUser user);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取菜单数据权限
|
|
||||||
*
|
|
||||||
* @param user 用户
|
|
||||||
*
|
|
||||||
* @return 菜单权限信息
|
|
||||||
*/
|
|
||||||
@PostMapping("/permission/getMenu")
|
|
||||||
public Set<String> getMenuPermission (@RequestBody SysUser user);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据部门编号获取详细信息
|
|
||||||
*/
|
|
||||||
@GetMapping(value = "/dept/{deptId}")
|
|
||||||
public Result<SysDept> selectDeptById (@PathVariable("deptId") Long deptId);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增用户角色信息
|
|
||||||
*
|
|
||||||
* @param user 用户对象
|
|
||||||
*/
|
|
||||||
@PostMapping("/user/insertUserRole")
|
|
||||||
public void insertUserRole (@RequestBody SysUser user);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增用户岗位信息
|
|
||||||
*
|
|
||||||
* @param user 用户对象
|
|
||||||
*/
|
|
||||||
@PostMapping("/user/insertUserPost")
|
|
||||||
public void insertUserPost (@RequestBody SysUser user);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册用户
|
|
||||||
*/
|
|
||||||
@PostMapping("/user")
|
|
||||||
public Result addUser (@RequestBody SysUser user);
|
|
||||||
|
|
||||||
@GetMapping("/member/memberId/{firmCode}")
|
|
||||||
public Result<SysMember> selectSysMemberListById(@PathVariable("firmCode") String firmCode);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.muyu.common.system.remote.factory;
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.system.remote.RemoteDataService;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据处理访问熔断器
|
|
||||||
*
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: RemoteDataFallbackFactory
|
|
||||||
* @Description: 数据处理访问熔断器
|
|
||||||
* @CreatedDate: 2024/10/10 下午6:26
|
|
||||||
* @FilePath: com.muyu.common.system.remote.factory
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class RemoteDataFallbackFactory implements FallbackFactory<RemoteDataService> {
|
|
||||||
@Override
|
|
||||||
public RemoteDataService create(Throwable cause) {
|
|
||||||
return new RemoteDataService() {
|
|
||||||
@Override
|
|
||||||
public Result<String> carRealTimeStatus(@NonNull String vin, @NonNull Boolean status) {
|
|
||||||
return Result.error("远程调用错误");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
package com.muyu.common.system.remote.factory;
|
|
||||||
/**
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: RemoteEntFallbackFactory
|
|
||||||
* @Description:
|
|
||||||
* @CreatedDate: 2024/9/20 下午3:11
|
|
||||||
* @FilePath: com.muyu.common.system.remote
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.system.domain.SysUser;
|
|
||||||
import com.muyu.common.system.remote.RemoteSaasService;
|
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: 胡杨
|
|
||||||
* @Name: RemoteEntFallbackFactory
|
|
||||||
* @Description:
|
|
||||||
* @CreatedDate: 2024/9/20 下午3:11
|
|
||||||
* @FilePath: com.muyu.common.system.remote
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class RemoteSaasFallbackFactory implements FallbackFactory<RemoteSaasService> {
|
|
||||||
@Override
|
|
||||||
public RemoteSaasService create(Throwable cause) {
|
|
||||||
return new RemoteSaasService() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<SysUser> getUserInfo(String firmCode, String username, String source) {
|
|
||||||
return Result.error("获取用户失败:" + cause.getMessage());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +1,14 @@
|
||||||
package com.muyu.common.system.remote.factory;
|
package com.muyu.common.system.remote.factory;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
|
||||||
import com.muyu.common.system.domain.*;
|
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
|
||||||
|
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
import com.muyu.common.system.remote.RemoteUserService;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
|
|
||||||
import com.muyu.openbusiness.domain.SysCarMessage;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户服务降级处理
|
* 用户服务降级处理
|
||||||
*
|
*
|
||||||
|
@ -35,68 +22,15 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
||||||
public RemoteUserService create (Throwable throwable) {
|
public RemoteUserService create (Throwable throwable) {
|
||||||
log.error("用户服务调用失败:{}", throwable.getMessage());
|
log.error("用户服务调用失败:{}", throwable.getMessage());
|
||||||
return new RemoteUserService() {
|
return new RemoteUserService() {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<LoginUser> getUserInfo (String username, String source) {
|
public Result<LoginUser> getUserInfo (String username, String source) {
|
||||||
return Result.error("获取用户失败:" + throwable.getMessage());
|
return Result.error("获取用户失败:" + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
||||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public Result<List<SysUser>> companyList() {
|
|
||||||
return Result.error("获取企业列表失败:" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<List<SysEnt>> list(SysEnt sysEnt) {
|
|
||||||
return Result.error("获取企业列表失败:" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<LoginUser> getUserInfo(String firmCode, String userName, String source) {
|
|
||||||
return Result.error("获取用户信息失败:" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getRolePermission(SysUser user) {
|
|
||||||
return Set.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getMenuPermission(SysUser user) {
|
|
||||||
return Set.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<SysDept> selectDeptById(Long deptId) {
|
|
||||||
return Result.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertUserRole(SysUser user) {
|
|
||||||
log.warn("新增用户角色失败!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertUserPost(SysUser user) {
|
|
||||||
log.warn("新增用户权限失败!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result addUser(SysUser user) {
|
|
||||||
return Result.error(throwable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<SysMember> selectSysMemberListById(String firmCode) {
|
|
||||||
return Result.error();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
||||||
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
||||||
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
||||||
com.muyu.common.system.remote.factory.RemoteDataFallbackFactory
|
|
||||||
com.muyu.common.system.remote.factory.RemoteSaasFallbackFactory
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,6 @@
|
||||||
<module>cloud-common-system</module>
|
<module>cloud-common-system</module>
|
||||||
<module>cloud-common-xxl</module>
|
<module>cloud-common-xxl</module>
|
||||||
<module>cloud-common-rabbit</module>
|
<module>cloud-common-rabbit</module>
|
||||||
<module>cloud-common-saas</module>
|
|
||||||
<module>cloud-common-cache</module>
|
|
||||||
<module>cloud-common-caffeine</module>
|
|
||||||
<module>cloud-common-iotdb</module>
|
|
||||||
<module>cloud-common-kafka</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-common</artifactId>
|
<artifactId>cloud-common</artifactId>
|
||||||
|
@ -35,4 +30,3 @@
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,6 @@
|
||||||
<version>4.5.0</version>
|
<version>4.5.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -13,9 +13,5 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
public class CloudGatewayApplication {
|
public class CloudGatewayApplication {
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
SpringApplication.run(CloudGatewayApplication.class, args);
|
SpringApplication.run(CloudGatewayApplication.class, args);
|
||||||
|
|
||||||
System.out.println("CloudGateway 模块启动成功!");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue