Compare commits
82 Commits
master
...
dev.gatewa
Author | SHA1 | Date |
---|---|---|
|
2b159662db | |
|
37521c39de | |
|
6dde202353 | |
|
3b2e16a39e | |
|
39432a1270 | |
|
c7c51c2305 | |
|
11ab968c8d | |
|
4e3dce703d | |
|
b29b1f18db | |
|
35e2b9d3e5 | |
|
e40fbee02a | |
|
1577ae1008 | |
|
226c427255 | |
|
5ac1ef17a3 | |
|
04450b84e6 | |
|
dfdcbdbd86 | |
|
536c40a8e2 | |
|
761fd61725 | |
|
c5f79db964 | |
|
bfb3b98684 | |
|
c37e762dd6 | |
|
cd4a07e637 | |
|
a138c0dacd | |
|
eea7db374d | |
|
4396e30dfd | |
|
d6167ebfed | |
|
e9e32c2ad0 | |
|
9952d8b24d | |
|
d7f31e3482 | |
|
a88e91c139 | |
|
06a35cd645 | |
|
6fbff659c5 | |
|
443350c8f4 | |
|
19f99ac116 | |
|
e5b5222c39 | |
|
d24110090c | |
|
14cc2afd35 | |
|
afdc7b3421 | |
|
535eae941e | |
|
bd2865ebc5 | |
|
eef2467a61 | |
|
a66329500c | |
|
f98c11e825 | |
|
c241897dfe | |
|
6f9079ec5f | |
|
eff427473f | |
|
c87bf8a2fa | |
|
0bb5a912f7 | |
|
1d43fa7888 | |
|
61dc7f9277 | |
|
6eff930c84 | |
|
ecf81cc79e | |
|
63ebaee731 | |
|
dd94f2e39e | |
|
2084013449 | |
|
3ac5b84ef6 | |
|
5f391234e2 | |
|
127c941d1c | |
|
f3428404a2 | |
|
491ecec44a | |
|
efd7a46c68 | |
|
1e19d99748 | |
|
93f78cdc3e | |
|
3953642310 | |
|
29f08cbb46 | |
|
05e6ecb947 | |
|
1f98e4ea26 | |
|
6eb46f53ae | |
|
db16c57199 | |
|
90195a9226 | |
|
70ee6d0628 | |
|
7971b67277 | |
|
49a7e0df4d | |
|
e491c7de89 | |
|
0303b4fe72 | |
|
1b982ed5a2 | |
|
244ceb5b46 | |
|
0ae1ddbbca | |
|
5994bf1550 | |
|
aa39403714 | |
|
7ae5082c3d | |
|
40e3a1ceb7 |
|
@ -4,10 +4,10 @@ server:
|
|||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 123.57.152.124:8848
|
||||
addr: 127.0.0.1:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: yan1
|
||||
namespace: wx
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -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>
|
||||
|
||||
<description>
|
||||
cloud-common-cache 缓存基准
|
||||
</description>
|
||||
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
<maven.compiler.target>23</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- redis 缓存模块-->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>enterpise-common</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,62 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 抽象缓存层
|
||||
* * @className: CacheAbsBasic ️✈️
|
||||
* * @author: Yang 鹏 🦅
|
||||
* * @date: 2024/9/29 16:08 ⏰
|
||||
* * @Version: 1.0
|
||||
* * @description:
|
||||
*/
|
||||
public abstract class CacheAbsBasic <K, V> implements CacheBasic<K, V>{
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
|
||||
try {
|
||||
redisService.setCacheObject(encode(key), value);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
|
||||
try {
|
||||
return redisService.getCacheObject(encode(key));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(K key) {
|
||||
|
||||
try {
|
||||
redisService.deleteObject(encode(key));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hashKey(K key){
|
||||
Boolean b = false;
|
||||
|
||||
try {
|
||||
b = redisService.hasKey(encode(key));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
|
||||
}
|
||||
return b;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
import org.springframework.data.redis.core.TimeoutUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 缓存基础
|
||||
* * @className: CacheBasic ️✈️
|
||||
* * @author: Yang 鹏 🦅
|
||||
* * @date: 2024/9/29 16:08 ⏰
|
||||
* * @Version: 1.0
|
||||
* * @description:
|
||||
*/
|
||||
public interface CacheBasic<K, V> extends PrimaryKeyBasic<K> {
|
||||
void put(K key, V value);
|
||||
|
||||
V get(K key);
|
||||
|
||||
void remove(K key);
|
||||
|
||||
boolean hashKey(K key);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
|
||||
/**
|
||||
* 主键基础
|
||||
* * @className: PrimaryKeyBasic ️✈️
|
||||
* * @author: Yang 鹏 🦅
|
||||
* * @date: 2024/9/29 16:08 ⏰
|
||||
* * @Version: 1.0
|
||||
* * @description:
|
||||
*/
|
||||
public interface PrimaryKeyBasic <K>{
|
||||
|
||||
/**
|
||||
* 主键前缀
|
||||
* @return
|
||||
*/
|
||||
public String keyPre();
|
||||
|
||||
/**
|
||||
* 主键编码
|
||||
* @param key 缓存建
|
||||
* @return 装修建
|
||||
*/
|
||||
public default String encode(K key){
|
||||
return keyPre() + key.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 主键解码
|
||||
* @param key 缓存建
|
||||
* @return 装修建
|
||||
*/
|
||||
public default K decode(String key) {
|
||||
return (K) key.substring(keyPre().length());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.common.domain;
|
||||
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.domain.SysCar;
|
||||
import com.muyu.domain.WarnLogs;
|
||||
import com.muyu.domain.resp.FaultConditionTotalListResp;
|
||||
import com.muyu.domain.resp.FenceGroupResp;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/9/30
|
||||
* @Description 消息数据对象
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class InformationData {
|
||||
/**
|
||||
* 车辆基本信息
|
||||
*/
|
||||
private SysCar sysCar;
|
||||
/**
|
||||
* 公司信息
|
||||
*/
|
||||
private SysDept sysDept;
|
||||
/**
|
||||
* 车辆电子绑定电子围栏信息
|
||||
*/
|
||||
private FenceGroupResp fenceGroupResp;
|
||||
/**
|
||||
* 故障规则数据总数列表
|
||||
*/
|
||||
private FaultConditionTotalListResp faultConditionTotalListResp;
|
||||
/**
|
||||
* 预警日志对象
|
||||
*/
|
||||
private List<WarnLogs> warnLogsList;
|
||||
}
|
|
@ -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>
|
||||
|
||||
<description>
|
||||
cloud-common-caffeine 本地缓存服务
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.common.caffeine.bean;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.muyu.common.caffeine.enums.CacheNameEnums;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.caffeine.CaffeineCache;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Caffeine管理器
|
||||
* @Author: WangXin
|
||||
* @Name: CaffeineCacheConfig
|
||||
* @Description: Caffeine管理器
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CaffeineManager {
|
||||
|
||||
/**
|
||||
* 创建缓存管理器
|
||||
* @return 缓存管理器实例
|
||||
*/
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
SimpleCacheManager cacheManager = new SimpleCacheManager();
|
||||
List<String> cacheNames = CacheNameEnums.getCodes();
|
||||
cacheManager.setCaches(cacheNames.stream()
|
||||
.map(name -> new CaffeineCache(
|
||||
name,
|
||||
Caffeine.newBuilder()
|
||||
.recordStats()
|
||||
.build()))
|
||||
.toList());
|
||||
log.info("缓存管理器初始化完成,缓存分区:{}", cacheNames);
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.common.caffeine.constents;
|
||||
|
||||
/**
|
||||
* Caffeine常量
|
||||
* @Author: WangXin
|
||||
* @Name: CaffeineContent
|
||||
* @Description: Caffeine常量
|
||||
*/
|
||||
|
||||
public class CaffeineContent {
|
||||
|
||||
public static final String CAR_VIN_KEY = "car:vin";
|
||||
|
||||
public static final String VIN = "vin";
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.common.caffeine.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 缓存分区枚举
|
||||
*
|
||||
* @Author: WangXin
|
||||
* @Name: CacheNameEnums
|
||||
* @Description: 缓存分区枚举
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public enum CacheNameEnums {
|
||||
STORAGE("storage", "持久化"),
|
||||
FAULT("fault", "故障"),
|
||||
FENCE("fence", "围栏"),
|
||||
WARMING("warming", "预警"),
|
||||
REALTIME("realTime", "实时信息");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
CacheNameEnums(String code, String info) {
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 鉴别参数是否是枚举的值
|
||||
*
|
||||
* @param code 需鉴别参数
|
||||
* @return 如果存在返回结果turn, 否则返回false
|
||||
*/
|
||||
public static boolean isCode(String code) {
|
||||
return Arrays.stream(values())
|
||||
.map(CacheNameEnums::getCode)
|
||||
.anyMatch(c -> c.equals(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举Value
|
||||
* @param code 编码
|
||||
* @return Value
|
||||
*/
|
||||
public static String getInfo(String code) {
|
||||
return Arrays.stream(values())
|
||||
.filter(c -> c.getCode().equals(code))
|
||||
.map(CacheNameEnums::getInfo)
|
||||
.findFirst()
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有code
|
||||
* @return code集合
|
||||
*/
|
||||
public static List<String> getCodes() {
|
||||
return Arrays.stream(values())
|
||||
.map(CacheNameEnums::getCode)
|
||||
.toList();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package com.muyu.common.caffeine.utils;
|
||||
|
||||
|
||||
import com.muyu.common.caffeine.enums.CacheNameEnums;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Caffeine缓存工具
|
||||
* @Author: WangXin
|
||||
* @Name: CaffeineUtils
|
||||
* @Description: 缓存工具类
|
||||
* @CreatedDate: 2024/9/26 下午2:53
|
||||
* @FilePath: com.muyu.common.caffeine
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CaffeineCacheUtils {
|
||||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
@Resource
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 车辆上线 - 新增缓存
|
||||
*/
|
||||
public void addCarCache(String vin) {
|
||||
// 从Redis中获取缓存信息
|
||||
for (String name : CacheNameEnums.getCodes()) {
|
||||
String value = redisTemplate.opsForValue().get(name+":"+vin);
|
||||
cacheManager.getCache(name).put(vin, value);
|
||||
log.info("存储缓存, 缓存分区:[{}], 车辆编码:[{}], 存储值:[{}]", name, vin, value);
|
||||
}
|
||||
log.info("车辆编码:{},本地缓存完成...",vin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆下线 - 删除缓存
|
||||
*/
|
||||
public void deleteCarCache(String cacheName) {
|
||||
if (!hasCarVinCache(cacheName,null)) {
|
||||
log.warn("车辆编码:{},本地缓存不存在该车辆信息...", cacheName);
|
||||
return;
|
||||
}
|
||||
cacheManager.getCache(cacheName).invalidate();
|
||||
log.info("车辆编码:{},本地缓存删除完成...", cacheName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆信息缓存
|
||||
*/
|
||||
public Object getCarCache(String cacheName, String key) {
|
||||
if (!hasCarVinCache(cacheName, key)){
|
||||
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",cacheName);
|
||||
return null;
|
||||
}
|
||||
return cacheManager.getCache(cacheName).get(key).get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆信息缓存
|
||||
*/
|
||||
public <T> T getCarCache(String cacheName, String key, Class<T> type) {
|
||||
if (!hasCarVinCache(cacheName,key)){
|
||||
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",cacheName);
|
||||
return null;
|
||||
}
|
||||
return cacheManager.getCache(cacheName).get(key, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断缓存存在与否
|
||||
*/
|
||||
public Boolean hasCarVinCache(String cacheName,String key) {
|
||||
boolean notEmpty = ObjectUtils.isNotEmpty(cacheManager.getCache(cacheName));
|
||||
if (notEmpty && StringUtils.isNotEmpty(key)){
|
||||
return ObjectUtils.isNotEmpty(cacheManager.getCache(cacheName).get(key).get());
|
||||
}
|
||||
return notEmpty;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
com.muyu.common.caffeine.utils.CaffeineCacheUtils
|
||||
com.muyu.common.caffeine.bean.CaffeineManager
|
|
@ -20,4 +20,10 @@ public class ServiceNameConstants {
|
|||
* 文件服务的serviceid
|
||||
*/
|
||||
public static final String FILE_SERVICE = "cloud-file";
|
||||
|
||||
/**
|
||||
* 车辆服务的serviceid
|
||||
*/
|
||||
public static final String ENTERPRISE_SERVICE = "cloud-saas";
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.muyu.common.core.domain;
|
|||
import com.muyu.common.core.constant.Constants;
|
||||
import com.muyu.common.core.constant.HttpStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
@ -15,7 +15,7 @@ import java.io.Serializable;
|
|||
* @author muyu
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Result<T> implements Serializable {
|
||||
|
@ -33,6 +33,7 @@ public class Result<T> implements Serializable {
|
|||
public static final int WARN = HttpStatus.WARN;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int code;
|
||||
|
||||
private String msg;
|
||||
|
@ -96,8 +97,8 @@ public class Result<T> implements Serializable {
|
|||
private static <T> Result<T> restResult (T data, int code, String msg) {
|
||||
return Result.<T>builder()
|
||||
.code(code)
|
||||
.data(data)
|
||||
.msg(msg)
|
||||
.data(data)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.muyu.common.core.web.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.core.utils.PageUtils;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -19,7 +21,7 @@ import java.util.List;
|
|||
*
|
||||
* @author muyu
|
||||
*/
|
||||
public class BaseController {
|
||||
public class BaseController<M extends BaseEntity> {
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-common-iotdb</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-common-iotdb 时序性数据存储服务
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-session</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,180 @@
|
|||
|
||||
package com.muyu.common.iotdb.config;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.isession.SessionDataSet;
|
||||
import org.apache.iotdb.isession.pool.SessionDataSetWrapper;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.pool.SessionPool;
|
||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||
import org.apache.iotdb.tsfile.read.common.Field;
|
||||
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.muyu.common.iotdb.constant.IotdbConstant.ROOT_DATA_DATAJSON;
|
||||
import static com.muyu.common.iotdb.constant.IotdbConstant.SELECT_ROOT_DATA_DATAJSON_DATASOURCE;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/9/30
|
||||
* @Description IotDBSessionConfig配置类
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
@Configuration
|
||||
public class IotDBSessionConfig {
|
||||
|
||||
@Value("${spring.iotdb.username:root}")
|
||||
private String username;
|
||||
|
||||
@Value("${spring.iotdb.password:root}")
|
||||
private String password;
|
||||
|
||||
@Value("${spring.iotdb.ip:127.0.0.1}")
|
||||
private String ip;
|
||||
|
||||
@Value("${spring.iotdb.port:6667}")
|
||||
private int port;
|
||||
|
||||
@Value("${spring.iotdb.maxSize:10}")
|
||||
private int maxSize;
|
||||
|
||||
private static SessionPool sessionPool;
|
||||
|
||||
/**
|
||||
* 获取IotDBSession对象
|
||||
* @return iotDBSession对象
|
||||
*/
|
||||
public SessionPool getSessionPool() {
|
||||
if (sessionPool == null) {
|
||||
sessionPool = new SessionPool(ip, port, username, password, maxSize);
|
||||
}
|
||||
return sessionPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据
|
||||
* @param deviceId
|
||||
* @param time
|
||||
* @param measurements
|
||||
* @param value
|
||||
*/
|
||||
public void insertRecord(SessionPool sessionPool,String deviceId,
|
||||
long time, List<String> measurements,List<TSDataType> dataTypeList, JSONObject value) {
|
||||
try {
|
||||
log.info("iotdb数据入库:device_id:[{}], measurements:[{}], values:[{}]", deviceId, measurements, value);
|
||||
sessionPool.insertRecord(deviceId, time, measurements,dataTypeList,new Object[]{value.toJSONString()});
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertRecord失败: deviceId={}, time={}, measurements={}, values={}, error={}",
|
||||
deviceId, time, measurements, value, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void JSONObject(JSONObject value){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* sql查数据
|
||||
* @param sessionPool
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
public SessionDataSet selectRecord(SessionPool sessionPool,String sql) {
|
||||
log.info("iotdb数据查询:sql:[{}]",sql);
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
try {
|
||||
log.info("iotdb SQL查询:sql:[{}]", sql);
|
||||
sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeQueryStatement失败:sql:[{}],error={}", sql, e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public JSONObject getJsonFindByTime(SessionPool sessionPool,String fieldName,String deviceId,Long timestamp) {
|
||||
String sql = String.format("SELECT %s FROM %s WHERE time = %d", fieldName, deviceId, timestamp);
|
||||
SessionDataSet sessionDataSet = selectRecord(sessionPool, sql);
|
||||
try {
|
||||
while (sessionDataSet.hasNext()){
|
||||
RowRecord next = sessionDataSet.next();
|
||||
for (Field field : next.getFields()) {
|
||||
String stringValue = field.getStringValue();
|
||||
}
|
||||
}
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SessionPool sessionPool = new SessionPool("127.0.0.1", 6667, "root", "root", 10);
|
||||
|
||||
|
||||
String jsonValue = """
|
||||
{
|
||||
"name": "张三",
|
||||
"age": 28,
|
||||
"email": "zhangsan@example.com",
|
||||
"isStudent": false,
|
||||
"hobbies": ["阅读", "旅行", "编程"],
|
||||
"address": {
|
||||
"street": "长安街100号",
|
||||
"city": "北京",
|
||||
"postalCode": "100000"
|
||||
}
|
||||
}
|
||||
""";
|
||||
JSONObject value = JSONObject.parseObject(jsonValue);
|
||||
|
||||
IotDBSessionConfig iotDBSessionConfig = new IotDBSessionConfig();
|
||||
|
||||
List<String> measurements = List.of("datasource");
|
||||
List<TSDataType> datatypeList = List.of(TSDataType.TEXT);
|
||||
iotDBSessionConfig.insertRecord(sessionPool,ROOT_DATA_DATAJSON,System.currentTimeMillis(),measurements,datatypeList,value);
|
||||
|
||||
SessionDataSet sessionDataSet = iotDBSessionConfig.selectRecord(sessionPool,SELECT_ROOT_DATA_DATAJSON_DATASOURCE);
|
||||
|
||||
HashMap<Long, Map<String, String>> longMapHashMap = new HashMap<>();
|
||||
|
||||
try {
|
||||
while (sessionDataSet.hasNext()){
|
||||
RowRecord next = sessionDataSet.next();
|
||||
long timestamp = next.getTimestamp();
|
||||
Map<String, String> fieldMap = new HashMap<>();
|
||||
for (Field field : next.getFields()) {
|
||||
TSDataType dataType = field.getDataType();
|
||||
String stringValue = field.getStringValue();
|
||||
fieldMap.put(dataType.name(), stringValue);
|
||||
}
|
||||
longMapHashMap.put(timestamp, fieldMap);
|
||||
}
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
log.info("数据为:{}", JSONObject.toJSONString(longMapHashMap));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.common.iotdb.constant;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/9/30
|
||||
* @Description iotdb数据库常量
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
public interface IotdbConstant {
|
||||
|
||||
String ROOT_DATA_DATAJSON = "root.car.data.datajson";
|
||||
|
||||
String SELECT_ROOT_DATA_DATAJSON_DATASOURCE = "select * from root.car.data.datajson";
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.muyu.common.iotdb.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class InsertDataDTO {
|
||||
private Float temperature;
|
||||
private String hardware;
|
||||
private Boolean status;
|
||||
|
||||
public InsertDataDTO buildOne() {
|
||||
InsertDataDTO insertDataDTO = new InsertDataDTO();
|
||||
insertDataDTO.setHardware("ss");
|
||||
insertDataDTO.setStatus(true);
|
||||
insertDataDTO.setTemperature(12.0F);
|
||||
return insertDataDTO;
|
||||
}
|
||||
|
||||
public List<InsertDataDTO> buildList() {
|
||||
List<InsertDataDTO> insertDataDTOS = new ArrayList<>();
|
||||
int buildNum = 10;
|
||||
for (int i = 0; i < buildNum; i++) {
|
||||
InsertDataDTO insertDataDTO = new InsertDataDTO();
|
||||
insertDataDTO.setHardware(i % 2 == 0 ? "pp" + i : null);
|
||||
insertDataDTO.setStatus(i % 2 == 0);
|
||||
insertDataDTO.setTemperature(12.0F + i);
|
||||
insertDataDTOS.add(insertDataDTO);
|
||||
}
|
||||
return insertDataDTOS;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.common.iotdb.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/9/30
|
||||
* @Description IotDBServiceImpl业务实现层
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class IotDbRecordAble {
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.common.iotdb.domain.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MeasurementSchemaValuesDTO {
|
||||
|
||||
private List<MeasurementSchema> schemaList;
|
||||
|
||||
private List<Object> values;
|
||||
|
||||
private List<Integer> valueIsNullIndex;
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
package com.muyu.common.iotdb.service;
|
||||
|
||||
import com.muyu.common.iotdb.domain.dto.IotDbRecordAble;
|
||||
import com.muyu.common.iotdb.domain.dto.MeasurementSchemaValuesDTO;
|
||||
import org.apache.iotdb.common.rpc.thrift.TAggregationType;
|
||||
import org.apache.iotdb.isession.SessionDataSet;
|
||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||
import org.apache.iotdb.tsfile.write.record.Tablet;
|
||||
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/9/28
|
||||
* @Description IotDBServiceImpl业务层
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
public interface IotDBService {
|
||||
|
||||
void insertTablet(Tablet tablet);
|
||||
|
||||
void insertTablets(Map<String, Tablet> tablets);
|
||||
|
||||
void insertStringRecord(String deviceId, long time, List<String> measurements, List<String> values);
|
||||
|
||||
void insertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values);
|
||||
|
||||
void insertStringRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList);
|
||||
|
||||
void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList);
|
||||
|
||||
void insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList);
|
||||
|
||||
void insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList);
|
||||
|
||||
void deleteData(String path, long endTime);
|
||||
|
||||
void deleteData(List<String> paths, long endTime);
|
||||
|
||||
SessionDataSet executeRawDataQuery(List<String> paths, long startTime, long endTime, long timeOut);
|
||||
|
||||
<T> List<T> executeRawDataQuery(List<String> paths, long startTime, long endTime, long timeOut, Class<? extends IotDbRecordAble> clazz);
|
||||
|
||||
SessionDataSet executeLastDataQuery(List<String> paths, long lastTime);
|
||||
|
||||
<T> List<T> executeLastDataQuery(List<String> paths, long lastTime, Class<? extends IotDbRecordAble> clazz);
|
||||
|
||||
SessionDataSet executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes);
|
||||
|
||||
<T> List<T> executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes, Class<? extends IotDbRecordAble> clazz);
|
||||
|
||||
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations);
|
||||
|
||||
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime);
|
||||
|
||||
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime, long interval);
|
||||
|
||||
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime, long interval, long slidingStep);
|
||||
|
||||
SessionDataSet executeQueryStatement(String sql);
|
||||
|
||||
|
||||
/**
|
||||
* SQL非查询
|
||||
*
|
||||
* @param sql
|
||||
*/
|
||||
void executeNonQueryStatement(String sql);
|
||||
|
||||
/**
|
||||
* 封装处理数据
|
||||
*
|
||||
* @param sessionDataSet
|
||||
* @param titleList
|
||||
*/
|
||||
List<Map<String, Object>> packagingMapData(SessionDataSet sessionDataSet, List<String> columnNames);
|
||||
|
||||
/**
|
||||
* 封装处理数据(不支持聚合查询)
|
||||
*
|
||||
* @param sessionDataSet 查询返回的结果集
|
||||
* @param titleList 查询返回的结果集内的字段名
|
||||
* @param clazz 返回数据对应的对象(对象属性必须与字段名对应)
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
<T> List<T> packagingObjectData(SessionDataSet sessionDataSet, List<String> titleList, Class<? extends IotDbRecordAble> clazz);
|
||||
|
||||
/**
|
||||
* 根据对象构建MeasurementSchemas
|
||||
*
|
||||
* @param object 对象
|
||||
* @return
|
||||
*/
|
||||
List<MeasurementSchema> buildMeasurementSchemas(Object object);
|
||||
/**
|
||||
* 根据对象构建MeasurementSchemaValuesDTO
|
||||
*
|
||||
* @param object 对象
|
||||
* @return
|
||||
*/
|
||||
MeasurementSchemaValuesDTO buildMeasurementSchemasAndValues(Object object);
|
||||
}
|
|
@ -0,0 +1,711 @@
|
|||
package com.muyu.common.iotdb.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.muyu.common.iotdb.config.IotDBSessionConfig;
|
||||
import com.muyu.common.iotdb.domain.dto.IotDbRecordAble;
|
||||
import com.muyu.common.iotdb.domain.dto.MeasurementSchemaValuesDTO;
|
||||
import com.muyu.common.iotdb.service.IotDBService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.iotdb.common.rpc.thrift.TAggregationType;
|
||||
import org.apache.iotdb.isession.SessionDataSet;
|
||||
import org.apache.iotdb.isession.pool.SessionDataSetWrapper;
|
||||
import org.apache.iotdb.session.pool.SessionPool;
|
||||
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
|
||||
import org.apache.iotdb.tsfile.read.common.Field;
|
||||
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||
import org.apache.iotdb.tsfile.write.record.Tablet;
|
||||
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/9/28
|
||||
* @Description IotDBServiceImpl业务实现层
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class IotDBServiceImpl implements IotDBService {
|
||||
|
||||
@Resource
|
||||
private IotDBSessionConfig iotDBSessionConfig;
|
||||
|
||||
/**
|
||||
* 单设备批量插入数据
|
||||
*
|
||||
* @param tablet
|
||||
*/
|
||||
@Override
|
||||
public void insertTablet(Tablet tablet) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:tablet:[{}]", tablet);
|
||||
sessionPool.insertTablet(tablet);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertTablet失败: tablet={}, error={}", tablet, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 多设备批量插入数据
|
||||
*
|
||||
* @param tablets
|
||||
*/
|
||||
@Override
|
||||
public void insertTablets(Map<String, Tablet> tablets) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:tablets:[{}]", tablets);
|
||||
sessionPool.insertTablets(tablets);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertTablets失败: tablets={}, error={}", tablets, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条数据插入(string类型数据项)
|
||||
*
|
||||
* @param deviceId 设备名(表名)root.ln.wf01.wt01
|
||||
* @param time 时间戳
|
||||
* @param measurements 数据项列表
|
||||
* @param values 数据项对应值列表
|
||||
*/
|
||||
@Override
|
||||
public void insertStringRecord(String deviceId, long time, List<String> measurements, List<String> values) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:device_id:[{}], measurements:[{}], values:[{}]", deviceId, measurements, values);
|
||||
sessionPool.insertRecord(deviceId, time, measurements, values);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertRecord失败: deviceId={}, time={}, measurements={}, values={}, error={}",
|
||||
deviceId, time, measurements, values, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条数据插入(不同类型数据项)
|
||||
*
|
||||
* @param deviceId 设备名(表名)root.ln.wf01.wt01
|
||||
* @param time 时间戳
|
||||
* @param measurements 数据项列表
|
||||
* @param types 数据项对应类型列表
|
||||
* @param values 数据项对应值列表
|
||||
*/
|
||||
@Override
|
||||
public void insertRecord(String deviceId, long time, List<String> measurements, List<TSDataType> types, List<Object> values) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:device_id:[{}], measurements:[{}], types:[{}], values:[{}]", deviceId, measurements, types, values);
|
||||
sessionPool.insertRecord(deviceId, time, measurements, types, values);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertRecordHasTypes失败: deviceId={}, time={}, measurements={},types={}, values={}, error={}",
|
||||
deviceId, time, measurements, types, values, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多个设备多条数据插入(string类型数据项)
|
||||
*
|
||||
* @param deviceIds 多个设备名(表名)root.ln.wf01.wt01
|
||||
* @param times 时间戳的列表
|
||||
* @param measurementsList 数据项列表的列表
|
||||
* @param valuesList 数据项对应值列表的列表
|
||||
*/
|
||||
@Override
|
||||
public void insertStringRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:deviceIds:[{}], measurementsList:[{}], valuesList:[{}]", deviceIds, measurementsList, valuesList);
|
||||
sessionPool.insertRecords(deviceIds, times, measurementsList, valuesList);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertRecords失败: deviceIds={}, times={}, measurementsList={}, valuesList={}, error={}",
|
||||
deviceIds, times, measurementsList, valuesList, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 多个设备多条数据插入(不同类型数据项)
|
||||
*
|
||||
* @param deviceIds 多个设备名(表名))root.ln.wf01.wt01
|
||||
* @param times 时间戳的列表
|
||||
* @param measurementsList 数据项列表的列表
|
||||
* @param typesList 数据项对应类型列表的列表
|
||||
* @param valuesList 数据项对应值列表的列表
|
||||
*/
|
||||
@Override
|
||||
public void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:deviceIds:[{}], measurementsList:[{}], typesList:[{}], valuesList:[{}]", deviceIds, measurementsList, typesList, valuesList);
|
||||
sessionPool.insertRecords(deviceIds, times, measurementsList, typesList, valuesList);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertRecords失败: deviceIds={}, times={}, measurementsList={}, typesList=[],valuesList={}, error={}",
|
||||
deviceIds, times, measurementsList, typesList, valuesList, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个设备多条数据插入(string类型数据项)
|
||||
*
|
||||
* @param deviceId 单个设备名(表名))root.ln.wf01.wt01
|
||||
* @param times 时间戳的列表
|
||||
* @param measurementsList 数据项列表的列表
|
||||
* @param valuesList 数据项对应值列表的列表
|
||||
*/
|
||||
@Override
|
||||
public void insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:deviceId:[{}], measurementsList:[{}], valuesList:[{}]", deviceId, measurementsList, valuesList);
|
||||
sessionPool.insertStringRecordsOfOneDevice(deviceId, times, measurementsList, valuesList);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertStringRecordsOfOneDevice失败: deviceId={}, times={}, measurementsList={}, valuesList={}, error={}",
|
||||
deviceId, times, measurementsList, valuesList, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个设备多条数据插入(不同类型数据项)
|
||||
*
|
||||
* @param deviceId 单个设备名(表名))root.ln.wf01.wt01
|
||||
* @param times 时间戳的列表
|
||||
* @param measurementsList 数据项列表的列表
|
||||
* @param typesList 数据项对应类型列表的列表
|
||||
* @param valuesList 数据项对应值列表的列表
|
||||
*/
|
||||
@Override
|
||||
public void insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据入库:deviceId:[{}], measurementsList:[{}], typesList:[{}], valuesList:[{}]", deviceId, measurementsList, typesList, valuesList);
|
||||
sessionPool.insertRecordsOfOneDevice(deviceId, times, measurementsList, typesList, valuesList);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession insertRecordsOfOneDevice失败: deviceId={}, times={}, measurementsList={}, typesList=[],valuesList={}, error={}", deviceId, times, measurementsList, typesList, valuesList, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据(删除一个时间序列在某个时间点前或这个时间点的数据)
|
||||
*
|
||||
* @param path 单个字段 root.ln.wf01.wt01.temperature
|
||||
* @param endTime 删除时间点
|
||||
*/
|
||||
@Override
|
||||
public void deleteData(String path, long endTime) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据删除:path:[{}], endTime:[{}]", path, endTime);
|
||||
sessionPool.deleteData(path, endTime);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession deleteData失败: deviceId={}, times={},error={}", path, endTime, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据(删除多个时间序列在某个时间点前或这个时间点的数据)
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param endTime 删除时间点
|
||||
*/
|
||||
@Override
|
||||
public void deleteData(List<String> paths, long endTime) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb数据删除:paths:[{}], endTime:[{}]", paths, endTime);
|
||||
sessionPool.deleteData(paths, endTime);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession deleteData失败: paths={}, times={},error={}", paths, endTime, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据查询(时间序列原始数据范围查询,时间范围为左闭右开区间,包含开始时间但不包含结束时间)
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param outTime 超时时间
|
||||
* @return SessionDataSet (Time,paths)
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeRawDataQuery(List<String> paths, long startTime, long endTime, long outTime) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
try {
|
||||
log.info("iotdb数据查询:paths:[{}], startTime:[{}], endTime:[{}],outTime:[{}]", paths, startTime, endTime, outTime);
|
||||
sessionDataSetWrapper = sessionPool.executeRawDataQuery(paths, startTime, endTime, outTime);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeRawDataQuery失败: paths={}, startTime:[{}], endTime:[{}],outTime:[{}],error={}", paths, startTime, endTime, outTime, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据查询(时间序列原始数据范围查询,时间范围为左闭右开区间,包含开始时间但不包含结束时间)
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param outTime 超时时间
|
||||
* @param clazz 返回数据对应的对象(对象属性必须与字段名对应)
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> executeRawDataQuery(List<String> paths, long startTime, long endTime, long outTime, Class<? extends IotDbRecordAble> clazz) {
|
||||
SessionDataSet sessionDataSet = executeRawDataQuery(paths, startTime, endTime, outTime);
|
||||
List<String> columnNames = sessionDataSet.getColumnNames();
|
||||
List<T> resultEntities = null;
|
||||
try {
|
||||
resultEntities = packagingObjectData(sessionDataSet, columnNames, clazz);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeRawDataQuery失败: paths={}, startTime:[{}], endTime:[{}],outTime:[{}],error={}", paths, startTime, endTime, outTime, e.getMessage());
|
||||
}
|
||||
return resultEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最新点查询(查询最后一条时间戳大于等于某个时间点的数据)
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param lastTime 结束时间
|
||||
* @return SessionDataSet
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeLastDataQuery(List<String> paths, long lastTime) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
try {
|
||||
log.info("iotdb数据查询:paths:[{}], lastTime:[{}]", paths, lastTime);
|
||||
sessionDataSetWrapper = sessionPool.executeLastDataQuery(paths, lastTime);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeLastDataQuery失败: paths={}, lastTime:[{}], error={}", paths, lastTime, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最新点查询(查询最后一条时间戳大于等于某个时间点的数据)
|
||||
*
|
||||
* @param <T>
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param lastTime 结束时间
|
||||
* @param clazz 返回数据对应的对象(对象属性必须与字段名对应)
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> executeLastDataQuery(List<String> paths, long lastTime, Class<? extends IotDbRecordAble> clazz) {
|
||||
SessionDataSet sessionDataSet = executeLastDataQuery(paths, lastTime);
|
||||
List<String> columnNames = sessionDataSet.getColumnNames();
|
||||
List<T> resultEntities = null;
|
||||
try {
|
||||
resultEntities = packagingObjectData(sessionDataSet, columnNames, clazz);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeLastDataQuery失败: paths={}, lastTime:[{}], error={}", paths, lastTime, e.getMessage());
|
||||
}
|
||||
return resultEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最新点查询(快速查询单设备下指定序列最新点)
|
||||
*
|
||||
* @param db root.ln.wf01
|
||||
* @param device root.ln.wf01.wt01
|
||||
* @param sensors temperature,status(字段名)
|
||||
* @param isLegalPathNodes true(避免路径校验)
|
||||
* @return SessionDataSet
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
try {
|
||||
log.info("iotdb数据查询:db:[{}], device:[{}],sensors:[{}], isLegalPathNodes:[{}]", db, device, sensors, isLegalPathNodes);
|
||||
sessionDataSetWrapper = sessionPool.executeLastDataQueryForOneDevice(db, device, sensors, isLegalPathNodes);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeLastDataQueryForOneDevice失败: db:[{}], device:[{}],sensors:[{}], isLegalPathNodes:[{}], error={}", db, device, sensors, isLegalPathNodes, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param db root.ln.wf01
|
||||
* @param device root.ln.wf01.wt01
|
||||
* @param sensors temperature,status(字段名)
|
||||
* @param isLegalPathNodes true(避免路径校验)
|
||||
* @param clazz 返回数据对应的对象(对象属性必须与字段名对应)
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T> List<T> executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes, Class<? extends IotDbRecordAble> clazz) {
|
||||
SessionDataSet sessionDataSet = executeLastDataQueryForOneDevice(db, device, sensors, isLegalPathNodes);
|
||||
List<String> columnNames = sessionDataSet.getColumnNames();
|
||||
List<T> resultEntities = null;
|
||||
try {
|
||||
resultEntities = packagingObjectData(sessionDataSet, columnNames, clazz);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeLastDataQueryForOneDevice失败: db:[{}], device:[{}],sensors:[{}], isLegalPathNodes:[{}], error={}", db, device, sensors, isLegalPathNodes, e.getMessage());
|
||||
}
|
||||
return resultEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合查询
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param aggregations 聚合操作 TAggregationType.SUM,TAggregationType.COUNT
|
||||
* @return SessionDataSet
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
try {
|
||||
log.info("iotdb聚合查询:paths:[{}], aggregations:[{}]", paths, aggregations);
|
||||
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations:[{}] ,error={}", paths, aggregations, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合查询(时间序列原始数据范围查询,时间范围为左闭右开区间,包含开始时间但不包含结束时间)
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param aggregations 聚合操作 TAggregationType.SUM,TAggregationType.COUNT
|
||||
* @param startTime 开始时间(包含)
|
||||
* @param endTime 结束时间
|
||||
* @return SessionDataSet
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
try {
|
||||
log.info("iotdb聚合查询:paths:[{}], aggregations:[{}],startTime:[{}], endTime:[{}]", paths, aggregations, startTime, endTime);
|
||||
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations, startTime, endTime);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations:[{}] ,startTime:[{}], endTime:[{}],error={}", paths, aggregations, startTime, endTime, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合查询(支持按照时间区间分段查询)
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param aggregations 聚合操作 TAggregationType.SUM,TAggregationType.COUNT
|
||||
* @param startTime 开始时间(包含)
|
||||
* @param endTime 结束时间
|
||||
* @param interval
|
||||
* @return SessionDataSet
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime, long interval) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
try {
|
||||
log.info("iotdb聚合查询:paths:[{}], aggregations:[{}],startTime:[{}], endTime:[{}] ,interval:[{}]", paths, aggregations, startTime, endTime, interval);
|
||||
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations, startTime, endTime, interval);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations:[{}] ,startTime:[{}], endTime:[{}], interval:[{}], error={}", paths, aggregations, startTime, endTime, interval, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合查询(支持按照时间区间分段查询)
|
||||
*
|
||||
* @param paths 多个字段(表名)) root.ln.wf01.wt01.temperature
|
||||
* @param aggregations 聚合操作 TAggregationType.SUM,TAggregationType.COUNT
|
||||
* @param startTime 开始时间(包含)
|
||||
* @param endTime 结束时间
|
||||
* @param interval
|
||||
* @param slidingStep
|
||||
* @return SessionDataSet
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, long startTime, long endTime, long interval, long slidingStep) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
|
||||
try {
|
||||
log.info("iotdb聚合查询:paths:[{}], aggregations:[{}],startTime:[{}], endTime:[{}] ,interval:[{}], slidingStep:[{}]", paths, aggregations, startTime, endTime, interval, slidingStep);
|
||||
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations, startTime, endTime, interval, slidingStep);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations:[{}] ,startTime:[{}], endTime:[{}], interval:[{}], slidingStep:[{}] ,error={}", paths, aggregations, startTime, endTime, interval, slidingStep, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL查询
|
||||
*
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SessionDataSet executeQueryStatement(String sql) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
SessionDataSetWrapper sessionDataSetWrapper = null;
|
||||
|
||||
try {
|
||||
log.info("iotdb SQL查询:sql:[{}]", sql);
|
||||
sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
|
||||
return sessionDataSetWrapper.getSessionDataSet();
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeQueryStatement失败:sql:[{}],error={}", sql, e.getMessage());
|
||||
} finally {
|
||||
sessionPool.closeResultSet(sessionDataSetWrapper);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL非查询
|
||||
*
|
||||
* @param sql
|
||||
*/
|
||||
@Override
|
||||
public void executeNonQueryStatement(String sql) {
|
||||
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
|
||||
try {
|
||||
log.info("iotdb SQL无查询:sql:[{}]", sql);
|
||||
sessionPool.executeNonQueryStatement(sql);
|
||||
} catch (Exception e) {
|
||||
log.error("IotDBSession executeNonQueryStatement失败:sql:[{}],error={}", sql, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装处理数据
|
||||
*
|
||||
* @param sessionDataSet
|
||||
* @param titleList
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public List<Map<String, Object>> packagingMapData(SessionDataSet sessionDataSet, List<String> titleList) {
|
||||
int fetchSize = sessionDataSet.getFetchSize();
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
titleList.remove("Time");
|
||||
if (fetchSize > 0) {
|
||||
while (sessionDataSet.hasNext()) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
RowRecord next = sessionDataSet.next();
|
||||
List<Field> fields = next.getFields();
|
||||
String timeString = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(next.getTimestamp());
|
||||
resultMap.put("time", timeString);
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
Field field = fields.get(i);
|
||||
if (field.getDataType() == null || field.getObjectValue(field.getDataType()) == null) {
|
||||
resultMap.put(splitString(titleList.get(i)), null);
|
||||
} else {
|
||||
resultMap.put(splitString(titleList.get(i)), field.getObjectValue(field.getDataType()).toString());
|
||||
}
|
||||
}
|
||||
resultList.add(resultMap);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装处理数据(不支持聚合查询)
|
||||
*
|
||||
* @param sessionDataSet 查询返回的结果集
|
||||
* @param titleList 查询返回的结果集内的字段名
|
||||
* @param clazz 返回数据对应的对象(对象属性必须与字段名对应)
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public <T> List<T> packagingObjectData(SessionDataSet sessionDataSet, List<String> titleList, Class<? extends IotDbRecordAble> clazz) {
|
||||
int fetchSize = sessionDataSet.getFetchSize();
|
||||
List<T> resultList = new ArrayList<>();
|
||||
titleList.remove("Time");
|
||||
if (fetchSize > 0) {
|
||||
while (sessionDataSet.hasNext()) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
RowRecord next = sessionDataSet.next();
|
||||
List<Field> fields = next.getFields();
|
||||
String timeString = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(next.getTimestamp());
|
||||
resultMap.put("time", timeString);
|
||||
if (titleList.stream().anyMatch(str -> str.contains("."))) {
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
Field field = fields.get(i);
|
||||
String title = titleList.get(i);
|
||||
if (field.getDataType() == null || field.getObjectValue(field.getDataType()) == null) {
|
||||
resultMap.put(splitString(title), null);
|
||||
} else {
|
||||
resultMap.put(splitString(title), field.getObjectValue(field.getDataType()).toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Field fieldName = fields.get(0);
|
||||
Field fieldValue = fields.get(1);
|
||||
Field fieldDataType = fields.get(2);
|
||||
if (fieldName.getDataType() != null && fieldName.getObjectValue(fieldName.getDataType()) != null) {
|
||||
String mapKey = fieldName.getObjectValue(fieldName.getDataType()).toString();
|
||||
Object mapValue = convertStringToType(fieldValue.getObjectValue(fieldValue.getDataType()).toString(), fieldDataType.getObjectValue(fieldDataType.getDataType()).toString());
|
||||
resultMap.put(splitString(mapKey), mapValue);
|
||||
}
|
||||
}
|
||||
|
||||
String jsonString = JSON.toJSONString(resultMap);
|
||||
resultList.add(JSON.parseObject(jsonString, (Type) clazz));
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分割获取字段名
|
||||
*
|
||||
* @param str
|
||||
* @return 字段名
|
||||
*/
|
||||
public static String splitString(String str) {
|
||||
String[] parts = str.split("\\.");
|
||||
if (parts.length <= 0) {
|
||||
return str;
|
||||
} else {
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数据值和数据类型返回对应数据类型数据
|
||||
*
|
||||
* @param value 数据值
|
||||
* @param typeName 数据类型
|
||||
* @return 转换后的数据值
|
||||
*/
|
||||
public static Object convertStringToType(String value, String typeName) {
|
||||
String type = typeName.toLowerCase();
|
||||
if (type.isEmpty()) {
|
||||
return value;
|
||||
}
|
||||
if ("boolean".equals(type)) {
|
||||
return Boolean.parseBoolean(value);
|
||||
} else if ("double".equals(type)) {
|
||||
return Double.parseDouble(value);
|
||||
} else if ("int32".equals(type)) {
|
||||
return Integer.parseInt(value);
|
||||
} else if ("int64".equals(type)) {
|
||||
return Long.parseLong(value);
|
||||
} else if ("float".equals(type)) {
|
||||
return Float.parseFloat(value);
|
||||
} else if ("text".equals(type)) {
|
||||
return value;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据对象属性的数据类型返回对应的TSDataType
|
||||
*
|
||||
* @param type 属性的数据类型
|
||||
* @return TSDataType
|
||||
*/
|
||||
public static TSDataType getTsDataTypeByString(String type) {
|
||||
String typeName = splitString(type).toLowerCase();
|
||||
if ("boolean".equals(typeName)) {
|
||||
return TSDataType.BOOLEAN;
|
||||
} else if ("double".equals(typeName)) {
|
||||
return TSDataType.DOUBLE;
|
||||
} else if ("int".equals(typeName) || "integer".equals(typeName)) {
|
||||
return TSDataType.INT32;
|
||||
} else if ("long".equals(typeName)) {
|
||||
return TSDataType.INT64;
|
||||
} else if ("float".equals(typeName)) {
|
||||
return TSDataType.FLOAT;
|
||||
} else if ("text".equals(typeName)) {
|
||||
return TSDataType.TEXT;
|
||||
} else if ("string".equals(typeName)) {
|
||||
return TSDataType.TEXT;
|
||||
} else {
|
||||
return TSDataType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据对象构建MeasurementSchemas
|
||||
*
|
||||
* @param obj 对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<MeasurementSchema> buildMeasurementSchemas(Object obj) {
|
||||
java.lang.reflect.Field[] fields = obj.getClass().getDeclaredFields();
|
||||
List<MeasurementSchema> schemaList = Arrays.stream(fields).map(field ->
|
||||
new MeasurementSchema(field.getName(),
|
||||
getTsDataTypeByString(
|
||||
field.getType().getName()
|
||||
))).
|
||||
collect(Collectors.toList());
|
||||
return schemaList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据对象构建MeasurementSchemaValuesDTO
|
||||
*
|
||||
* @param obj 对象
|
||||
* @return
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public MeasurementSchemaValuesDTO buildMeasurementSchemasAndValues(Object obj) {
|
||||
MeasurementSchemaValuesDTO measurementSchemaValuesDTO = new MeasurementSchemaValuesDTO();
|
||||
java.lang.reflect.Field[] fields = obj.getClass().getDeclaredFields();
|
||||
List<MeasurementSchema> schemaList = new ArrayList<>();
|
||||
List<Object> values = new ArrayList<>();
|
||||
List<Integer> valuesIsNullIndex = new ArrayList<>();
|
||||
int valueIndex = 0;
|
||||
for (java.lang.reflect.Field field : fields) {
|
||||
MeasurementSchema measurementSchema = new MeasurementSchema(field.getName(), getTsDataTypeByString(field.getType().getName()));
|
||||
schemaList.add(measurementSchema);
|
||||
Object value = field.get(obj);
|
||||
if (value == null) {
|
||||
valuesIsNullIndex.add(valueIndex);
|
||||
}
|
||||
values.add(value);
|
||||
valueIndex++;
|
||||
}
|
||||
measurementSchemaValuesDTO.setSchemaList(schemaList);
|
||||
measurementSchemaValuesDTO.setValues(values);
|
||||
return measurementSchemaValuesDTO;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.muyu.common.iotdb.config.IotDBSessionConfig
|
|
@ -0,0 +1,38 @@
|
|||
<?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>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<description>
|
||||
cloud-common-kafka kafka公共模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 项目公共核心模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- kafka客户端 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,102 @@
|
|||
package com.muyu.common.kafka.config;
|
||||
|
||||
import com.muyu.common.core.text.StrFormatter;
|
||||
import com.muyu.common.kafka.constant.KafkaConfigConstants;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author: wangXin
|
||||
* @Date 2024/9/28 20:32
|
||||
* @Description Kafka消费者配置
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaConsumerConfig {
|
||||
|
||||
/**
|
||||
* 服务端IP
|
||||
*/
|
||||
@Value("${kafka.consumer.bootstrap-servers-ip}")
|
||||
private String bootstrapServersIP;
|
||||
|
||||
/**
|
||||
* 服务端口号
|
||||
*/
|
||||
@Value("${kafka.consumer.bootstrap-servers-port}")
|
||||
private String bootstrapServersPort;
|
||||
|
||||
/**
|
||||
* 开启消费者偏移量
|
||||
*/
|
||||
@Value("${kafka.consumer.enable-auto-commit}")
|
||||
private Boolean enableAutoCommit;
|
||||
|
||||
/**
|
||||
* 自动提交时间间隔
|
||||
*/
|
||||
@Value("${kafka.consumer.auto-commit-interval}")
|
||||
private Integer autoCommitInterval;
|
||||
|
||||
/**
|
||||
* 自动重置偏移量
|
||||
*/
|
||||
@Value("${kafka.consumer.auto-offset-reset}")
|
||||
private String autoOffsetReset;
|
||||
|
||||
/**
|
||||
* 请求阻塞的最大时间
|
||||
*/
|
||||
@Value("${kafka.consumer.fetch-max-wait}")
|
||||
private Integer fetchMaxWait;
|
||||
|
||||
/**
|
||||
* 请求应答的最小字节数
|
||||
*/
|
||||
@Value("${kafka.consumer.fetch-min-size}")
|
||||
private Integer fetchMinSize;
|
||||
|
||||
/**
|
||||
* 心跳间隔时间
|
||||
*/
|
||||
@Value("${kafka.consumer.heartbeat-interval}")
|
||||
private Integer heartbeatInterval;
|
||||
|
||||
/**
|
||||
* 一次调用poll返回的最大记录条数
|
||||
*/
|
||||
@Value("${kafka.consumer.max-poll-records}")
|
||||
private Integer maxPollRecords;
|
||||
|
||||
/**
|
||||
* 指定消费组
|
||||
*/
|
||||
@Value("${kafka.consumer.group-id}")
|
||||
private String groupId;
|
||||
|
||||
/**
|
||||
* Kafka消费者初始化配置
|
||||
* @return Kafka消费者实例
|
||||
*/
|
||||
@Bean
|
||||
public KafkaConsumer<String, String> kafkaConsumer() {
|
||||
HashMap<String, Object> configs = new HashMap<>();
|
||||
configs.put(KafkaConfigConstants.BOOTSTRAP_SERVERS,
|
||||
StrFormatter.format("{}:{}", bootstrapServersIP, bootstrapServersPort));
|
||||
configs.put(KafkaConfigConstants.ENABLE_AUTO_COMMIT, enableAutoCommit);
|
||||
configs.put(KafkaConfigConstants.AUTO_COMMIT_INTERVAL, autoCommitInterval);
|
||||
configs.put(KafkaConfigConstants.AUTO_OFFSET_RESET, autoOffsetReset);
|
||||
configs.put(KafkaConfigConstants.FETCH_MAX_WAIT, fetchMaxWait);
|
||||
configs.put(KafkaConfigConstants.FETCH_MIN_SIZE, fetchMinSize);
|
||||
configs.put(KafkaConfigConstants.HEARTBEAT_INTERVAL, heartbeatInterval);
|
||||
configs.put(KafkaConfigConstants.MAX_POLL_RECORDS, maxPollRecords);
|
||||
configs.put(KafkaConfigConstants.GROUP_ID, groupId);
|
||||
Deserializer<String> keyDeserializer = new StringDeserializer();
|
||||
Deserializer<String> valueDeserializer = new StringDeserializer();
|
||||
return new KafkaConsumer<>(configs, keyDeserializer, valueDeserializer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.muyu.common.kafka.config;
|
||||
|
||||
import com.muyu.common.core.text.StrFormatter;
|
||||
import com.muyu.common.kafka.constant.KafkaConfigConstants;
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.common.serialization.Serializer;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @Author: wangXin
|
||||
* @Date 2024/9/28 16:35
|
||||
* @Description Kafka生产者配置
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaProducerConfig {
|
||||
|
||||
/**
|
||||
* 服务端IP
|
||||
*/
|
||||
@Value("${kafka.producer.bootstrap-servers-ip}")
|
||||
private String bootstrapServersIP;
|
||||
|
||||
/**
|
||||
* 服务端口号
|
||||
*/
|
||||
@Value("${kafka.producer.bootstrap-servers-port}")
|
||||
private String bootstrapServersPort;
|
||||
|
||||
/**
|
||||
* 重试次数
|
||||
*/
|
||||
@Value("${kafka.producer.retries}")
|
||||
private Integer retries;
|
||||
|
||||
/**
|
||||
* 默认批量大小
|
||||
*/
|
||||
@Value("${kafka.producer.batch-size}")
|
||||
private Integer batchSize;
|
||||
|
||||
/**
|
||||
* 总内存字节数
|
||||
*/
|
||||
@Value("${kafka.producer.buffer-memory}")
|
||||
private Integer bufferMemory;
|
||||
|
||||
/**
|
||||
* 偏移量
|
||||
*/
|
||||
@Value("${kafka.producer.acks}")
|
||||
private String acks;
|
||||
|
||||
/**
|
||||
* Kafka生产者初始化配置
|
||||
* @return kafka生产者实例
|
||||
*/
|
||||
@Bean
|
||||
public KafkaProducer<String, String> kafkaProducer() {
|
||||
HashMap<String, Object> configs = new HashMap<>();
|
||||
configs.put(KafkaConfigConstants.BOOTSTRAP_SERVERS,
|
||||
StrFormatter.format("{}:{}", bootstrapServersIP, bootstrapServersPort));
|
||||
configs.put(KafkaConfigConstants.RETRIES, retries);
|
||||
configs.put(KafkaConfigConstants.BATCH_SIZE, batchSize);
|
||||
configs.put(KafkaConfigConstants.BUFFER_MEMORY, bufferMemory);
|
||||
configs.put(KafkaConfigConstants.ACKS, acks);
|
||||
Serializer<String> keySerializer = new StringSerializer();
|
||||
Serializer<String> valueSerializer = new StringSerializer();
|
||||
return new KafkaProducer<>(configs, keySerializer, valueSerializer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.muyu.common.kafka.constant;
|
||||
|
||||
/**
|
||||
* @Author: wangXin
|
||||
* @Date 2024/9/28 20:07
|
||||
* @Description Kafka配置通用常量
|
||||
*/
|
||||
public class KafkaConfigConstants {
|
||||
|
||||
/**
|
||||
* 服务端ip+端口号
|
||||
*/
|
||||
public static final String BOOTSTRAP_SERVERS = "bootstrap.servers";
|
||||
|
||||
/**
|
||||
* 重试次数
|
||||
*/
|
||||
public static final String RETRIES = "retries";
|
||||
|
||||
/**
|
||||
* 默认批量大小
|
||||
*/
|
||||
public static final String BATCH_SIZE = "batch.size";
|
||||
|
||||
/**
|
||||
* 总内存字节数
|
||||
*/
|
||||
public static final String BUFFER_MEMORY = "buffer-memory";
|
||||
|
||||
/**
|
||||
* 偏移量
|
||||
*/
|
||||
public static final String ACKS = "acks";
|
||||
|
||||
/**
|
||||
* 开启消费者偏移量
|
||||
*/
|
||||
public static final String ENABLE_AUTO_COMMIT = "enable.auto.commit";
|
||||
|
||||
/**
|
||||
* 自动提交时间间隔
|
||||
*/
|
||||
public static final String AUTO_COMMIT_INTERVAL = "auto.commit.interval";
|
||||
|
||||
/**
|
||||
* 自动重置偏移量
|
||||
*/
|
||||
public static final String AUTO_OFFSET_RESET = "auto.offset.reset";
|
||||
|
||||
/**
|
||||
* 请求阻塞的最大时间
|
||||
*/
|
||||
public static final String FETCH_MAX_WAIT = "fetch.max.wait";
|
||||
|
||||
/**
|
||||
* 请求应答的最小字节数
|
||||
*/
|
||||
public static final String FETCH_MIN_SIZE = "fetch.min.size";
|
||||
|
||||
/**
|
||||
* 心跳间隔时间
|
||||
*/
|
||||
public static final String HEARTBEAT_INTERVAL = "heartbeat-interval";
|
||||
|
||||
/**
|
||||
* 一次调用poll返回的最大记录条数
|
||||
*/
|
||||
public static final String MAX_POLL_RECORDS = "max.poll.records";
|
||||
|
||||
/**
|
||||
* 指定消费组
|
||||
*/
|
||||
public static final String GROUP_ID = "group.id";
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.common.kafka.constant;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @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.KafkaProducerConfig
|
||||
com.muyu.common.kafka.config.KafkaConsumerConfig
|
|
@ -17,6 +17,10 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<description>
|
||||
cloud-common-rabbit 消息队列服务
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- rabbitMq 消息队列 -->
|
||||
|
@ -28,7 +32,7 @@
|
|||
<!-- 项目公共核心 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 消息发送确认配置
|
||||
* 消息发送到交换机的回调
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
rabbitTemplate.setConfirmCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 交换机不管是否收到消息的一个回调方法
|
||||
*
|
||||
* @param correlationData 消息相关数据
|
||||
* @param ack 交换机是否收到消息
|
||||
* @param cause 失败原因
|
||||
*/
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
if (!ack) {
|
||||
String exchange = correlationData.getReturned().getExchange();
|
||||
String message = correlationData.getReturned().getMessage().getBody().toString();
|
||||
// 发送异常
|
||||
log.error("消息:{},发送到交换机:{}失败,原因是:{}", message, exchange, cause);
|
||||
// TODO 可以把异常信息 以及 消息的内容直接添加到 MYSQL
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,14 @@
|
|||
package com.muyu.common.rabbit;
|
||||
package com.muyu.common.rabbit.config;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Configuration
|
||||
public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer {
|
||||
|
||||
|
@ -16,7 +17,7 @@ public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit
|
|||
}
|
||||
|
||||
//以下配置RabbitMQ消息服务
|
||||
@Autowired
|
||||
@Resource
|
||||
public ConnectionFactory connectionFactory;
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.ReturnedMessage;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 消息发送到队列的确认
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
/**
|
||||
* @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
rabbitTemplate.setReturnsCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息发送失败 则会执行这个方法
|
||||
*
|
||||
* @param returnedMessage the returned message and metadata.
|
||||
*/
|
||||
@Override
|
||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
log.error("消息:{},被交换机:{} 回退!退回原因为:{}",
|
||||
returnedMessage.getMessage().toString(), returnedMessage.getExchange(), returnedMessage.getReplyText());
|
||||
// TODO 回退了所有的信息,可做补偿机制
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.common.rabbit.constants;
|
||||
|
||||
/**
|
||||
* rabbit常量
|
||||
* @Author: WangXin
|
||||
* @date: 2024/7/10
|
||||
* @Description: rabbit常量
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
public class RabbitConstants {
|
||||
|
||||
public final static String GO_ONLINE_QUEUE= "GoOnline";
|
||||
|
||||
public final static String DOWNLINE_QUEUE= "Downline";
|
||||
}
|
|
@ -1 +1,3 @@
|
|||
com.muyu.common.rabbit.RabbitListenerConfigurer
|
||||
com.muyu.common.rabbit.config.RabbitListenerConfigurer
|
||||
com.muyu.common.rabbit.config.ConfirmCallbackConfig
|
||||
com.muyu.common.rabbit.config.ReturnCallbackConfig
|
||||
|
|
|
@ -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,111 @@
|
|||
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.many.datasource.constents.DatasourceContent;
|
||||
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.constant.SecurityConstants;
|
||||
import com.muyu.common.core.constant.UserConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
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.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: 多数据源
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Log4j2
|
||||
@Configuration
|
||||
@AutoConfiguration(before = MybatisPlusAutoConfiguration.class)
|
||||
public class ManyDataSource implements ApplicationRunner {
|
||||
|
||||
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
RemoteUserService RemoteUserService = SpringUtils.getBean(RemoteUserService.class);
|
||||
Result<List<String>> listResult = RemoteUserService.selectFirmDatabaseList(SecurityConstants.INNER);
|
||||
if (listResult==null){
|
||||
throw new SaaSException("saas远调数据源错误");
|
||||
}
|
||||
List<String> data = listResult.getData();
|
||||
if (listResult.getCode() ==Result.SUCCESS && data !=null){
|
||||
List<EntInfo> list = new ArrayList<>();
|
||||
for (String row : data) {
|
||||
list.add(
|
||||
EntInfo.builder()
|
||||
.entCode(row)
|
||||
.ip(DatasourceContent.IP)
|
||||
.port(DatasourceContent.PORT)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
return list;
|
||||
}else {
|
||||
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(data));
|
||||
throw new RuntimeException("远调数据源错误,远调--》 companyList ");
|
||||
}
|
||||
}
|
||||
// private List<EntInfo> dataPrimarySourceInfoList(){
|
||||
// List<EntInfo> list = new ArrayList<>();
|
||||
// list.add(
|
||||
// EntInfo.builder()
|
||||
// .entCode()
|
||||
// .ip(DatasourceContent.IP)
|
||||
// .port(DatasourceContent.PORT)
|
||||
// .build()
|
||||
// );
|
||||
// return list;
|
||||
// }
|
||||
|
||||
@Bean
|
||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||
// 企业列表 企业CODE,端口,IP
|
||||
Map<Object, Object> dataSourceMap = new HashMap<>();
|
||||
dataSourceInfoList()
|
||||
.stream()
|
||||
.map(entInfo -> DataSourceInfo.hostAndPortBuild(entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort()))
|
||||
.forEach(dataSourceInfo -> {
|
||||
dataSourceMap.put(dataSourceInfo.getKey(), druidDataSourceFactory.create(dataSourceInfo));
|
||||
});
|
||||
//设置动态数据源
|
||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||
// dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
|
||||
dynamicDataSource.setTargetDataSources(dataSourceMap);
|
||||
//将数据源信息备份在defineTargetDataSources中
|
||||
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||
for (EntInfo entInfo : dataSourceInfoList()) {
|
||||
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(
|
||||
entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort()
|
||||
);
|
||||
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
||||
dynamicDataSource.put(dataSourceInfo.getKey(), druidDataSource);
|
||||
log.info("存储数据连接池为:key:{}",dataSourceInfo.getKey());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 = "wx0713101x";
|
||||
|
||||
public final static String IP = "127.0.0.1";
|
||||
|
||||
public final static Integer PORT = 3307;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.muyu.cloud.common.many.datasource.domain.model;
|
||||
|
||||
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
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: 根据传递的数据源信息测试数据库连接
|
||||
*/
|
||||
public DruidDataSource create(DataSourceInfo dataSourceInfo) {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setUrl(dataSourceInfo.getUrl());
|
||||
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());
|
||||
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,55 @@
|
|||
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 org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 动态数据源
|
||||
* 调用AddDefineDataSource组件的addDefineDynamicDataSource()方法,获取原来targetdatasources的map,并将新的数据源信息添加到map中,并替换targetdatasources中的map
|
||||
* 切换数据源时可以使用@DataSource(value = "数据源名称"),或者DynamicDataSourceContextHolder.setContextKey("数据源名称")
|
||||
* @author Dongzl
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@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) {
|
||||
defineTargetDataSources.put(key, value);
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* 决定当前线程使用哪个数据源
|
||||
*/
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DynamicDataSourceHolder.getDynamicDataSourceKey();
|
||||
}
|
||||
}
|
|
@ -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,25 @@
|
|||
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;
|
||||
}
|
|
@ -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,66 @@
|
|||
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.utils.ServletUtils;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
||||
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/3
|
||||
* @Description: SAAS拦截器
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Log4j2
|
||||
public class SaaSInterceptor implements AsyncHandlerInterceptor {
|
||||
|
||||
private Boolean flag = false;
|
||||
|
||||
/**
|
||||
* 之前
|
||||
*/
|
||||
@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);
|
||||
if (SaaSKey == null) {
|
||||
throw new SaaSException("SaaS非法访问");
|
||||
}
|
||||
if (SaaSKey.equals("-")){
|
||||
log.info("使用 [ nacos ] 配置数据库 ");
|
||||
flag = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
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 {
|
||||
if (flag){
|
||||
DynamicDataSourceHolder.removeDynamicDataSourceKey();
|
||||
flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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[] excludeUrls = {"/login", "/logout", "/refresh"};
|
||||
|
||||
@Override
|
||||
public void addInterceptors (InterceptorRegistry registry) {
|
||||
registry.addInterceptor(getHeaderInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(excludeUrls)
|
||||
.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
|
|
@ -25,5 +25,9 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/10/2
|
||||
* @Description 数据源信息
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tag(name = "数据源信息")
|
||||
@TableName("sys_firm_datasource")
|
||||
public class SysFirmDatasource {
|
||||
|
||||
/**
|
||||
* 数据源Id
|
||||
*/
|
||||
@Schema(name = "数据源Id")
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
/**
|
||||
* 数据源url
|
||||
*/
|
||||
@Schema(name = "数据源url")
|
||||
private String datasourceUrl;
|
||||
/**
|
||||
* 数据源用户名
|
||||
*/
|
||||
@Schema(name = "数据源用户名")
|
||||
private String username;
|
||||
/**
|
||||
* 数据源密码
|
||||
*/
|
||||
@Schema(name = "数据源密码")
|
||||
private String password;
|
||||
/**
|
||||
* 数据源IP
|
||||
*/
|
||||
@Schema(name = "数据源IP")
|
||||
private String ip;
|
||||
/**
|
||||
* 数据源端口号
|
||||
*/
|
||||
@Schema(name = "数据源端口号")
|
||||
private Integer port;
|
||||
/**
|
||||
* 数据源库名
|
||||
*/
|
||||
@Schema(name = "数据源库名")
|
||||
private String databaseName;
|
||||
}
|
|
@ -9,6 +9,8 @@ import com.muyu.common.system.domain.LoginUser;
|
|||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
|
@ -37,4 +39,7 @@ public interface RemoteUserService {
|
|||
*/
|
||||
@PostMapping("/user/register")
|
||||
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
@GetMapping("/")
|
||||
Result<List<String>> selectFirmDatabaseList(@RequestHeader(SecurityConstants.FROM_SOURCE) String inner);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
|
@ -31,6 +33,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<String>> selectFirmDatabaseList(String inner) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,11 @@
|
|||
<module>cloud-common-system</module>
|
||||
<module>cloud-common-xxl</module>
|
||||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-cache</module>
|
||||
<module>cloud-common-kafka</module>
|
||||
<module>cloud-common-iotdb</module>
|
||||
<module>cloud-common-caffeine</module>
|
||||
<module>cloud-common-saas</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package com.muyu;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
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 javax.xml.crypto.Data;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @className: SysCarFaultApplication ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/21 11:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class SysCarFaultApplication {
|
||||
public static void main (String[] args) throws ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+08"));
|
||||
String format = simpleDateFormat.format(new Date());
|
||||
System.out.println("故障模块启动成功"+format);
|
||||
SpringApplication.run(SysCarFaultApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.service.CarTypeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @className: CarTypeController ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@RequestMapping("/cartype")
|
||||
@RestController
|
||||
public class CarTypeController {
|
||||
|
||||
@Autowired
|
||||
private CarTypeService carTypeService;
|
||||
|
||||
/**
|
||||
* 车辆类型
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "车辆类型",description = "车辆类型信息")
|
||||
public Result carTypeList(){
|
||||
return Result.success(carTypeService.selectcarType());
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.domain.req.FaultCodeAddReq;
|
||||
import com.muyu.fault.domain.req.FaultCodeListReq;
|
||||
import com.muyu.fault.domain.req.FaultCodeUpdReq;
|
||||
import com.muyu.fault.domain.resp.FaultCodeTotalListResp;
|
||||
import com.muyu.fault.service.FaultCodeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @className: CarTypeController ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 车辆故障码
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/faultcode")
|
||||
public class FaultCodeController {
|
||||
|
||||
@Autowired
|
||||
private FaultCodeService faultCodeService;
|
||||
|
||||
/**
|
||||
* 故障码展示(仅故障码单表)
|
||||
* @param faultCodeListReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(path = "/list")
|
||||
@Operation(summary = "故障码列表(单)",description = "展示故障码信息")
|
||||
public Result<FaultCodeTotalListResp> selectlist(@Validated @RequestBody FaultCodeListReq faultCodeListReq){
|
||||
return Result.success(faultCodeService.selectlist(faultCodeListReq));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 故障码展示(故障码联查)
|
||||
* @param faultCodeListReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultcodelist")
|
||||
@Operation(summary = "故障码列表(多)",description = "展示故障码信息")
|
||||
public Result<FaultCodeTotalListResp> selectfaultcodelist(@Validated @RequestBody FaultCodeListReq faultCodeListReq){
|
||||
return Result.success(faultCodeService.selectfaultcodelist(faultCodeListReq));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增故障码
|
||||
* @param faultCodeAddReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultcodeadd")
|
||||
@Operation(summary = "新增故障码",description = "新增故障码信息")
|
||||
public Result insertfaultcode(@Validated @RequestBody FaultCodeAddReq faultCodeAddReq){
|
||||
faultCodeService.insert(faultCodeAddReq);
|
||||
return Result.success(null,"新增成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改故障码
|
||||
* @param faultCodeUpdReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultcodeupd")
|
||||
@Operation(summary = "修改故障码",description = "修改故障码信息")
|
||||
public Result updfaultcode(@Validated @RequestBody FaultCodeUpdReq faultCodeUpdReq){
|
||||
faultCodeService.upd(faultCodeUpdReq);
|
||||
return Result.success(null,"修改成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除故障码
|
||||
* @param messageTypeId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultcodedel/{messageTypeId}")
|
||||
@Operation(summary = "删除故障码",description = "删除故障码信息")
|
||||
public Result delfaultcode(@PathVariable("messageTypeId") Integer messageTypeId){
|
||||
faultCodeService.del(messageTypeId);
|
||||
return Result.success(null,"删除成功");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.domain.FaultCondition;
|
||||
import com.muyu.fault.domain.req.FaultConditionAddReq;
|
||||
import com.muyu.fault.domain.req.FaultConditionListReq;
|
||||
import com.muyu.fault.domain.req.FaultConditionUpdReq;
|
||||
import com.muyu.fault.service.FaultConditionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className: CarTypeController ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/faultcondition")
|
||||
public class FaultConditionController {
|
||||
|
||||
@Autowired
|
||||
private FaultConditionService faultConditionService;
|
||||
|
||||
|
||||
/**
|
||||
* 故障规则
|
||||
* @param faultConditionListReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "故障规则列表展示",description = "故障规则列表展示")
|
||||
public Result getfaultrulelist(@RequestBody @Validated FaultConditionListReq faultConditionListReq){
|
||||
return Result.success(faultConditionService.getfaultrulelist(faultConditionListReq));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 故障规则添加
|
||||
* @param faultConditionAddReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultconditionadd")
|
||||
@Operation(summary = "添加规则",description = "添加故障规则")
|
||||
public Result faultconditionadd(@RequestBody FaultConditionAddReq faultConditionAddReq){
|
||||
//判断车辆类型是否已存在所对应的故障规则
|
||||
List<FaultCondition> faultConditionList = faultConditionService.selectBytypeAndlabel(faultConditionAddReq);
|
||||
if (faultConditionList.size()>0){
|
||||
return Result.error("此车辆类型已存在所对应的故障规则,无需重新制定,可在原规则上进行修改");
|
||||
}
|
||||
faultConditionService.save(FaultCondition.faultConditionadd(faultConditionAddReq));
|
||||
return Result.success(null,"规则制定成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 故障规则修改
|
||||
* @param
|
||||
* @param faultConditionUpdReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultconditionupd")
|
||||
@Operation(summary = "修改规则",description = "修改故障规则")
|
||||
public Result faultconditionupd(
|
||||
@RequestBody @Validated FaultConditionUpdReq faultConditionUpdReq){
|
||||
faultConditionService.updateById(FaultCondition.faultConditionupd(faultConditionUpdReq,()->faultConditionUpdReq.getCarconditionId()));
|
||||
return Result.success(null,"规则修改成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 故障规则删除
|
||||
* @param carconditionId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/faultconditiondel/{carconditionId}")
|
||||
@Operation(summary = "删除规则",description = "删除故障规则")
|
||||
public Result faultconditiondel(@PathVariable("carconditionId") long carconditionId){
|
||||
faultConditionService.removeById(carconditionId);
|
||||
return Result.success(null,"规则删除成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
import com.muyu.fault.service.FaultDetectionStrategyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @className: FaultDetectionStrategyController ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 车辆故障码
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/faultdetectionstrategy")
|
||||
public class FaultDetectionStrategyController {
|
||||
|
||||
@Autowired
|
||||
private FaultDetectionStrategyService faultDetectionStrategyService;
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.service.FaultLabelService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 故障码分类
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/faultlabel")
|
||||
public class FaultLabelController {
|
||||
|
||||
@Autowired
|
||||
private FaultLabelService faultLabelService;
|
||||
|
||||
|
||||
/**
|
||||
* 故障名称
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "故障名称查询",description = "故障名称信息")
|
||||
public Result findfaulttype(){
|
||||
return Result.success(faultLabelService.select());
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.domain.req.FaultLogListReq;
|
||||
import com.muyu.fault.service.FaultLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/faultlog")
|
||||
public class FaultLogController {
|
||||
@Autowired
|
||||
private FaultLogService faultLogService;
|
||||
|
||||
|
||||
/**
|
||||
* 故障日志列表
|
||||
* @param faultLogListReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "故障日志列表",description = "故障日志列表展示")
|
||||
public Result selectfaultlog(@Validated @RequestBody FaultLogListReq faultLogListReq){
|
||||
return Result.success(faultLogService.selectfaultlog(faultLogListReq));
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.domain.CarFaultRule;
|
||||
import com.muyu.fault.domain.FaultRule;
|
||||
import com.muyu.fault.service.FaultRuleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/faultrule")
|
||||
public class FaultRuleController {
|
||||
|
||||
@Autowired
|
||||
private FaultRuleService faultRuleService;
|
||||
|
||||
|
||||
/**
|
||||
* 车辆故障检测
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/check-faults")
|
||||
@Operation(summary = "检查故障",description = "进行故障检查")
|
||||
public Result checkfault(@Validated FaultRule faultRule){
|
||||
String checkfaults = faultRuleService.checkfaults(faultRule);
|
||||
return Result.success(checkfaults);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/cheakfaults")
|
||||
@Operation(summary = "故障参数匹配检查",description = "获取报文数据与故障参数进行比较")
|
||||
public Result cheakfaults(@Validated @RequestBody CarFaultRule carFaultRule){
|
||||
// faultRuleService.checkfaults(carFaultRule);
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测
|
||||
*/
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.service.FaultTypeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 故障码分类
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/faulttype")
|
||||
public class FaultTypeController {
|
||||
|
||||
@Autowired
|
||||
private FaultTypeService faultTypeService;
|
||||
|
||||
|
||||
/**
|
||||
* 故障码分类查询
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "故障码分类查询",description = "故障码分类信息")
|
||||
public Result findfaulttype(){
|
||||
return Result.success(faultTypeService.select());
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.fault.domain.message.Message;
|
||||
import com.muyu.fault.domain.message.MessageReq;
|
||||
import com.muyu.fault.domain.message.MessageSendReq;
|
||||
import com.muyu.fault.service.MessageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/message")
|
||||
public class MessageController {
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
|
||||
/**
|
||||
* 消息发送
|
||||
* @param messageSendReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/sendmessage")
|
||||
@Operation(summary = "发送消息",description = "站内信消息发送")
|
||||
public Result sendmessage(@Validated MessageSendReq messageSendReq){
|
||||
messageService.sendmessage(messageSendReq);
|
||||
return Result.success(null,"发送成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息查看
|
||||
* @param messageReq
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/messagelist")
|
||||
@Operation(summary = "消息查看(能根据登录人新的信息查看当前登录人的消息栏)",description = "消息查看")
|
||||
public Result selectmessage(@Validated @RequestBody MessageReq messageReq){
|
||||
return Result.success(messageService.selectmessage(messageReq));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看消息改变状态
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/changestatus")
|
||||
@Operation(summary = "状态改变",description = "状态改变")
|
||||
public Result changestatus(@RequestBody Message message){
|
||||
messageService.changestatus(message);
|
||||
return Result.success(null,"成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查看未读的消息
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/unread")
|
||||
@Operation(summary = "查看未读的消息",description = "查看未读的消息")
|
||||
public Result unread(){
|
||||
return Result.success(messageService.unread());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package com.muyu.fault.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.fault.domain.SysCarFault;
|
||||
import com.muyu.fault.service.ISysCarFaultService;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 车辆故障Controller
|
||||
*
|
||||
* @author Yang鹏
|
||||
* @date 2024-09-18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/fault")
|
||||
public class SysCarFaultController extends BaseController
|
||||
{
|
||||
@Resource
|
||||
private ISysCarFaultService sysCarFaultService;
|
||||
|
||||
/**
|
||||
* 查询车辆故障列表
|
||||
*/
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<SysCarFault>> list(SysCarFault sysCarFault)
|
||||
{
|
||||
startPage();
|
||||
List<SysCarFault> list = sysCarFaultService.selectSysCarFaultList(sysCarFault);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出车辆故障列表
|
||||
*/
|
||||
@RequiresPermissions("syscarfault:fault:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysCarFault sysCarFault)
|
||||
{
|
||||
List<SysCarFault> list = sysCarFaultService.selectSysCarFaultList(sysCarFault);
|
||||
ExcelUtil<SysCarFault> util = new ExcelUtil<SysCarFault>(SysCarFault.class);
|
||||
util.exportExcel(response, list, "车辆故障数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车辆故障详细信息
|
||||
*/
|
||||
@RequiresPermissions("syscarfault:fault:query")
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result<List<SysCarFault>> getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(sysCarFaultService.selectSysCarFaultById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增车辆故障
|
||||
*/
|
||||
@RequiresPermissions("syscarfault:fault:add")
|
||||
@PostMapping
|
||||
public Result<Integer> add(
|
||||
@Validated @RequestBody SysCarFault sysCarFault)
|
||||
{
|
||||
if (sysCarFaultService.checkIdUnique(sysCarFault)) {
|
||||
return error("新增 车辆故障 '" + sysCarFault + "'失败,车辆故障已存在");
|
||||
}
|
||||
sysCarFault.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(sysCarFaultService.save(sysCarFault));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改车辆故障
|
||||
*/
|
||||
@RequiresPermissions("syscarfault:fault:edit")
|
||||
@PutMapping
|
||||
public Result<Integer> edit(
|
||||
@Validated @RequestBody SysCarFault sysCarFault)
|
||||
{
|
||||
if (!sysCarFaultService.checkIdUnique(sysCarFault)) {
|
||||
return error("修改 车辆故障 '" + sysCarFault + "'失败,车辆故障不存在");
|
||||
}
|
||||
sysCarFault.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(sysCarFaultService.updateById(sysCarFault));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除车辆故障
|
||||
*/
|
||||
@RequiresPermissions("syscarfault:fault:remove")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result<Integer> remove(@PathVariable("ids") Long[] ids)
|
||||
{
|
||||
sysCarFaultService.removeBatchByIds(Arrays.asList(ids));
|
||||
return success();
|
||||
}
|
||||
}
|
|
@ -1,206 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
/**
|
||||
* @className: CarFaultRule ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class CarFaultRule {/**
|
||||
* VIN码VIN码VIN码
|
||||
*/
|
||||
private String vin;
|
||||
/**
|
||||
* 时间戳时间戳时间戳
|
||||
*/
|
||||
private long timestamp;
|
||||
/**
|
||||
* 经度经度经度
|
||||
*/
|
||||
private double longitude;
|
||||
/**
|
||||
* 纬度纬度纬度
|
||||
*/
|
||||
private double latitude;
|
||||
/**
|
||||
* 车速车速车速
|
||||
*/
|
||||
private double speed;
|
||||
/**
|
||||
* 总里程总里程总里程
|
||||
*/
|
||||
private long TM;
|
||||
/**
|
||||
* 总电压总电压总电压
|
||||
*/
|
||||
private double TV;
|
||||
/**
|
||||
* 总电流总电流总电流
|
||||
*/
|
||||
private double CC;
|
||||
/**
|
||||
* 绝缘电阻绝缘电阻绝缘电阻
|
||||
*/
|
||||
private double IR;
|
||||
/**
|
||||
* 档位档位档位
|
||||
*/
|
||||
private String GP;
|
||||
/**
|
||||
* 加速踏板行程值加速踏板行程值加速踏板行程值
|
||||
*/
|
||||
private double APTV;
|
||||
/**
|
||||
* 制动踏板行程值制动踏板行程值制动踏板行程值
|
||||
*/
|
||||
private double BPTV;
|
||||
/**
|
||||
* 燃料消耗率燃料消耗率燃料消耗率
|
||||
*/
|
||||
private double SFC;
|
||||
/**
|
||||
* 电机控制器温度电机控制器温度电机控制器温度
|
||||
*/
|
||||
private double MCT;
|
||||
/**
|
||||
* 电机转速电机转速电机转速
|
||||
*/
|
||||
private int MS;
|
||||
/**
|
||||
* 电机转矩电机转矩电机转矩
|
||||
*/
|
||||
private double MTO;
|
||||
/**
|
||||
* 电机温度电机温度电机温度
|
||||
*/
|
||||
private double MTE;
|
||||
/**
|
||||
* 电机电压电机电压电机电压
|
||||
*/
|
||||
private double MV;
|
||||
/**
|
||||
* 电机电流电机电流电机电流
|
||||
*/
|
||||
private double MC;
|
||||
/**
|
||||
* 动力电池剩余电量SOC动力电池剩余电量SOC动力电池剩余电量SOC
|
||||
*/
|
||||
private double PBRSOC;
|
||||
/**
|
||||
* 当前状态允许的最大反馈功率当前状态允许的最大反馈功率当前状态允许的最大反馈功率
|
||||
*/
|
||||
private double MACSFP;
|
||||
/**
|
||||
* 当前状态允许最大放电功率当前状态允许最大放电功率当前状态允许最大放电功率
|
||||
*/
|
||||
private double CSATMDP;
|
||||
/**
|
||||
* BMS自检计数器BMS自检计数器BMS自检计数器
|
||||
*/
|
||||
private int BMS;
|
||||
/**
|
||||
* 动力电池充放电电流动力电池充放电电流动力电池充放电电流
|
||||
*/
|
||||
private double CADC;
|
||||
/**
|
||||
* 动力电池负载端总电压V3动力电池负载端总电压V3动力电池负载端总电压V3
|
||||
*/
|
||||
private double PBLETVV3;
|
||||
/**
|
||||
* 单次最大电压单次最大电压单次最大电压
|
||||
*/
|
||||
private double SMV;
|
||||
/**
|
||||
* 单体电池最低电压单体电池最低电压单体电池最低电压
|
||||
*/
|
||||
private double MVOAB;
|
||||
/**
|
||||
* 单体电池最高温度单体电池最高温度单体电池最高温度
|
||||
*/
|
||||
private double MAXBT;
|
||||
/**
|
||||
* 单体电池最低温度单体电池最低温度单体电池最低温度
|
||||
*/
|
||||
private double MINBT;
|
||||
/**
|
||||
* 动力电池可用容量动力电池可用容量动力电池可用容量
|
||||
*/
|
||||
private double PBAC;
|
||||
/**
|
||||
* 车辆状态车辆状态车辆状态
|
||||
*/
|
||||
private String VS;
|
||||
/**
|
||||
* 充电状态充电状态充电状态
|
||||
*/
|
||||
private String CS;
|
||||
/**
|
||||
* 运行状态运行状态运行状态
|
||||
*/
|
||||
private String RS;
|
||||
/**
|
||||
* SOCSOCSOC
|
||||
*/
|
||||
private double SOC;
|
||||
/**
|
||||
* 可充电储能装置工作状态可充电储能装置工作状态可充电储能装置工作状态
|
||||
*/
|
||||
private String RESDWC;
|
||||
/**
|
||||
* EASEASEAS
|
||||
*/
|
||||
private String EAS;
|
||||
/**
|
||||
* PTCPTCPTC
|
||||
*/
|
||||
private String PTC;
|
||||
/**
|
||||
* EPSEPSEPS
|
||||
*/
|
||||
private String EPS;
|
||||
/**
|
||||
* ABSABSABS
|
||||
*/
|
||||
private String ABS;
|
||||
/**
|
||||
* MCUMCUMCU
|
||||
*/
|
||||
private String MCU;
|
||||
/**
|
||||
* 动力电池加热状态动力电池加热状态动力电池加热状态
|
||||
*/
|
||||
private String PBHS;
|
||||
/**
|
||||
* 动力电池当前状态动力电池当前状态动力电池当前状态
|
||||
*/
|
||||
private String PBCS;
|
||||
/**
|
||||
* 动力电池保温状态动力电池保温状态动力电池保温状态
|
||||
*/
|
||||
private String PBIS;
|
||||
/**
|
||||
* DCDCDCDCDCDC
|
||||
*/
|
||||
private String DCDC;
|
||||
/**
|
||||
* CHGCHGCHG
|
||||
*/
|
||||
private String CHG;
|
||||
/**
|
||||
* 校验位校验位校验位
|
||||
*/
|
||||
private byte CHB;
|
||||
/**
|
||||
* 截止位截止位截止位
|
||||
*/
|
||||
private byte CUB;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: CarType ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:01 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_type",autoResultMap = true)
|
||||
public class CarType {
|
||||
/**
|
||||
* 车辆类型ID
|
||||
*/
|
||||
private long carTypeId;
|
||||
/**
|
||||
* 车辆类型名
|
||||
*/
|
||||
private String carTypeName;
|
||||
/**
|
||||
* 车辆规则外键ID
|
||||
*/
|
||||
private long carTypeRules;
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.fault.domain.req.FaultCodeAddReq;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: FaultCode ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:21 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_faultcode", autoResultMap = true)
|
||||
public class FaultCode {
|
||||
/**
|
||||
* 故障码Id
|
||||
*/
|
||||
@TableId(value = "faultcode_id", type = IdType.AUTO)
|
||||
private long faultcodeId;
|
||||
/**
|
||||
* 故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
* 故障码
|
||||
*/
|
||||
private String faultcodeNumber;
|
||||
/**
|
||||
* 故障组
|
||||
*/
|
||||
private String faultGroup;
|
||||
/**
|
||||
* 故障位
|
||||
*/
|
||||
private String faultBit;
|
||||
/**
|
||||
* 故障值
|
||||
*/
|
||||
private String faultValue;
|
||||
/**
|
||||
* 是否警告
|
||||
*/
|
||||
private Integer isWarning;
|
||||
|
||||
private String faulttypeName;
|
||||
private String messageTypeName;
|
||||
private String messageTypeCode;
|
||||
private String messageTypeBelongs;
|
||||
|
||||
public static FaultCode addfaultcode(FaultCodeAddReq faultCodeAddReq) {
|
||||
return FaultCode.builder()
|
||||
.faultcodeId(0)
|
||||
.messageTypeId(faultCodeAddReq.getMessageTypeId())
|
||||
.faultcodeNumber(faultCodeAddReq.getFaultcodeNumber())
|
||||
.faultGroup(faultCodeAddReq.getFaultGroup())
|
||||
.faultBit(faultCodeAddReq.getFaultBit())
|
||||
.faultValue(faultCodeAddReq.getFaultValue())
|
||||
.isWarning(faultCodeAddReq.getIsWarning())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.fault.domain.req.FaultConditionAddReq;
|
||||
import com.muyu.fault.domain.req.FaultConditionUpdReq;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @className: FaultCondition ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:07 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_fault_condition",autoResultMap = true)
|
||||
public class FaultCondition {
|
||||
/**
|
||||
* 故障规则表Id
|
||||
*/
|
||||
@TableId(value = "carcondition_id",type = IdType.AUTO)
|
||||
private long carconditionId;
|
||||
/**
|
||||
* 车辆类型Id
|
||||
*/
|
||||
private long carTypeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
* 故障条件
|
||||
*/
|
||||
private String faultconditionIdentification;
|
||||
/**
|
||||
* 故障规则参数
|
||||
*/
|
||||
private BigDecimal faultconditionParameter;
|
||||
/**
|
||||
* 车辆类型名称
|
||||
*/
|
||||
private String carTypeName;
|
||||
/**
|
||||
* 故障名称
|
||||
*/
|
||||
private String messageTypeName;
|
||||
/**
|
||||
* 报文编码
|
||||
*/
|
||||
private String messageTypeCode;
|
||||
|
||||
|
||||
public static FaultCondition faultConditionadd(FaultConditionAddReq faultConditionAddReq){
|
||||
return FaultCondition.builder()
|
||||
.carTypeId(faultConditionAddReq.getCarTypeId())
|
||||
.messageTypeId(faultConditionAddReq.getMessageTypeId())
|
||||
.faultconditionIdentification(faultConditionAddReq.getFaultconditionIdentification())
|
||||
.faultconditionParameter(faultConditionAddReq.getFaultconditionParameter())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static FaultCondition faultConditionupd(FaultConditionUpdReq faultConditionUpdReq, Supplier<Long> idSupplier){
|
||||
return FaultCondition.builder()
|
||||
.carconditionId(faultConditionUpdReq.getCarconditionId())
|
||||
.carTypeId(faultConditionUpdReq.getCarTypeId())
|
||||
.messageTypeId(faultConditionUpdReq.getMessageTypeId())
|
||||
.faultconditionIdentification(faultConditionUpdReq.getFaultconditionIdentification())
|
||||
.faultconditionParameter(faultConditionUpdReq.getFaultconditionParameter())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: FaultLabel ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:07 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_fault_label",autoResultMap = true)
|
||||
public class FaultLabel {
|
||||
|
||||
/**
|
||||
*自增主键
|
||||
*/
|
||||
@TableId(value = "message_type_id",type = IdType.AUTO)
|
||||
private String messageTypeId;
|
||||
/**
|
||||
*报文编码
|
||||
*/
|
||||
private String messageTypeCode;
|
||||
/**
|
||||
*报文名称
|
||||
*/
|
||||
private String messageTypeName;
|
||||
/**
|
||||
*报文所属类别
|
||||
*/
|
||||
private String messageTypeBelongs;
|
||||
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_fault_log",autoResultMap = true)
|
||||
public class FaultLog {
|
||||
|
||||
/**
|
||||
* 故障日志Id
|
||||
*/
|
||||
@TableId(value = "log_id",type = IdType.AUTO)
|
||||
private long logId;
|
||||
/**
|
||||
* 故障码Id
|
||||
*/
|
||||
private long faultcodeId;
|
||||
/**
|
||||
* 车辆Id
|
||||
*/
|
||||
private long carInformationId;
|
||||
/**
|
||||
* 车辆VIN
|
||||
*/
|
||||
private String carVin;
|
||||
/**
|
||||
* 开始报警时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "开始报警时间",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date startwarningTime;
|
||||
/**
|
||||
* 结束报警时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "结束报警时间",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date endwarningTime;
|
||||
/**
|
||||
* 故障码
|
||||
*/
|
||||
private String faultcodeNumber;
|
||||
/**
|
||||
* 车辆vin
|
||||
*/
|
||||
private String carInformationVIN;
|
||||
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: FaultReport ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:05 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class FaultReport {
|
||||
private String VehicleType;
|
||||
private String FaultDescription;
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @className: FaultRule ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:05 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_fault_condition",autoResultMap = true)
|
||||
public class FaultRule {
|
||||
/**
|
||||
* 触发条件Id
|
||||
*/
|
||||
private long conditionId;
|
||||
|
||||
/**
|
||||
* 故障码Id
|
||||
*/
|
||||
private long faultcodeId;
|
||||
|
||||
/**
|
||||
* 触发条件描述
|
||||
*/
|
||||
private String conditionContent;
|
||||
|
||||
/**
|
||||
* 单个参数的阈值
|
||||
*/
|
||||
private BigDecimal singleThreshold;
|
||||
|
||||
/**
|
||||
* 区间参数的阈值的最小值
|
||||
*/
|
||||
private BigDecimal minThreshold;
|
||||
|
||||
/**
|
||||
* 区间参数的阈值的最大值
|
||||
*/
|
||||
private BigDecimal maxThreshold;
|
||||
|
||||
/**
|
||||
* 触发条件是否激活
|
||||
*/
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 车辆数据值
|
||||
*/
|
||||
private BigDecimal Threshold;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: FaultType ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:04 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_fault_type",autoResultMap = true)
|
||||
public class FaultType {
|
||||
/**
|
||||
*故障类型Id
|
||||
*/
|
||||
@TableId(value = "faulttype_id",type = IdType.AUTO)
|
||||
private long faulttypeId;
|
||||
/**
|
||||
*故障类型名称
|
||||
*/
|
||||
private String faulttypeName;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.muyu.fault.domain.message.Message;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
/**
|
||||
* @className: MessageDao ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 20:58 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
public class MessageDao {
|
||||
private Connection connection;
|
||||
|
||||
public MessageDao(Connection connection){
|
||||
this.connection=connection;
|
||||
}
|
||||
|
||||
public void sendMessage(Message message) throws Exception{
|
||||
String sql="INSERT INTO `eight`.`car_fault_message` (`id`, `sender`, `receiver`, `content`, `status`, `create_time`, `user_id`) " +
|
||||
"VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
|
||||
try(PreparedStatement pstmt=connection.prepareStatement(sql)){
|
||||
pstmt.setString(1, message.getContent());
|
||||
pstmt.setString(2, message.getSender());
|
||||
pstmt.setString(3, message.getReceiver());
|
||||
pstmt.setObject(4, message.getCreateTime());
|
||||
pstmt.executeUpdate();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.muyu.fault.domain.message.Message;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className: MessageService ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:01 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 业务逻辑层将负责实现消息的发送逻辑
|
||||
*/
|
||||
|
||||
public class MessageService {
|
||||
private MessageDao messageDao;
|
||||
|
||||
public MessageService(MessageDao messageDao){
|
||||
this.messageDao=messageDao;
|
||||
}
|
||||
|
||||
public void sendMessage(String content,String sender,String receiver){
|
||||
|
||||
// 定义一个DateTimeFormatter对象,用于格式化日期时间为yyyy-MM-dd HH:mm:ss
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// 获取当前日期和时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 使用formatter格式化当前日期和时间
|
||||
String formattedDateTime = now.format(formatter);
|
||||
// 使用formatter将字符串解析回LocalDateTime
|
||||
LocalDateTime parsedDateTime = LocalDateTime.parse(formattedDateTime, formatter);
|
||||
// 然后按照上面的步骤将LocalDateTime转换为Date
|
||||
ZonedDateTime zdt = parsedDateTime.atZone(ZoneId.systemDefault());
|
||||
Date date = Date.from(zdt.toInstant());
|
||||
|
||||
|
||||
Message message = new Message();
|
||||
message.setContent(content);
|
||||
message.setSender(sender);
|
||||
message.setReceiver(receiver);
|
||||
message.setCreateTime(date);
|
||||
|
||||
try {
|
||||
messageDao.sendMessage(message);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
|
||||
/**
|
||||
* 车辆故障对象 sys_car_fault
|
||||
*
|
||||
* @author Yang鹏
|
||||
* @date 2024-09-18
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Setter
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("sys_car_fault")
|
||||
public class SysCarFault extends BaseEntity{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 自增主键 */
|
||||
@TableId( type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 车辆故障编码; */
|
||||
@Excel(name = "车辆故障编码;")
|
||||
private String faultCode;
|
||||
|
||||
/** 车辆故障名称 */
|
||||
@Excel(name = "车辆故障名称")
|
||||
private String faultName;
|
||||
|
||||
/** 车辆故障类型 */
|
||||
@Excel(name = "车辆故障类型")
|
||||
private String faultType;
|
||||
|
||||
/** 故障VIN编码 */
|
||||
@Excel(name = "故障VIN编码")
|
||||
private String carVin;
|
||||
|
||||
/** 车辆故障标签 */
|
||||
@Excel(name = "车辆故障标签")
|
||||
private String faultLabel;
|
||||
|
||||
/** 车辆故障位 */
|
||||
@Excel(name = "车辆故障位")
|
||||
private String faultBit;
|
||||
|
||||
/** 车辆故障值 */
|
||||
@Excel(name = "车辆故障值")
|
||||
private String faultValue;
|
||||
|
||||
/** 故障级别; */
|
||||
@Excel(name = "故障级别;")
|
||||
private String faultWarn;
|
||||
|
||||
/** 报警状态(Y.是,N.否) */
|
||||
@Excel(name = "报警状态", readConverterExp = "Y=.是,N.否")
|
||||
private String warnStatus;
|
||||
|
||||
/** 故障描述信息 */
|
||||
@Excel(name = "故障描述信息")
|
||||
private String faultDesc;
|
||||
|
||||
/** 启用状态(1.待处理 2.处理中 3.已处理 4.忽略) */
|
||||
@Excel(name = "启用状态(1.待处理 2.处理中 3.已处理 4.忽略)")
|
||||
private String state;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("faultCode", getFaultCode())
|
||||
.append("faultName", getFaultName())
|
||||
.append("faultType", getFaultType())
|
||||
.append("carVin", getCarVin())
|
||||
.append("faultLabel", getFaultLabel())
|
||||
.append("faultBit", getFaultBit())
|
||||
.append("faultValue", getFaultValue())
|
||||
.append("faultWarn", getFaultWarn())
|
||||
.append("warnStatus", getWarnStatus())
|
||||
.append("faultDesc", getFaultDesc())
|
||||
.append("state", getState())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package com.muyu.fault.domain;
|
||||
|
||||
public enum WarnLevel {
|
||||
LOW, MEDIUM, HIGH
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package com.muyu.fault.domain.message;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className: Message ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/22 10:55 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@TableName(value = "car_fault_message",autoResultMap = true)
|
||||
public class Message {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private long id;
|
||||
|
||||
/**
|
||||
* 发送者
|
||||
*/
|
||||
private String sender;
|
||||
|
||||
/**
|
||||
* 接收者
|
||||
*/
|
||||
private String receiver;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 消息状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "消息创建时间",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date createTime;
|
||||
/**
|
||||
* 登录人Id
|
||||
*/
|
||||
private long userId;
|
||||
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package com.muyu.fault.domain.message;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: MessageReq ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 20:59 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class MessageReq {
|
||||
/**
|
||||
* 消息状态
|
||||
*/
|
||||
@TableId(type = IdType.AUTO,value = "status")
|
||||
private Integer status;
|
||||
/**
|
||||
* 登录人Id
|
||||
*/
|
||||
@Excel(name = "登录人Id")
|
||||
private long userId;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package com.muyu.fault.domain.message;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className: MessageSendReq ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:00 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class MessageSendReq {
|
||||
/**
|
||||
* 发送者
|
||||
*/
|
||||
@TableId(type = IdType.AUTO,value = "id")
|
||||
private String sender;
|
||||
/**
|
||||
* 接收者
|
||||
*/
|
||||
@Excel(name = "接收者")
|
||||
private String receiver;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
@Excel(name = "消息内容")
|
||||
private String content;
|
||||
/**
|
||||
* 登录人Id
|
||||
*/
|
||||
@Excel(name = "登录人Id")
|
||||
private long userId;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "消息创建时间",defaultValue = "2024-8-9 10:47:57",type = "String")
|
||||
private Date createTime;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.muyu.fault.domain.message;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: User ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 20:56 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class User {
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Excel(name = "用户名")
|
||||
private String username;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Excel(name="邮箱")
|
||||
private String email;
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package com.muyu.fault.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class FaultCodeAddReq {
|
||||
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
* 故障名称
|
||||
*/
|
||||
private String messageTypeName;
|
||||
/**
|
||||
* 报文编码
|
||||
*/
|
||||
private String messageTypeCode;
|
||||
|
||||
/**
|
||||
* 故障码
|
||||
*/
|
||||
private String faultcodeNumber;
|
||||
/**
|
||||
* 故障分类Id
|
||||
*/
|
||||
private long faulttypeId;
|
||||
/**
|
||||
* 是否产生报警
|
||||
*/
|
||||
private Integer isWarning;
|
||||
/**
|
||||
* 故障描述
|
||||
*/
|
||||
private String faultContent;
|
||||
/**
|
||||
*故障组
|
||||
*/
|
||||
private String faultGroup;
|
||||
/**
|
||||
*故障位
|
||||
*/
|
||||
private String faultBit;
|
||||
/**
|
||||
*故障值
|
||||
*/
|
||||
private String faultValue;
|
||||
/**
|
||||
*报文所属类别
|
||||
*/
|
||||
private String messageTypeBelongs;
|
||||
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.muyu.fault.domain.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
|
||||
@Tag(name = "故障码列表请求对象")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class FaultCodeListReq {
|
||||
/**
|
||||
*故障码
|
||||
*/
|
||||
private String faultcodeNumber;
|
||||
/**
|
||||
*故障位
|
||||
*/
|
||||
private String faultBit;
|
||||
/**
|
||||
* 页码,从1开始
|
||||
*/
|
||||
private Integer pageNum=1;
|
||||
/**
|
||||
* 每页大小
|
||||
*/
|
||||
private Integer pageSize=10;
|
||||
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.muyu.fault.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class FaultConditionAddReq {
|
||||
/**
|
||||
* 故障规则表Id
|
||||
*/
|
||||
private long carconditionId;
|
||||
/**
|
||||
* 车辆类型Id
|
||||
*/
|
||||
private long carTypeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
* 故障条件
|
||||
*/
|
||||
private String faultconditionIdentification;
|
||||
/**
|
||||
* 故障规则参数
|
||||
*/
|
||||
private BigDecimal faultconditionParameter;
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.muyu.fault.domain.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Tag(name = "故障规则列表请求对象")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class FaultConditionListReq {
|
||||
|
||||
|
||||
/**
|
||||
* 车辆类型Id
|
||||
*/
|
||||
private long carTypeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
* 页码,从1开始
|
||||
*/
|
||||
private Integer pageNum=1;
|
||||
/**
|
||||
* 每页大小
|
||||
*/
|
||||
private Integer pageSize=10;
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.muyu.fault.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class FaultConditionUpdReq {
|
||||
|
||||
/**
|
||||
* 故障规则表Id
|
||||
*/
|
||||
private long carconditionId;
|
||||
/**
|
||||
* 车辆类型Id
|
||||
*/
|
||||
private long carTypeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
* 故障条件
|
||||
*/
|
||||
private String faultconditionIdentification;
|
||||
/**
|
||||
* 故障规则参数
|
||||
*/
|
||||
private BigDecimal faultconditionParameter;
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package com.muyu.fault.domain.req;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Tag(name = "故障日志列表请求对象")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class FaultLogListReq {
|
||||
|
||||
/**
|
||||
* 故障码Id
|
||||
*/
|
||||
private long faultcodeId;
|
||||
/**
|
||||
* 车辆VIN
|
||||
*/
|
||||
private String carVin;
|
||||
/**
|
||||
* 开始报警时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "开始报警时间",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date startwarningTime;
|
||||
/**
|
||||
* 结束报警时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "结束报警时间",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date endwarningTime;
|
||||
|
||||
/**
|
||||
* 页码,从1开始
|
||||
*/
|
||||
private Integer pageNum=1;
|
||||
/**
|
||||
* 每页大小
|
||||
*/
|
||||
private Integer pageSize=10;
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package com.muyu.fault.domain.resp;
|
||||
|
||||
import com.muyu.fault.domain.vo.FaultCodeVo;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @className: Messages ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/22 10:55 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@Tag(name="故障码信息响应对象",description = "故障码查询的响应结果")
|
||||
public class FaultCodeListResp {
|
||||
|
||||
/**
|
||||
*故障码Id
|
||||
*/
|
||||
private long faultcodeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
*故障码
|
||||
*/
|
||||
private String faultcodeNumber;
|
||||
/**
|
||||
*故障组
|
||||
*/
|
||||
private String faultGroup;
|
||||
/**
|
||||
*故障位
|
||||
*/
|
||||
private String faultBit;
|
||||
/**
|
||||
*故障值
|
||||
*/
|
||||
private String faultValue;
|
||||
/**
|
||||
*是否警告
|
||||
*/
|
||||
private Integer isWarning;
|
||||
/**
|
||||
*故障类型名称
|
||||
*/
|
||||
private String faulttypeName;
|
||||
/**
|
||||
* 故障名称
|
||||
*/
|
||||
private String messageTypeName;
|
||||
/**
|
||||
* 报文编码
|
||||
*/
|
||||
private String messageTypeCode;
|
||||
/**
|
||||
*报文所属类别
|
||||
*/
|
||||
private String messageTypeBelongs;
|
||||
|
||||
/**
|
||||
* 数据库对象构建为返回结果对象
|
||||
* @param faultCodeVO
|
||||
* @return
|
||||
*/
|
||||
public static FaultCodeListResp faultCodeListResp(FaultCodeVo faultCodeVO){
|
||||
return FaultCodeListResp.builder()
|
||||
.faultcodeId(faultCodeVO.getFaultcodeId())
|
||||
.messageTypeId(faultCodeVO.getMessageTypeId())
|
||||
.faultcodeNumber(faultCodeVO.getFaultcodeNumber())
|
||||
.faultGroup(faultCodeVO.getFaultGroup())
|
||||
.faultBit(faultCodeVO.getFaultBit())
|
||||
.faultValue(faultCodeVO.getFaultValue())
|
||||
.isWarning(faultCodeVO.getIsWarning())
|
||||
.faulttypeName(faultCodeVO.getFaulttypeName())
|
||||
.messageTypeName(faultCodeVO.getMessageTypeName())
|
||||
.messageTypeCode(faultCodeVO.getMessageTypeCode())
|
||||
.messageTypeBelongs(faultCodeVO.getMessageTypeBelongs())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.muyu.fault.domain.resp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className: Messages ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/22 10:55 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tag(name="数据总数列表",description = "数据和总数的响应")
|
||||
public class FaultCodeTotalListResp {
|
||||
|
||||
|
||||
private List<FaultCodeListResp> faultCodeListRespList;
|
||||
|
||||
private long total;
|
||||
|
||||
public static FaultCodeTotalListResp faultCodeTotalListResp(List<FaultCodeListResp> faultCodeListRespList,long total){
|
||||
FaultCodeTotalListResp faultCodeTotalListResp = new FaultCodeTotalListResp();
|
||||
faultCodeTotalListResp.setFaultCodeListRespList(faultCodeListRespList);
|
||||
faultCodeTotalListResp.setTotal(total);
|
||||
return faultCodeTotalListResp;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package com.muyu.fault.domain.resp;
|
||||
|
||||
|
||||
import com.muyu.fault.domain.FaultCondition;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@Tag(name="故障规则信息响应对象",description = "故障规则查询的响应结果")
|
||||
public class FaultConditionListResp {
|
||||
|
||||
/**
|
||||
* 故障规则表Id
|
||||
*/
|
||||
private long carconditionId;
|
||||
/**
|
||||
* 车辆类型Id
|
||||
*/
|
||||
private long carTypeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
private long messageTypeId;
|
||||
/**
|
||||
* 故障条件
|
||||
*/
|
||||
private String faultconditionIdentification;
|
||||
/**
|
||||
* 故障规则参数
|
||||
*/
|
||||
private BigDecimal faultconditionParameter;
|
||||
/**
|
||||
* 车辆类型名称
|
||||
*/
|
||||
private String carTypeName;
|
||||
/**
|
||||
* 故障名称
|
||||
*/
|
||||
private String messageTypeName;
|
||||
/**
|
||||
* 报文编码
|
||||
*/
|
||||
private String messageTypeCode;
|
||||
|
||||
/**
|
||||
* 数据库对象构建为返回结果对象
|
||||
* @param faultCondition
|
||||
* @return
|
||||
*/
|
||||
public static FaultConditionListResp faultConditionListResp(FaultCondition faultCondition){
|
||||
return FaultConditionListResp.builder()
|
||||
.carconditionId(faultCondition.getCarconditionId())
|
||||
.carTypeId(faultCondition.getCarTypeId())
|
||||
.messageTypeId(faultCondition.getMessageTypeId())
|
||||
.faultconditionParameter(faultCondition.getFaultconditionParameter())
|
||||
.faultconditionIdentification(faultCondition.getFaultconditionIdentification())
|
||||
.carTypeName(faultCondition.getCarTypeName())
|
||||
.messageTypeName(faultCondition.getMessageTypeName())
|
||||
.messageTypeCode(faultCondition.getMessageTypeCode())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.muyu.fault.domain.resp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className: FaultLog ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tag(name="故障规则数据总数列表",description = "数据和总数的响应")
|
||||
public class FaultConditionTotalListResp {
|
||||
|
||||
private List<FaultConditionListResp> faultConditionListRespList;
|
||||
|
||||
private long total;
|
||||
|
||||
public static FaultConditionTotalListResp faultConditionTotalListResp(List<FaultConditionListResp> faultConditionListRespList,long total){
|
||||
FaultConditionTotalListResp faultConditionTotalListResp = new FaultConditionTotalListResp();
|
||||
faultConditionTotalListResp.setFaultConditionListRespList(faultConditionListRespList);
|
||||
faultConditionTotalListResp.setTotal(total);
|
||||
return faultConditionTotalListResp;
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package com.muyu.fault.domain.resp;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import com.muyu.fault.domain.FaultLog;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className: Messages ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/22 10:55 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@Tag(name="故障日志信息响应对象",description = "故障日志的响应结果")
|
||||
public class FaultLogListResp {
|
||||
|
||||
|
||||
/**
|
||||
* 故障日志Id
|
||||
*/
|
||||
private long logId;
|
||||
/**
|
||||
* 故障码Id
|
||||
*/
|
||||
private long faultcodeId;
|
||||
/**
|
||||
* 车辆Id
|
||||
*/
|
||||
private long carInformationId;
|
||||
/**
|
||||
* 车辆VIN
|
||||
*/
|
||||
private String carVin;
|
||||
/**
|
||||
* 开始报警时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "开始报警时间",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date startwarningTime;
|
||||
/**
|
||||
* 结束报警时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "结束报警时间",defaultValue = "2024-8-9 10:47:57",type = "Date")
|
||||
private Date endwarningTime;
|
||||
/**
|
||||
* 故障码
|
||||
*/
|
||||
private String faultcodeNumber;
|
||||
/**
|
||||
* 车辆vin
|
||||
*/
|
||||
private String carInformationVIN;
|
||||
|
||||
|
||||
/**
|
||||
* 数据库对象构建为返回结果对象
|
||||
* @param faultLog
|
||||
* @return
|
||||
*/
|
||||
public static FaultLogListResp faultLogListResp(FaultLog faultLog){
|
||||
return FaultLogListResp.builder()
|
||||
.logId(faultLog.getLogId())
|
||||
.faultcodeId(faultLog.getFaultcodeId())
|
||||
.carInformationId(faultLog.getCarInformationId())
|
||||
.carVin(faultLog.getCarVin())
|
||||
.startwarningTime(faultLog.getStartwarningTime())
|
||||
.endwarningTime(faultLog.getEndwarningTime())
|
||||
.faultcodeNumber(faultLog.getFaultcodeNumber())
|
||||
.carInformationVIN(faultLog.getCarInformationVIN())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package com.muyu.fault.domain.resp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className: Messages ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/22 10:55 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tag(name="故障日志数据总数列表",description = "数据和总数的响应")
|
||||
public class FaultLogTotalListResp {
|
||||
|
||||
private List<FaultLogListResp> faultLogListRespList;
|
||||
|
||||
private long total;
|
||||
|
||||
public static FaultLogTotalListResp faultLogTotalListResp(List<FaultLogListResp> faultLogListRespList,long total){
|
||||
FaultLogTotalListResp faultLogTotalListResp = new FaultLogTotalListResp();
|
||||
faultLogTotalListResp.setFaultLogListRespList(faultLogListRespList);
|
||||
faultLogTotalListResp.setTotal(total);
|
||||
return faultLogTotalListResp;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.muyu.fault.domain.vo;
|
||||
|
||||
import com.muyu.fault.domain.FaultCode;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
/**
|
||||
* @className: FaultCodeVo ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 22:18 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class FaultCodeVo extends FaultCode {
|
||||
/**
|
||||
*故障类型名称
|
||||
*/
|
||||
private String faulttypeName;
|
||||
/**
|
||||
* 故障名称
|
||||
*/
|
||||
private String messageTypeName;
|
||||
/**
|
||||
* 报文编码
|
||||
*/
|
||||
private String messageTypeCode;
|
||||
/**
|
||||
*报文所属类别
|
||||
*/
|
||||
private String messageTypeBelongs;
|
||||
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.muyu.fault.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.fault.domain.CarType;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @className: CarTypeMapper ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface CarTypeMapper extends BaseMapper<CarType> {
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package com.muyu.fault.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import com.muyu.fault.domain.FaultCode;
|
||||
|
||||
import com.muyu.fault.domain.FaultLabel;
|
||||
import com.muyu.fault.domain.req.FaultCodeAddReq;
|
||||
import com.muyu.fault.domain.req.FaultCodeListReq;
|
||||
import com.muyu.fault.domain.req.FaultCodeUpdReq;
|
||||
import com.muyu.fault.domain.vo.FaultCodeVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className: FaultCodeMapper ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface FaultCodeMapper extends BaseMapper<FaultCodeVo> {
|
||||
|
||||
List<FaultCodeVo> selectfaultcodelist(FaultCodeListReq faultCodeListReq);
|
||||
|
||||
|
||||
|
||||
//新增故障码
|
||||
FaultLabel selectfaultName(@Param("messageTypeName") String messageTypeName);
|
||||
FaultCode selectfaultCode(@Param("faultcodeNumber") String faultcodeNumber);
|
||||
Integer insertfaultlabel(FaultCodeAddReq faultCodeAddReq);
|
||||
Integer insertfaultcode(FaultCodeAddReq faultCodeAddReq);
|
||||
|
||||
//修改故障码
|
||||
Integer updfaultlabel(FaultCodeUpdReq faultCodeUpdReq);
|
||||
Integer updfaultcode(FaultCodeUpdReq faultCodeUpdReq);
|
||||
|
||||
|
||||
|
||||
Integer delfaultcode(@Param("messageTypeId") long messageTypeId);
|
||||
Integer delfaultlabel(@Param("messageTypeId") long messageTypeId);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.muyu.fault.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import com.muyu.fault.domain.FaultCondition;
|
||||
import com.muyu.fault.domain.req.FaultConditionAddReq;
|
||||
import com.muyu.fault.domain.req.FaultConditionListReq;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @className: FaultConditionMapper ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 21:06 ⏰
|
||||
* @Version: 1.0
|
||||
* @description: 故障检测策略的接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface FaultConditionMapper extends BaseMapper<FaultCondition> {
|
||||
|
||||
List<FaultCondition> selectfaultconditionlist(FaultConditionListReq faultConditionListReq);
|
||||
|
||||
|
||||
List<FaultCondition> selectBytypeAndlabel(FaultConditionAddReq faultConditionAddReq);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.muyu.fault.mapper;
|
||||
|
||||
/**
|
||||
* @className: FaultDetectionStrategyMapper ️✈️
|
||||
* @author: Yang 鹏 🦅
|
||||
* @date: 2024/9/23 23:59 ⏰
|
||||
* @Version: 1.0
|
||||
* @description:
|
||||
*/
|
||||
public interface FaultDetectionStrategyMapper {
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue