Compare commits
No commits in common. "master" and "dev.protocol.parsing" have entirely different histories.
master
...
dev.protoc
|
@ -16,23 +16,10 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!-- 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>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.muyu</groupId>-->
|
||||
<!-- <artifactId>cloud-common-saas</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
|
@ -58,6 +45,48 @@
|
|||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</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>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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 org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
@ -10,10 +13,18 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
@SpringBootApplication(
|
||||
exclude = {
|
||||
DataSourceAutoConfiguration.class,
|
||||
DruidDataSourceAutoConfigure.class,
|
||||
DynamicDataSourceAutoConfiguration.class
|
||||
}
|
||||
)
|
||||
public class CloudAuthApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(CloudAuthApplication.class, args);
|
||||
System.out.println("CloudAuth 模块启动成功!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.muyu.common.security.auth.AuthUtil;
|
|||
import com.muyu.common.security.service.TokenService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -25,16 +25,16 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
*/
|
||||
@RestController
|
||||
public class TokenController {
|
||||
@Autowired
|
||||
@Resource
|
||||
private TokenService tokenService;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysLoginService sysLoginService;
|
||||
|
||||
@PostMapping("login")
|
||||
public Result<?> login (@RequestBody LoginBody form) {
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||
LoginUser userInfo = sysLoginService.login(form);
|
||||
// 获取登录token
|
||||
return Result.success(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package com.muyu.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户登录对象
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@Data
|
||||
public class LoginBody {
|
||||
|
||||
private String firmCode;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
@ -15,20 +20,4 @@ public class LoginBody {
|
|||
* 用户密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
public String getUsername () {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername (String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword () {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword (String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.auth.service;
|
||||
|
||||
import com.muyu.auth.form.LoginBody;
|
||||
import com.muyu.common.core.constant.CacheConstants;
|
||||
import com.muyu.common.core.constant.Constants;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
|
@ -12,12 +13,16 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.ip.IpUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.remote.RemoteSaasService;
|
||||
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 javax.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
*
|
||||
|
@ -25,24 +30,30 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Component
|
||||
public class SysLoginService {
|
||||
@Autowired
|
||||
@Resource
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysPasswordService passwordService;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysRecordLogService recordLogService;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Resource
|
||||
private RemoteSaasService remoteSaasService;
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public LoginUser login (String username, String password) {
|
||||
public LoginUser login (LoginBody form) {
|
||||
String firmCode = form.getFirmCode();
|
||||
String username = form.getUsername();
|
||||
String password = form.getPassword();
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password)) {
|
||||
if (StringUtils.isAnyBlank(firmCode, username, password)) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
||||
throw new ServiceException("用户/密码必须填写");
|
||||
}
|
||||
|
@ -65,8 +76,7 @@ public class SysLoginService {
|
|||
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
||||
}
|
||||
// 查询用户信息
|
||||
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
|
||||
Result<LoginUser> userResult = remoteUserService.getUserInfo(firmCode, username, SecurityConstants.INNER);
|
||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||
|
@ -76,8 +86,8 @@ public class SysLoginService {
|
|||
throw new ServiceException(userResult.getMsg());
|
||||
}
|
||||
|
||||
LoginUser userInfo = userResult.getData();
|
||||
SysUser user = userResult.getData().getSysUser();
|
||||
LoginUser loginUser = userResult.getData();
|
||||
SysUser user = loginUser.getSysUser();
|
||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
||||
|
@ -88,7 +98,8 @@ public class SysLoginService {
|
|||
}
|
||||
passwordService.validate(user, password);
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
return userInfo;
|
||||
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
public void logout (String loginName) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.muyu.common.core.exception.ServiceException;
|
|||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -18,14 +18,14 @@ import java.util.concurrent.TimeUnit;
|
|||
*/
|
||||
@Component
|
||||
public class SysPasswordService {
|
||||
@Autowired
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
private int maxRetryCount = CacheConstants.PASSWORD_MAX_RETRY_COUNT;
|
||||
|
||||
private Long lockTime = CacheConstants.PASSWORD_LOCK_TIME;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private SysRecordLogService recordLogService;
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.ip.IpUtils;
|
||||
import com.muyu.common.system.remote.RemoteLogService;
|
||||
import com.muyu.common.system.domain.SysLogininfor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Component
|
||||
public class SysRecordLogService {
|
||||
@Autowired
|
||||
@Resource
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,10 +4,10 @@ server:
|
|||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: nacos.muyu.icu:8848
|
||||
addr: 47.116.173.119:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: muyu-cloud
|
||||
namespace: one-saas
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
@ -40,8 +40,8 @@ spring:
|
|||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统环境Config共享配置
|
||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?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>
|
||||
|
||||
<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>
|
||||
<version>2.9.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,98 @@
|
|||
package com.muyu.common.caffeine;
|
||||
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.muyu.common.caffeine.constents.CaffeineContent;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.cache.caffeine.CaffeineCache;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: CaffeineUtils
|
||||
* @Description: 缓存工具类
|
||||
* @CreatedDate: 2024/9/26 下午2:53
|
||||
* @FilePath: com.muyu.common.caffeine
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CaffeineCacheUtils {
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@Resource
|
||||
private SimpleCacheManager simpleCacheManager;
|
||||
|
||||
|
||||
/**
|
||||
* 车辆上线 - 新增缓存
|
||||
*/
|
||||
public void addCarCache(String vin) {
|
||||
ArrayList<CaffeineCache> caches = new ArrayList<>();
|
||||
// 从Redis中获取缓存信息
|
||||
Map<String,Object> cacheMap = redisService.getCacheMap(CaffeineContent.CAR_VIN_KEY +vin);
|
||||
cacheMap.forEach((key, value) -> {
|
||||
Cache<Object , Object> cache = Caffeine.newBuilder().build();
|
||||
cache.put(key, value);
|
||||
// 全部存储到 CaffeineCache集合
|
||||
caches.add(new CaffeineCache(vin, cache));
|
||||
});
|
||||
simpleCacheManager.setCaches(caches);
|
||||
log.info("车辆编码:{},本地缓存完成...",vin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆下线 - 删除缓存
|
||||
*/
|
||||
public void deleteCarCache(String vin) {
|
||||
if (hasCarVinCache(vin)) {
|
||||
log.warn("车辆编码:{},本地缓存不存在该车辆信息...", vin);
|
||||
return;
|
||||
}
|
||||
simpleCacheManager.getCache(vin).invalidate();
|
||||
log.info("车辆编码:{},本地缓存删除完成...", vin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆信息缓存
|
||||
*/
|
||||
public Object getCarCache(String vin, String key) {
|
||||
if (hasCarVinKeyCache(vin, key)){
|
||||
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",vin);
|
||||
return null;
|
||||
}
|
||||
return simpleCacheManager.getCache(vin).get(key).get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆信息缓存
|
||||
*/
|
||||
public <T> T getCarCache(String vin, String key, Class<T> type) {
|
||||
if (hasCarVinKeyCache(vin,key)){
|
||||
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",vin);
|
||||
return null;
|
||||
}
|
||||
return simpleCacheManager.getCache(vin).get(key, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断缓存存在与否
|
||||
*/
|
||||
public Boolean hasCarVinCache(String vin) {
|
||||
return ObjectUtils.isNotEmpty(simpleCacheManager.getCache(vin));
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断缓存的Key存在与否
|
||||
*/
|
||||
public Boolean hasCarVinKeyCache(String vin,String key) {
|
||||
return hasCarVinCache(vin) && ObjectUtils.isNotEmpty(simpleCacheManager.getCache(vin).get(key).get());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.common.caffeine.bean;
|
||||
|
||||
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: CaffeineCacheConfig
|
||||
* @Description: Caffeine管理器
|
||||
* @CreatedDate: 2024/9/26 上午11:52
|
||||
* @FilePath: com.muyu.common.caffeine.config
|
||||
*/
|
||||
@Component
|
||||
public class CaffeineManagerBean {
|
||||
|
||||
/**
|
||||
* 创建缓存管理器
|
||||
* @return 缓存管理器实例
|
||||
*/
|
||||
@Bean
|
||||
public SimpleCacheManager simpleCacheManager() {
|
||||
return new SimpleCacheManager();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.common.caffeine.constents;
|
||||
|
||||
/**
|
||||
* @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";
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
com.muyu.common.caffeine.bean.CaffeineManagerBean
|
|
@ -16,6 +16,11 @@
|
|||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.4.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Openfeign -->
|
||||
<dependency>
|
||||
|
|
|
@ -45,4 +45,9 @@ public class SecurityConstants {
|
|||
* 角色权限
|
||||
*/
|
||||
public static final String ROLE_PERMISSION = "role_permission";
|
||||
|
||||
/**
|
||||
* SAAS请求头的key
|
||||
*/
|
||||
public static final String SAAS_KEY = "ent-code";
|
||||
}
|
||||
|
|
|
@ -20,4 +20,13 @@ public class ServiceNameConstants {
|
|||
* 文件服务的serviceid
|
||||
*/
|
||||
public static final String FILE_SERVICE = "cloud-file";
|
||||
|
||||
/**
|
||||
* 智能车联服务
|
||||
*/
|
||||
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";
|
||||
}
|
||||
|
|
|
@ -80,4 +80,12 @@ public class SecurityContextHolder {
|
|||
public static void remove () {
|
||||
THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
public static String getSaasKey() {
|
||||
return get(SecurityConstants.SAAS_KEY);
|
||||
}
|
||||
public static void setSaasKey(String saasKey) {
|
||||
set(SecurityConstants.SAAS_KEY,saasKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ package com.muyu.common.core.exception;
|
|||
*
|
||||
* @author muyu
|
||||
*/
|
||||
public final class ServiceException extends RuntimeException {
|
||||
public class ServiceException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ public final class ServiceException extends RuntimeException {
|
|||
/**
|
||||
* 错误明细,内部调试错误
|
||||
* <p>
|
||||
* 和 {@link CommonResult#getDetailMessage()} 一致的设计
|
||||
* 和 {CommonResult#getDetailMessage()} 一致的设计
|
||||
*/
|
||||
private String detailMessage;
|
||||
|
||||
|
|
|
@ -162,4 +162,15 @@ public class JwtUtils {
|
|||
public static String getValue (Claims claims, String 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?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>
|
||||
|
||||
<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>
|
|
@ -0,0 +1,54 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
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_topic";
|
||||
|
||||
public final static String KafkaGrop = "kafka_grop";
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
com.muyu.common.kafka.config.KafkaConsumerConfig
|
||||
com.muyu.common.kafka.config.KafkaProviderConfig
|
|
@ -18,7 +18,7 @@ import org.aspectj.lang.annotation.Aspect;
|
|||
import org.aspectj.lang.annotation.Before;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -48,7 +48,7 @@ public class LogAspect {
|
|||
*/
|
||||
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private AsyncLogService asyncLogService;
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.muyu.common.log.service;
|
|||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
import com.muyu.common.system.remote.RemoteLogService;
|
||||
import com.muyu.common.system.domain.SysOperLog;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -14,7 +14,7 @@ import org.springframework.stereotype.Service;
|
|||
*/
|
||||
@Service
|
||||
public class AsyncLogService {
|
||||
@Autowired
|
||||
@Resource
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.muyu.common.rabbit;
|
|||
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||
|
@ -16,7 +16,7 @@ public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit
|
|||
}
|
||||
|
||||
//以下配置RabbitMQ消息服务
|
||||
@Autowired
|
||||
@Resource
|
||||
public ConnectionFactory connectionFactory;
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.muyu.common.redis.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.data.redis.core.BoundSetOperations;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
|
|||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||
@Component
|
||||
public class RedisService {
|
||||
@Autowired
|
||||
@Resource
|
||||
public RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?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>
|
||||
|
||||
<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>
|
|
@ -0,0 +1,105 @@
|
|||
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)
|
||||
.forEach(dataSourceInfo -> {
|
||||
dataSourceMap.put(dataSourceInfo.getKey(), druidDataSourceFactory.create(dataSourceInfo));
|
||||
});
|
||||
//设置动态数据源
|
||||
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();
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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 = "127.0.0.1";
|
||||
|
||||
public final static Integer PORT = 3306;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.muyu.cloud.common.many.datasource.factory;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
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.setUrl(dataSourceInfo.getUrl());
|
||||
druidDataSource.setConnectTimeout(10000);
|
||||
druidDataSource.setUsername(dataSourceInfo.getUserName());
|
||||
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
||||
druidDataSource.setBreakAfterAcquireFailure(true);
|
||||
druidDataSource.setConnectionErrorRetryAttempts(0);
|
||||
try {
|
||||
druidDataSource.getConnection(2000);
|
||||
log.info("{} -> 数据源连接成功", dataSourceInfo.getKey());
|
||||
return druidDataSource;
|
||||
} catch (SQLException throwables) {
|
||||
log.error("数据源 {} 连接失败,用户名:{},密码 {}, 原因:{}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword(), throwables);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
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";
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
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"};
|
||||
|
||||
@Override
|
||||
public void addInterceptors (InterceptorRegistry registry) {
|
||||
registry.addInterceptor(getHeaderInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(EXCLUDE_URLS)
|
||||
.order(-10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义请求头拦截器
|
||||
*/
|
||||
public SaaSInterceptor getHeaderInterceptor () {
|
||||
return new SaaSInterceptor();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
com.muyu.cloud.common.saas.interceptor.WebMvcSaaSConfig
|
||||
com.muyu.cloud.common.many.datasource.ManyDataSource
|
||||
com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory
|
|
@ -28,6 +28,7 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor {
|
|||
}
|
||||
|
||||
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.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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -34,7 +34,7 @@ public class TokenService {
|
|||
private final static long expireTime = CacheConstants.EXPIRATION;
|
||||
|
||||
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
|
||||
@Autowired
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
|
@ -55,10 +55,11 @@ public class TokenService {
|
|||
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||
|
||||
claimsMap.put(SecurityConstants.SAAS_KEY,loginUser.getSysUser().getFirmCode());
|
||||
// 接口返回信息
|
||||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
||||
rspMap.put("ent_code", loginUser.getSysUser().getFirmCode());
|
||||
rspMap.put("expires_in", expireTime);
|
||||
return rspMap;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ public class SecurityUtils {
|
|||
return SecurityContextHolder.getUserName();
|
||||
}
|
||||
|
||||
public static String getSaasKey () {
|
||||
return SecurityContextHolder.getSaasKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户key
|
||||
*/
|
||||
|
|
|
@ -63,4 +63,6 @@ public class LoginUser implements Serializable {
|
|||
*/
|
||||
private SysUser sysUser;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ public class SysDept extends BaseEntity {
|
|||
*/
|
||||
private Long parentId;
|
||||
|
||||
private String firmCode;
|
||||
|
||||
/**
|
||||
* 祖级列表
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
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;
|
||||
}
|
|
@ -36,6 +36,8 @@ public class SysRole extends BaseEntity {
|
|||
@Excel(name = "角色名称")
|
||||
private String roleName;
|
||||
|
||||
private String firmCode;
|
||||
|
||||
/**
|
||||
* 角色权限
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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.ColumnType;
|
||||
import com.muyu.common.core.annotation.Excel.Type;
|
||||
|
@ -28,6 +31,7 @@ import java.util.List;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_user")
|
||||
public class SysUser extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
@ -35,8 +39,11 @@ public class SysUser extends BaseEntity {
|
|||
* 用户ID
|
||||
*/
|
||||
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long userId;
|
||||
|
||||
private Integer isAdmin;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
|
@ -49,6 +56,9 @@ public class SysUser extends BaseEntity {
|
|||
@Excel(name = "登录名称")
|
||||
private String userName;
|
||||
|
||||
|
||||
private String firmCode;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
|
@ -135,6 +145,8 @@ public class SysUser extends BaseEntity {
|
|||
*/
|
||||
private Long roleId;
|
||||
|
||||
|
||||
|
||||
public SysUser (Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
@ -143,8 +155,9 @@ public class SysUser extends BaseEntity {
|
|||
return userId != null && 1L == userId;
|
||||
}
|
||||
|
||||
|
||||
public boolean isAdmin () {
|
||||
return isAdmin(this.userId);
|
||||
return isAdmin(this.userId) || (this.isAdmin != null && this.isAdmin == 1);
|
||||
}
|
||||
|
||||
@Xss(message = "用户昵称不能包含脚本字符")
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
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;
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
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,12 +3,14 @@ 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.domain.*;
|
||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
|
@ -16,16 +18,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
*/
|
||||
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
|
||||
public interface RemoteUserService {
|
||||
/**
|
||||
* 通过用户名查询用户信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param source 请求来源
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/user/info/{username}")
|
||||
public Result<LoginUser> getUserInfo (@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 注册用户信息
|
||||
|
@ -37,4 +29,73 @@ public interface RemoteUserService {
|
|||
*/
|
||||
@PostMapping("/user/register")
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
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,14 +1,17 @@
|
|||
package com.muyu.common.system.remote.factory;
|
||||
|
||||
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.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
|
@ -22,15 +25,57 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
public RemoteUserService create (Throwable throwable) {
|
||||
log.error("用户服务调用失败:{}", throwable.getMessage());
|
||||
return new RemoteUserService() {
|
||||
@Override
|
||||
public Result<LoginUser> getUserInfo (String username, String source) {
|
||||
return Result.error("获取用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteSaasFallbackFactory
|
||||
|
|
|
@ -7,9 +7,9 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Log4j2
|
||||
@Component
|
||||
//@Component
|
||||
public class XXLJobConfig {
|
||||
@Bean
|
||||
// @Bean
|
||||
public XxlJobSpringExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties) {
|
||||
if (StringUtils.isEmpty(xxlJobProperties.getAdminAddresses())){
|
||||
throw new RuntimeException("请在bootstrap.yml当中配置shared-configs项,xxl-job共享配置[application-xxl-config]");
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
<module>cloud-common-system</module>
|
||||
<module>cloud-common-xxl</module>
|
||||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-saas</module>
|
||||
<module>cloud-common-caffeine</module>
|
||||
<module>cloud-common-kafka</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
<?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-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-data-processing</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-data-processing 数据处理模块
|
||||
</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-kafka</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-caffeine</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</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>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-jdbc</artifactId>
|
||||
<version>0.12.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.1.9</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis-spring</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– Druid –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba</groupId>-->
|
||||
<!-- <artifactId>druid-spring-boot-3-starter</artifactId>-->
|
||||
<!-- <version>${druid.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- <!– Dynamic DataSource –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.baomidou</groupId>-->
|
||||
<!-- <artifactId>dynamic-datasource-spring-boot3-starter</artifactId>-->
|
||||
<!-- <version>${dynamic-ds.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.data.processing;
|
||||
|
||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: MyData
|
||||
* @Description: 数据处理模块启动器
|
||||
* @CreatedDate: 2024/9/26 下午7:31
|
||||
* @FilePath: com.muyu.data.processing
|
||||
*/
|
||||
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class MyDataApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MyDataApplication.class, args);
|
||||
|
||||
System.out.println("MyData 模块启动成功!");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
package com.muyu.data.processing.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.data.processing.domain.IotDbData;
|
||||
import com.muyu.data.processing.service.DataProcessingService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据处理控制层
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: DataProcessing
|
||||
* @Description: 数据处理控制层
|
||||
* @CreatedDate: 2024/9/28 下午3:53
|
||||
* @FilePath: com.muyu.data.processing.controller
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/DataProcessing")
|
||||
public class DataProcessingController {
|
||||
@Resource
|
||||
private DataProcessingService service;
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/createCarData", method = RequestMethod.POST)
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
public Result createCarData(@RequestBody IotDbData data) {
|
||||
try {
|
||||
data.setTimestamp(System.currentTimeMillis());
|
||||
data.setCreateTime(new Date());
|
||||
Integer v = service.createCarData(data);
|
||||
if (v == -1) {
|
||||
return Result.success(v);
|
||||
} else {
|
||||
return Result.error(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("创建车辆报文记录失败!" + e);
|
||||
return Result.error(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新操作 其实也是插入操作 时间戳相同 只和时间戳相关
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/updateCarData", method = RequestMethod.POST)
|
||||
public Result updateCarData(@RequestBody IotDbData data) {
|
||||
try {
|
||||
data.setTimestamp(System.currentTimeMillis());
|
||||
data.setCreateTime(new Date());
|
||||
Integer v = service.updateCarData(data);
|
||||
if (v == -1) {
|
||||
return Result.success(v);
|
||||
} else {
|
||||
return Result.error(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("更新车辆报文记录失败!" + e);
|
||||
return Result.error(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除操作 要将时间戳的加号变成%2B
|
||||
* @param timestamp
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/deleteCarData", method = RequestMethod.GET)
|
||||
public Result deleteCarData(String timestamp) {
|
||||
try {
|
||||
Integer v = service.deleteCarData(timestamp);
|
||||
if (v == -1) {
|
||||
return Result.success(v);
|
||||
} else {
|
||||
return Result.error(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("删除车辆报文记录失败!" + e);
|
||||
return Result.error(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建组 也就是相当于数据库
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/createCarDataGroup", method = RequestMethod.POST)
|
||||
public Result createCarDataGroup() {
|
||||
try {
|
||||
Integer v = service.createCarDataGroup();
|
||||
if (v > 0) {
|
||||
return Result.success(v);
|
||||
} else {
|
||||
return Result.error(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("创建车辆报文记录组失败!" + e);
|
||||
return Result.error(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有车辆报文记录数据
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/queryCarData", method = RequestMethod.GET)
|
||||
public Result queryCarData() {
|
||||
try {
|
||||
List<IotDbData> v = service.queryCarData();
|
||||
if (v.size() > 0) {
|
||||
v.forEach(x -> {
|
||||
System.out.println(x.toString());
|
||||
});
|
||||
return Result.success(v);
|
||||
} else {
|
||||
return Result.error(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("查询车辆报文记录组失败!" + e);
|
||||
return Result.error(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看数据库有多少组
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/selectStorageGroup", method = RequestMethod.GET)
|
||||
public Result selectStorageGroup() {
|
||||
try {
|
||||
List<String> v = service.selectStorageGroup();
|
||||
if (v.size() > 0) {
|
||||
v.forEach(x -> {
|
||||
System.out.println("group------------------" + x.toString());
|
||||
});
|
||||
return Result.success(v);
|
||||
} else {
|
||||
return Result.error(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("查询组失败!" + e);
|
||||
return Result.error(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.muyu.data.processing.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||
import com.muyu.data.processing.domain.IotDbData;
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.root.RootStrategy;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 测试控制层
|
||||
* @Author: 胡杨
|
||||
* @Name: Test
|
||||
* @Description:
|
||||
* @CreatedDate: 2024/9/27 上午10:54
|
||||
* @FilePath: com.muyu.data.processing.controller
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/Test")
|
||||
public class TestController {
|
||||
@Resource
|
||||
private KafkaProducer<String,String> kafkaProducer;
|
||||
|
||||
@GetMapping("/testKafka")
|
||||
public void sendMsg(@RequestParam("msg") String msg) {
|
||||
try {
|
||||
IotDbData iotDbData = IotDbData.builder()
|
||||
.timestamp(System.currentTimeMillis())
|
||||
.vin("vin666")
|
||||
.key("test")
|
||||
.label("测试数据")
|
||||
.value("Kafka测试")
|
||||
.type("String")
|
||||
.build();
|
||||
String jsonString = JSONObject.toJSONString(iotDbData);
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>(KafkaConstants.KafkaTopic, jsonString);
|
||||
kafkaProducer.send(producerRecord);
|
||||
System.out.println("同步消息发送成功: " + msg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("同步消息发送失败: " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
private RootStrategy rootStrategy;
|
||||
|
||||
@PostMapping("/testStrategy")
|
||||
public TestResp testStrategy(@RequestBody TestReq testReq) {
|
||||
return rootStrategy.applyStrategy(testReq);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.data.processing.domain;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 报文信息 时序实体类
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: DataProcessing
|
||||
* @Description: 报文信息 时序实体类
|
||||
* @CreatedDate: 2024/9/28 下午3:48
|
||||
* @FilePath: com.muyu.data.processing.domain
|
||||
*/
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@ToString
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IotDbData extends BaseEntity {
|
||||
private long timestamp;
|
||||
|
||||
private String vin;
|
||||
|
||||
private String key;
|
||||
private String label;
|
||||
private String value;
|
||||
private String type;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.data.processing.domain;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 报文信息 时序实体类
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: DataProcessing
|
||||
* @Description: 报文信息 时序实体类
|
||||
* @CreatedDate: 2024/9/28 下午3:48
|
||||
* @FilePath: com.muyu.data.processing.domain
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class KafkaData implements Serializable {
|
||||
|
||||
private String key;
|
||||
private String label;
|
||||
private String value;
|
||||
private String type;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.muyu.data.processing.domain;
|
||||
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import com.muyu.data.processing.strategy.branch.OneBranchStrategy;
|
||||
import com.muyu.data.processing.strategy.branch.TwoBranchStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.FourLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.OneLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.ThreeLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.TwoLeavesStrategy;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 策略选择枚举
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: StrategyEums
|
||||
* @Description: 策略选择枚举
|
||||
* @CreatedDate: 2024/9/28 上午11:59
|
||||
* @FilePath: com.muyu.data.processing.domain
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public enum StrategyEums {
|
||||
TEST1("加减法", new OneBranchStrategy()),
|
||||
TEST2("乘除法", new TwoBranchStrategy()),
|
||||
TEST1_1("加法", new OneLeavesStrategy()),
|
||||
TEST1_2("减法", new TwoLeavesStrategy()),
|
||||
TEST2_1("乘法", new ThreeLeavesStrategy()),
|
||||
TEST2_2("除法", new FourLeavesStrategy());
|
||||
|
||||
private final String code;
|
||||
private final StrategyHandler<TestReq, TestResp> info;
|
||||
|
||||
StrategyEums(String code, StrategyHandler<TestReq, TestResp> info) {
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 鉴别参数是否是枚举的值
|
||||
*
|
||||
* @param code 需鉴别参数
|
||||
* @return 如果存在返回结果turn, 否则返回false
|
||||
*/
|
||||
public static boolean isCode(String code) {
|
||||
return Arrays.stream(values())
|
||||
.map(StrategyEums::getCode)
|
||||
.anyMatch(c -> c.equals(code));
|
||||
}
|
||||
|
||||
public static StrategyHandler<TestReq, TestResp> getStrategy(String code) {
|
||||
return Arrays.stream(values())
|
||||
.filter(c -> c.getCode().equals(code))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("参数错误"))
|
||||
.getInfo();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.data.processing.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 测试入参
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: TestReq
|
||||
* @Description: 测试入参
|
||||
* @CreatedDate: 2024/9/28 上午10:40
|
||||
* @FilePath: com.muyu.data.processing.domain.req
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TestReq {
|
||||
private Integer one;
|
||||
private Integer two;
|
||||
|
||||
private String type1;
|
||||
private String type2;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.data.processing.domain.resp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 测试出参
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: TestResp
|
||||
* @Description: 测试出参
|
||||
* @CreatedDate: 2024/9/28 上午10:40
|
||||
* @FilePath: com.muyu.data.processing.domain.req.resp
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TestResp {
|
||||
private String resp;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.muyu.data.processing.kafka;
|
||||
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
|
||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||
import com.muyu.data.processing.domain.IotDbData;
|
||||
import com.muyu.data.processing.domain.KafkaData;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: KafkaConsumerService
|
||||
* @Description: kafka消费者
|
||||
* @CreatedDate: 2024/9/27 上午9:27
|
||||
* @FilePath: com.muyu.data.processing.kafka
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class KafkaConsumerService implements InitializingBean {
|
||||
@Resource
|
||||
private KafkaConsumer kafkaConsumer;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Thread thread = new Thread(() -> {
|
||||
log.info("启动线程监听Topic: {}", KafkaConstants.KafkaTopic);
|
||||
ThreadUtil.sleep(1000);
|
||||
Collection<String> topics = Lists.newArrayList(KafkaConstants.KafkaTopic);
|
||||
kafkaConsumer.subscribe(topics);
|
||||
while (true) {
|
||||
ConsumerRecords<String, String> consumerRecords = kafkaConsumer.poll(Duration.ofMillis(1000));
|
||||
for (ConsumerRecord consumerRecord : consumerRecords) {
|
||||
//1.从ConsumerRecord中获取消费数据
|
||||
String originalMsg = (String) consumerRecord.value();
|
||||
log.info("从Kafka中消费的原始数据: " + originalMsg);
|
||||
//2.把消费数据转换为DTO对象
|
||||
List<KafkaData> kafkaDataList = JSONUtil.toList(originalMsg, KafkaData.class);
|
||||
log.info("消费数据转换为DTO对象: " + kafkaDataList.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.data.processing.mapper;
|
||||
|
||||
import com.muyu.data.processing.domain.IotDbData;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据处理持久层
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: DataPeocessingMapper
|
||||
* @Description: 数据处理持久层
|
||||
* @CreatedDate: 2024/9/28 下午3:47
|
||||
* @FilePath: com.muyu.data.processing.mapper
|
||||
*/
|
||||
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface DataProcessingMapper{
|
||||
|
||||
Integer createCarData(IotDbData data);
|
||||
|
||||
Integer updateCarData(IotDbData data);
|
||||
|
||||
Integer deleteCarData(String timestamp);
|
||||
|
||||
Integer createCarDataGroup();
|
||||
|
||||
Integer createCarDataGroupElement();
|
||||
|
||||
// List<DataProcessing> queryCarData();
|
||||
|
||||
List<String> selectStorageGroup();
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.muyu.data.processing.rebbit;
|
||||
|
||||
|
||||
import com.muyu.common.caffeine.CaffeineCacheUtils;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: DownlineRabbit
|
||||
* @Description: 车辆下线监听器
|
||||
* @CreatedDate: 2024/9/26 下午8:21
|
||||
* @FilePath: com.muyu.data.processing.rebbit
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DownlineRabbit {
|
||||
private CaffeineCacheUtils caffeineCacheUtils = new CaffeineCacheUtils();
|
||||
|
||||
private static final HashSet<String> DOWNLINE_SET = new HashSet<>();
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue("Downline")})
|
||||
public void downline(String vin, Message message, Channel channel) {
|
||||
log.info("车辆 {} 下线, 配置信息准备中。。。",vin);
|
||||
try {
|
||||
// 重复性校验
|
||||
if (DOWNLINE_SET.add(message.getMessageProperties().getMessageId())) {
|
||||
caffeineCacheUtils.deleteCarCache(vin);
|
||||
log.info("车辆 {} 下线, 消息已确认。。。",vin);
|
||||
} else {
|
||||
log.info("车辆 {} 下线, 消息重复消费,已确认。。。",vin);
|
||||
}
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
log.info("车辆 {} 下线, 配置信息已准备完毕。。。",vin);
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
log.warn("车辆 {} 下线, 配置信息准备失败,返回队列,原因:{}", vin, e.getMessage());
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
|
||||
} catch (IOException ex) {
|
||||
log.warn("车辆 {} 下线, 消息返回队列失败,原因:{}", vin, ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.data.processing.rebbit;
|
||||
|
||||
|
||||
import com.muyu.common.caffeine.CaffeineCacheUtils;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: GoOnlineRabbit
|
||||
* @Description: 上线事件
|
||||
* @CreatedDate: 2024/9/26 下午7:38
|
||||
* @FilePath: com.muyu.data.processing.rebbit
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class GoOnlineRabbit {
|
||||
|
||||
private CaffeineCacheUtils caffeineCacheUtils = new CaffeineCacheUtils();
|
||||
|
||||
private static final HashSet<String> DATA_SET = new HashSet<>();
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue("GoOnline")})
|
||||
public void goOnline(String vin, Message message, Channel channel){
|
||||
log.info("车辆 {} 上线, 配置信息准备中。。。",vin);
|
||||
try {
|
||||
// 重复性校验
|
||||
if (DATA_SET.add(message.getMessageProperties().getMessageId())) {
|
||||
caffeineCacheUtils.addCarCache(vin);
|
||||
log.info("车辆 {} 上线, 消息已确认。。。",vin);
|
||||
} else {
|
||||
log.info("车辆 {} 上线, 消息重复消费,已确认。。。",vin);
|
||||
}
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
log.info("车辆 {} 上线, 配置信息已准备完毕。。。",vin);
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
log.warn("车辆 {} 上线, 配置信息准备失败,返回队列,原因:{}", vin, e.getMessage());
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
|
||||
} catch (IOException ex) {
|
||||
log.warn("车辆 {} 上线, 消息返回队列失败,原因:{}", vin, ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.muyu.data.processing.service;
|
||||
|
||||
|
||||
import com.muyu.data.processing.domain.IotDbData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据处理业务层
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: DataProcessing
|
||||
* @Description: 数据处理业务层
|
||||
* @CreatedDate: 2024/9/28 下午3:52
|
||||
* @FilePath: com.muyu.data.processing.server
|
||||
*/
|
||||
|
||||
public interface DataProcessingService{
|
||||
/**
|
||||
* 创建车辆报文记录
|
||||
*
|
||||
* @param data 数据
|
||||
* @return {@link Integer }
|
||||
*/
|
||||
Integer createCarData(IotDbData data);
|
||||
|
||||
/**
|
||||
* 更新车辆报文记录
|
||||
*
|
||||
* @param data 数据
|
||||
* @return {@link Integer }
|
||||
*/
|
||||
Integer updateCarData(IotDbData data);
|
||||
|
||||
/**
|
||||
* 删除车辆报文记录
|
||||
*
|
||||
* @param timestamp 时间戳
|
||||
* @return {@link Integer }
|
||||
*/
|
||||
Integer deleteCarData(String timestamp);
|
||||
|
||||
/**
|
||||
* 创建车辆报文记录组
|
||||
*
|
||||
* @return {@link Integer }
|
||||
*/
|
||||
Integer createCarDataGroup();
|
||||
|
||||
/**
|
||||
* 查询顺序
|
||||
*
|
||||
* @return {@link List }<{@link IotDbData }>
|
||||
*/
|
||||
List<IotDbData> queryCarData();
|
||||
/**
|
||||
* 选择存储组
|
||||
*
|
||||
* @return {@link List }<{@link String }>
|
||||
*/
|
||||
List<String> selectStorageGroup();
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.muyu.data.processing.service.impl;
|
||||
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.muyu.data.processing.domain.IotDbData;
|
||||
import org.springframework.stereotype.Service;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.muyu.data.processing.mapper.DataProcessingMapper;
|
||||
import com.muyu.data.processing.service.DataProcessingService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据处理实现层
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: DataProcessing
|
||||
* @Description: 数据处理实现层
|
||||
* @CreatedDate: 2024/9/28 下午3:52
|
||||
* @FilePath: com.muyu.data.processing.server.impl
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataProcessingServiceImpl implements DataProcessingService {
|
||||
@Resource
|
||||
private DataProcessingMapper mapper;
|
||||
|
||||
@Override
|
||||
public Integer createCarData(IotDbData data) {
|
||||
return mapper.createCarData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateCarData(IotDbData data) {
|
||||
return mapper.updateCarData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteCarData(String timestamp) {
|
||||
return mapper.deleteCarData(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer createCarDataGroup() {
|
||||
try {
|
||||
Integer flag = mapper.createCarDataGroup();
|
||||
Integer flagEle = mapper.createCarDataGroupElement();
|
||||
System.out.println("\n\t执行sql数量为{}" + flagEle);
|
||||
return flagEle;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IotDbData> queryCarData() {
|
||||
// return mapper.queryCarData();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectStorageGroup() {
|
||||
return mapper.selectStorageGroup();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.data.processing.strategy;
|
||||
|
||||
/**
|
||||
* 策略控制者接口
|
||||
* @Author: 胡杨
|
||||
* @Name: StrategyHandler
|
||||
* @Description: 策略控制者接口
|
||||
* @CreatedDate: 2024/9/28 上午9:35
|
||||
* @FilePath: com.muyu.data.processing.strategy
|
||||
*/
|
||||
public interface StrategyHandler<T,R> {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
StrategyHandler DEFAULT = t -> null;
|
||||
|
||||
/**
|
||||
* 执行方法
|
||||
* @param t 入参
|
||||
* @return 返回结果
|
||||
*/
|
||||
R apply(T t);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.muyu.data.processing.strategy;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Objects;
|
||||
/**
|
||||
* 抽象策略路由
|
||||
* @Author: 胡杨
|
||||
* @Name: abstractStrategyRouter
|
||||
* @Description: 抽象策略路由
|
||||
* @CreatedDate: 2024/9/28 上午9:26
|
||||
* @FilePath: com.muyu.data.processing.strategy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public abstract class abstractStrategyRouter<T,R> {
|
||||
|
||||
/**
|
||||
* 策略映射器, 指定入参与出参以决定策略处理者
|
||||
* @param <T> 策略入参
|
||||
* @param <R> 策略出参
|
||||
*/
|
||||
public interface StrategyMapper<T,R>{
|
||||
// 通过入参获取对应策略处理方法,使用Map实现
|
||||
StrategyHandler<T,R> getHandler(T param);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽象注册方法
|
||||
* @return
|
||||
*/
|
||||
protected abstract StrategyMapper<T,R> registerStrategy();
|
||||
|
||||
/**
|
||||
* 默认策略处理者
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private StrategyHandler<T,R> defaultStrategyHandler = StrategyHandler.DEFAULT;
|
||||
|
||||
|
||||
/**
|
||||
* 选择策略处理者
|
||||
* @param param 入参
|
||||
* @return 策略处理结果
|
||||
*/
|
||||
public R applyStrategy(T param) {
|
||||
final StrategyHandler<T,R> strategyHandler = registerStrategy().getHandler(param);
|
||||
if (strategyHandler != null) {
|
||||
return strategyHandler.apply(param);
|
||||
}
|
||||
// 使用默认策略处理者
|
||||
return defaultStrategyHandler.apply(param);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.data.processing.strategy.branch;
|
||||
|
||||
import com.muyu.data.processing.domain.StrategyEums;
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import com.muyu.data.processing.strategy.abstractStrategyRouter;
|
||||
import com.muyu.data.processing.strategy.leaves.FourLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.OneLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.ThreeLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.TwoLeavesStrategy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 1号分支策略方法实现
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: OneBranchStrategy
|
||||
* @Description: 1号叶子策略方法实现
|
||||
* @CreatedDate: 2024/9/28 上午11:50
|
||||
* @FilePath: com.muyu.data.processing.strategy.impl
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OneBranchStrategy extends abstractStrategyRouter<TestReq, TestResp> implements StrategyHandler<TestReq,TestResp> {
|
||||
@Override
|
||||
public TestResp apply(TestReq testReq) {
|
||||
log.info("1号分支策略方法实现,参数1:{},参数2:{},执行方法:{}", testReq.getOne(), testReq.getTwo(), testReq.getType2());
|
||||
return applyStrategy(testReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StrategyMapper<TestReq, TestResp> registerStrategy() {
|
||||
return param -> StrategyEums.getStrategy(param.getType2());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.data.processing.strategy.branch;
|
||||
|
||||
import com.muyu.data.processing.domain.StrategyEums;
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import com.muyu.data.processing.strategy.abstractStrategyRouter;
|
||||
import com.muyu.data.processing.strategy.leaves.FourLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.OneLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.ThreeLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.TwoLeavesStrategy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 2号分支策略方法实现
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: TwoBranchStrategy
|
||||
* @Description: 1号叶子策略方法实现
|
||||
* @CreatedDate: 2024/9/28 上午11:50
|
||||
* @FilePath: com.muyu.data.processing.strategy.impl
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TwoBranchStrategy extends abstractStrategyRouter<TestReq, TestResp> implements StrategyHandler<TestReq,TestResp> {
|
||||
@Override
|
||||
public TestResp apply(TestReq testReq) {
|
||||
log.info("2号分支策略方法实现,参数1:{},参数2:{},执行方法:{}", testReq.getOne(), testReq.getTwo(), testReq.getType2());
|
||||
return applyStrategy(testReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StrategyMapper<TestReq, TestResp> registerStrategy() {
|
||||
return param -> StrategyEums.getStrategy(param.getType2());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.data.processing.strategy.leaves;
|
||||
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 4号处理者
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: FourLeavesStrategy
|
||||
* @Description: 4号处理者
|
||||
* @CreatedDate: 2024/9/28 上午11:54
|
||||
* @FilePath: com.muyu.data.processing.strategy.leaves
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FourLeavesStrategy implements StrategyHandler<TestReq, TestResp> {
|
||||
@Override
|
||||
public TestResp apply(TestReq testReq) {
|
||||
log.info("4号处理者实现,参数1:{},参数2:{},执行方法:{},结果:{}", testReq.getOne(), testReq.getTwo(), testReq.getType2(), (testReq.getOne()*1.0/testReq.getTwo()));
|
||||
return new TestResp("执行4号处理者-除法");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.data.processing.strategy.leaves;
|
||||
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import com.muyu.data.processing.strategy.abstractStrategyRouter;
|
||||
import com.muyu.data.processing.strategy.branch.OneBranchStrategy;
|
||||
import com.muyu.data.processing.strategy.branch.TwoBranchStrategy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 1号处理者
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: OneLeavesStrategy
|
||||
* @Description: 1号处理者
|
||||
* @CreatedDate: 2024/9/28 上午11:54
|
||||
* @FilePath: com.muyu.data.processing.strategy.leaves
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OneLeavesStrategy implements StrategyHandler<TestReq, TestResp> {
|
||||
@Override
|
||||
public TestResp apply(TestReq testReq) {
|
||||
log.info("1号处理者实现,参数1:{},参数2:{},执行方法:{},结果:{}", testReq.getOne(), testReq.getTwo(), testReq.getType2(), (testReq.getOne()+testReq.getTwo()));
|
||||
return new TestResp("执行1号处理者-加法");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.data.processing.strategy.leaves;
|
||||
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 3号处理者
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: ThreeLeavesStrategy
|
||||
* @Description: 3号处理者
|
||||
* @CreatedDate: 2024/9/28 上午11:54
|
||||
* @FilePath: com.muyu.data.processing.strategy.leaves
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ThreeLeavesStrategy implements StrategyHandler<TestReq, TestResp> {
|
||||
@Override
|
||||
public TestResp apply(TestReq testReq) {
|
||||
log.info("3号处理者实现,参数1:{},参数2:{},执行方法:{},结果:{}", testReq.getOne(), testReq.getTwo(), testReq.getType2(), (testReq.getOne()*testReq.getTwo()));
|
||||
return new TestResp("执行3号处理者-乘法");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.data.processing.strategy.leaves;
|
||||
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 2号处理者
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: TwoLeavesStrategy
|
||||
* @Description: 2号处理者
|
||||
* @CreatedDate: 2024/9/28 上午11:54
|
||||
* @FilePath: com.muyu.data.processing.strategy.leaves
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TwoLeavesStrategy implements StrategyHandler<TestReq, TestResp> {
|
||||
@Override
|
||||
public TestResp apply(TestReq testReq) {
|
||||
log.info("2号处理者实现,参数1:{},参数2:{},执行方法:{},结果:{}", testReq.getOne(), testReq.getTwo(), testReq.getType2(), (testReq.getOne()-testReq.getTwo()));
|
||||
return new TestResp("执行2号处理者-减法");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.data.processing.strategy.root;
|
||||
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.data.processing.domain.StrategyEums;
|
||||
import com.muyu.data.processing.domain.req.TestReq;
|
||||
import com.muyu.data.processing.domain.resp.TestResp;
|
||||
import com.muyu.data.processing.strategy.StrategyHandler;
|
||||
import com.muyu.data.processing.strategy.abstractStrategyRouter;
|
||||
import com.muyu.data.processing.strategy.branch.OneBranchStrategy;
|
||||
import com.muyu.data.processing.strategy.branch.TwoBranchStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.FourLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.OneLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.ThreeLeavesStrategy;
|
||||
import com.muyu.data.processing.strategy.leaves.TwoLeavesStrategy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 策略路由实现
|
||||
*
|
||||
* @Author: 胡杨
|
||||
* @Name: RootStrategy
|
||||
* @Description: 策略路由实现
|
||||
* @CreatedDate: 2024/9/28 上午10:39
|
||||
* @FilePath: com.muyu.data.processing.strategy.impl
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RootStrategy extends abstractStrategyRouter<TestReq, TestResp> {
|
||||
@Override
|
||||
protected StrategyMapper<TestReq , TestResp> registerStrategy() {
|
||||
return param -> StrategyEums.getStrategy(param.getType1());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,80 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9711
|
||||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 47.116.173.119:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: one-saas
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
datasource:
|
||||
username: root
|
||||
password: root
|
||||
driver-class-name: org.apache.iotdb.jdbc.IoTDBDriver
|
||||
url: jdbc:iotdb://47.116.173.119:6667/
|
||||
initial-size: 5
|
||||
min-idle: 10
|
||||
max-active: 20
|
||||
max-wait: 60000
|
||||
remove-abandoned: true
|
||||
remove-abandoned-timeout: 30
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
test-while-idle: false
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
amqp:
|
||||
deserialization:
|
||||
trust:
|
||||
all: true
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-data-processing
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
config:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统环境Config共享配置
|
||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# xxl-job 配置文件
|
||||
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# rabbit 配置文件
|
||||
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# kafka 配置文件
|
||||
- application-kafka-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.muyu.system.mapper: DEBUG
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-data-processing"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-data-processing"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-data-processing"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.data.processing.mapper.DataProcessingMapper">
|
||||
|
||||
<insert id="createCarData" parameterType="com.muyu.data.processing.domain.IotDbData">
|
||||
insert into root.one.data(timestamp, CarData_id, CarData_num, CarData_name,create_time) values(#{timestamp},#{CarDataId},#{CarDataNum},#{CarDataName},#{createTime});
|
||||
</insert>
|
||||
<select id="selectStorageGroup" resultType="java.lang.String">
|
||||
show storage group
|
||||
</select>
|
||||
<delete id="deleteCarData" parameterType="java.lang.String">
|
||||
delete from root.one.data where timestamp = ${timestamp};
|
||||
</delete>
|
||||
|
||||
<insert id="updateCarData">
|
||||
insert into root.one.data(timestamp, CarData_id, CarData_num, CarData_name,create_time) values(2021-11-24T18:28:20.689+08:00,#{CarDataId},#{CarDataNum},#{CarDataName},#{createTime});
|
||||
</insert>
|
||||
|
||||
<update id="createCarDataGroup">
|
||||
SET STORAGE GROUP TO root.one.data
|
||||
</update>
|
||||
<update id="createCarDataGroupElement">
|
||||
CREATE TIMESERIES root.one.data.CarData_num WITH DATATYPE=INT32, ENCODING=PLAIN, COMPRESSOR=SNAPPY;
|
||||
</update>
|
||||
|
||||
</mapper>
|
|
@ -81,7 +81,6 @@
|
|||
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
|
||||
<version>4.5.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -13,5 +13,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||
public class CloudGatewayApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(CloudGatewayApplication.class, args);
|
||||
System.out.println("CloudGateway 模块启动成功!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.muyu.gateway.config;
|
||||
|
||||
import com.muyu.gateway.handler.ValidateCodeHandler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.web.reactive.function.server.RouterFunctions;
|
|||
*/
|
||||
@Configuration
|
||||
public class RouterFunctionConfiguration {
|
||||
@Autowired
|
||||
@Resource
|
||||
private ValidateCodeHandler validateCodeHandler;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.gateway.config.properties.IgnoreWhiteProperties;
|
|||
import io.jsonwebtoken.Claims;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.core.Ordered;
|
||||
|
@ -31,10 +31,10 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||
private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
|
||||
|
||||
// 排除过滤的 uri 地址,nacos自行添加
|
||||
@Autowired
|
||||
@Resource
|
||||
private IgnoreWhiteProperties ignoreWhite;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
|
@ -63,6 +63,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||
}
|
||||
String userid = JwtUtils.getUserId(claims);
|
||||
String username = JwtUtils.getUserName(claims);
|
||||
String saasKey = JwtUtils.getSaasKey(claims);
|
||||
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
|
||||
return unauthorizedResponse(exchange, "令牌验证失败");
|
||||
}
|
||||
|
@ -71,6 +72,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||
addHeader(mutate, SecurityConstants.USER_KEY, userkey);
|
||||
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
|
||||
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
|
||||
addHeader(mutate,SecurityConstants.SAAS_KEY,saasKey);
|
||||
// 内部请求来源参数清除
|
||||
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
|
||||
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.muyu.common.core.utils.ServletUtils;
|
|||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.gateway.config.properties.CaptchaProperties;
|
||||
import com.muyu.gateway.service.ValidateCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
|
@ -29,9 +29,9 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> {
|
|||
private final static String[] VALIDATE_URL = new String[]{"/auth/login", "/auth/register"};
|
||||
private static final String CODE = "code";
|
||||
private static final String UUID = "uuid";
|
||||
@Autowired
|
||||
@Resource
|
||||
private ValidateCodeService validateCodeService;
|
||||
@Autowired
|
||||
@Resource
|
||||
private CaptchaProperties captchaProperties;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.html.EscapeUtil;
|
||||
import com.muyu.gateway.config.properties.XssProperties;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
|
@ -31,7 +31,7 @@ import java.nio.charset.StandardCharsets;
|
|||
@ConditionalOnProperty(value = "security.xss.enabled", havingValue = "true")
|
||||
public class XssFilter implements GlobalFilter, Ordered {
|
||||
// 跨站脚本的 xss 配置,nacos自行添加
|
||||
@Autowired
|
||||
@Resource
|
||||
private XssProperties xss;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.muyu.gateway.handler;
|
|||
import com.muyu.common.core.exception.CaptchaException;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.gateway.service.ValidateCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
|
@ -21,7 +21,7 @@ import java.io.IOException;
|
|||
*/
|
||||
@Component
|
||||
public class ValidateCodeHandler implements HandlerFunction<ServerResponse> {
|
||||
@Autowired
|
||||
@Resource
|
||||
private ValidateCodeService validateCodeService;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.muyu.common.redis.service.RedisService;
|
|||
import com.muyu.gateway.config.properties.CaptchaProperties;
|
||||
import com.muyu.gateway.model.resp.CaptchaCodeResp;
|
||||
import com.muyu.gateway.service.ValidateCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.FastByteArrayOutputStream;
|
||||
|
||||
|
@ -35,10 +35,10 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
|
|||
@Resource(name = "captchaProducerMath")
|
||||
private Producer captchaProducerMath;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private CaptchaProperties captchaProperties;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
|
|||
CaptchaCodeResp.CaptchaCodeRespBuilder respBuilder = CaptchaCodeResp.builder()
|
||||
.captchaEnabled(captchaEnabled);
|
||||
if (!captchaEnabled) {
|
||||
return Result.success(respBuilder);
|
||||
return Result.success(respBuilder.build());
|
||||
}
|
||||
|
||||
// 保存验证码信息
|
||||
|
|
|
@ -4,8 +4,6 @@ import cn.hutool.core.net.NetUtil;
|
|||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.gateway.route.Route;
|
||||
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
|
@ -18,8 +16,6 @@ import reactor.core.publisher.Mono;
|
|||
|
||||
/**
|
||||
* Web 工具类
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Log4j2
|
||||
public class WebFrameworkUtils {
|
||||
|
@ -72,8 +68,6 @@ public class WebFrameworkUtils {
|
|||
|
||||
/**
|
||||
* 获得客户端 IP
|
||||
*
|
||||
*
|
||||
* @param exchange 请求
|
||||
* @param otherHeaderNames 其它 header 名字的数组
|
||||
* @return 客户端 IP
|
||||
|
@ -91,7 +85,6 @@ public class WebFrameworkUtils {
|
|||
return NetUtil.getMultistageReverseProxyIp(ip);
|
||||
}
|
||||
}
|
||||
|
||||
// 方式二,通过 remoteAddress 获取
|
||||
if (exchange.getRequest().getRemoteAddress() == null) {
|
||||
return null;
|
||||
|
@ -102,7 +95,6 @@ public class WebFrameworkUtils {
|
|||
|
||||
/**
|
||||
* 获得请求匹配的 Route 路由
|
||||
*
|
||||
* @param exchange 请求
|
||||
* @return 路由
|
||||
*/
|
||||
|
|
|
@ -4,10 +4,10 @@ server:
|
|||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: nacos.muyu.icu:8848
|
||||
addr: 47.116.173.119:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: muyu-cloud
|
||||
namespace: one-saas
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
@ -22,29 +22,29 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# # nacos用户名
|
||||
# username: ${nacos.user-name}
|
||||
# # nacos密码
|
||||
# password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
config:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# # nacos用户名
|
||||
# username: ${nacos.user-name}
|
||||
# # nacos密码
|
||||
# password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统环境Config共享配置
|
||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
sentinel:
|
||||
# 取消控制台懒加载
|
||||
eager: true
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue