Compare commits
52 Commits
master
...
dev.carDat
Author | SHA1 | Date |
---|---|---|
|
d7a1d79a12 | |
|
5d4b1dbe67 | |
|
628b8d1fab | |
|
5b7de4a971 | |
|
ecd84b4672 | |
|
1ccf7419ae | |
|
7d0d0418c6 | |
|
e986ab4a17 | |
|
2a85b2bb67 | |
|
918b5223a8 | |
|
581e344fdf | |
|
e172137feb | |
|
82a7117e22 | |
|
7e0594185b | |
|
82bbab11db | |
|
b2a2a2bcb7 | |
|
4a005b3df0 | |
|
f7143fede7 | |
|
2e7169d5ed | |
|
3e73a8598a | |
|
26e1591f43 | |
|
e990dd304f | |
|
046b924c96 | |
|
daf43b843b | |
|
36c1f661b6 | |
|
50b462ae60 | |
|
8fa84a4562 | |
|
c42adb48cc | |
|
2864df2549 | |
|
fe70b7d3c1 | |
|
54f0aee961 | |
|
015d7c0896 | |
|
d947e9fbff | |
|
0523876861 | |
|
f6c0b72e18 | |
|
9185f33c0c | |
|
748d4be165 | |
|
df1c9ad9e8 | |
|
1a65c83a56 | |
|
4ae60743fa | |
|
9486710ae8 | |
|
e6e7e58f95 | |
|
7063af945e | |
|
bb56bc2393 | |
|
00d1eb18d1 | |
|
6e4b268730 | |
|
aeec2245c0 | |
|
43c74b9978 | |
|
f3c90ada2a | |
|
c34bec050c | |
|
a399073121 | |
|
fde90181c0 |
|
@ -57,7 +57,6 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -18,6 +18,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* token 控制
|
||||
*
|
||||
|
@ -34,9 +37,10 @@ public class TokenController {
|
|||
@PostMapping("login")
|
||||
public Result<?> login (@RequestBody LoginBody form) {
|
||||
// 用户登录
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(),form.getFirmName());
|
||||
// 获取登录token
|
||||
return Result.success(tokenService.createToken(userInfo));
|
||||
Map<String, Object> token = tokenService.createToken(userInfo);
|
||||
return Result.success(token);
|
||||
}
|
||||
|
||||
@DeleteMapping("logout")
|
||||
|
|
|
@ -17,7 +17,18 @@ public class LoginBody {
|
|||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 公司名称
|
||||
*/
|
||||
private String firmName;
|
||||
|
||||
public String getFirmName() {
|
||||
return firmName;
|
||||
}
|
||||
|
||||
public void setFirmName(String firmName) {
|
||||
this.firmName = firmName;
|
||||
}
|
||||
|
||||
public String getUsername () {
|
||||
return username;
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.muyu.common.core.utils.ip.IpUtils;
|
|||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.remote.RemoteFirmService;
|
||||
import com.muyu.common.system.domain.SysUserMessage;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
|
@ -31,9 +31,6 @@ public class SysLoginService {
|
|||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Autowired
|
||||
private RemoteFirmService remoteFirmService;
|
||||
|
||||
@Autowired
|
||||
private SysPasswordService passwordService;
|
||||
|
||||
|
@ -46,7 +43,7 @@ public class SysLoginService {
|
|||
/**
|
||||
* 登录
|
||||
*/
|
||||
public LoginUser login (String username, String password) {
|
||||
public LoginUser login (String username, String password,String firmName) {
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password)) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
||||
|
@ -71,7 +68,24 @@ public class SysLoginService {
|
|||
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
||||
}
|
||||
// 查询用户信息
|
||||
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
Result<LoginUser> userResult = null;
|
||||
//根据企业名称查询数据源
|
||||
if (StringUtils.isNotEmpty(firmName)){
|
||||
Result<String> result = remoteUserService.selectByfirmName(firmName);
|
||||
if (result.getData()!=null){
|
||||
SysUserMessage sysUserMessage = new SysUserMessage();
|
||||
sysUserMessage.setUsername(username);
|
||||
sysUserMessage.setPassword(password);
|
||||
sysUserMessage.setDatabaseName(result.getData());
|
||||
//查询这个数据源中的登录账号和密码
|
||||
userResult = remoteUserService.selectuser(sysUserMessage);
|
||||
}
|
||||
}
|
||||
// userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||
|
@ -118,7 +132,7 @@ public class SysLoginService {
|
|||
throw new ServiceException("密码长度必须在5到20个字符之间");
|
||||
}
|
||||
String firmName = registerBody.getFirmName();
|
||||
Result<Firm> byFirmName = remoteFirmService.findByFirmName(firmName);
|
||||
Result<Firm> byFirmName = remoteUserService.findByFirmName(firmName);
|
||||
Firm data = byFirmName.getData();
|
||||
if (null != data){
|
||||
throw new ServiceException("公司名称已经存在");
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: xxy
|
||||
namespace: eight
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-modules-cache 缓存基准
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 抽象缓存层
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.common
|
||||
* @Project:cloud-server-8
|
||||
* @name:CacheAbsBacis
|
||||
* @Date:2024/9/30 11:19
|
||||
*/
|
||||
public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V>{
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
redisService.setCacheObject(encode(key),value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return redisService.getCacheObject(encode(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(K key) {
|
||||
redisService.deleteObject(encode(key));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
/**
|
||||
* 缓存基础
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.common.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:CacheBasic
|
||||
* @Date:2024/9/30 11:41
|
||||
*/
|
||||
public interface CacheBasic<K,V> extends PrimaryKeyBasic<K>{
|
||||
|
||||
void put(K key,V value);
|
||||
|
||||
V get(K key);
|
||||
|
||||
void remove(K key);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.common.cache;
|
||||
|
||||
/**
|
||||
* 主键基础
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.common.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:PrimaryKeyBasic
|
||||
* @Date:2024/9/30 11:35
|
||||
*/
|
||||
public interface PrimaryKeyBasic <K>{
|
||||
|
||||
/**
|
||||
* key 前缀
|
||||
* @return 前缀
|
||||
*/
|
||||
public String keyPre();
|
||||
/**
|
||||
* 编码
|
||||
* @param key 缓存键
|
||||
* @return 装修键
|
||||
*/
|
||||
public default String encode(K key){
|
||||
return key.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码key
|
||||
* @param key 编码Key
|
||||
* @return 解码后的Key
|
||||
*/
|
||||
public K decode(String key);
|
||||
|
||||
}
|
|
@ -56,5 +56,5 @@ public class SecurityConstants {
|
|||
*/
|
||||
public static final String ROLE_PERMISSION = "role_permission";
|
||||
|
||||
public static final String SAAS_KEY = "ent-code";
|
||||
public static final String SAAS_KEY = "saas_key";
|
||||
}
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
package com.muyu.common.kafka.config;
|
||||
|
||||
import com.muyu.common.kafka.constants.KafkaConstants;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.apache.kafka.common.serialization.Deserializer;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* kafka 消息的消费者 配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaConsumerConfig {
|
||||
|
||||
@Bean
|
||||
public KafkaConsumer kafkaConsumer() {
|
||||
Map<String, Object> configs = new HashMap<>();
|
||||
//kafka服务端的IP和端口,格式:(ip:port)
|
||||
configs.put("bootstrap.servers", "60.204.221.52:9092");
|
||||
//开启consumer的偏移量(offset)自动提交到Kafka
|
||||
configs.put("enable.auto.commit", true);
|
||||
//consumer的偏移量(offset) 自动提交的时间间隔,单位毫秒
|
||||
configs.put("auto.commit.interval", 5000);
|
||||
//在Kafka中没有初始化偏移量或者当前偏移量不存在情况
|
||||
//earliest, 在偏移量无效的情况下, 自动重置为最早的偏移量
|
||||
//latest, 在偏移量无效的情况下, 自动重置为最新的偏移量
|
||||
//none, 在偏移量无效的情况下, 抛出异常.
|
||||
configs.put("auto.offset.reset", "latest");
|
||||
//请求阻塞的最大时间(毫秒)
|
||||
configs.put("fetch.max.wait", 500);
|
||||
//请求应答的最小字节数
|
||||
configs.put("fetch.min.size", 1);
|
||||
//心跳间隔时间(毫秒)
|
||||
configs.put("heartbeat-interval", 3000);
|
||||
//一次调用poll返回的最大记录条数
|
||||
configs.put("max.poll.records", 500);
|
||||
//指定消费组
|
||||
configs.put("group.id", KafkaConstants.KafkaGrop);
|
||||
//指定key使用的反序列化类
|
||||
Deserializer keyDeserializer = new StringDeserializer();
|
||||
//指定value使用的反序列化类
|
||||
Deserializer valueDeserializer = new StringDeserializer();
|
||||
//创建Kafka消费者
|
||||
KafkaConsumer kafkaConsumer = new KafkaConsumer(configs, keyDeserializer, valueDeserializer);
|
||||
return kafkaConsumer;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package com.muyu.common.kafka.config;
|
||||
|
||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
import org.apache.kafka.common.serialization.Serializer;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* kafka 消息的生产者 配置类
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaProviderConfig {
|
||||
|
||||
@Bean
|
||||
public KafkaProducer kafkaProducer() {
|
||||
Map<String, Object> configs = new HashMap<>();
|
||||
//#kafka服务端的IP和端口,格式:(ip:port)
|
||||
configs.put("bootstrap.servers", "47.116.173.119:9092");
|
||||
//客户端发送服务端失败的重试次数
|
||||
configs.put("retries", 2);
|
||||
//多个记录被发送到同一个分区时,生产者将尝试将记录一起批处理成更少的请求.
|
||||
//此设置有助于提高客户端和服务器的性能,配置控制默认批量大小(以字节为单位)
|
||||
configs.put("batch.size", 16384);
|
||||
//生产者可用于缓冲等待发送到服务器的记录的总内存字节数(以字节为单位)
|
||||
configs.put("buffer-memory", 33554432);
|
||||
//生产者producer要求leader节点在考虑完成请求之前收到的确认数,用于控制发送记录在服务端的持久化
|
||||
//acks=0,设置为0,则生产者producer将不会等待来自服务器的任何确认.该记录将立即添加到套接字(socket)缓冲区并视为已发送.在这种情况下,无法保证服务器已收到记录,并且重试配置(retries)将不会生效(因为客户端通常不会知道任何故障),每条记录返回的偏移量始终设置为-1.
|
||||
//acks=1,设置为1,leader节点会把记录写入本地日志,不需要等待所有follower节点完全确认就会立即应答producer.在这种情况下,在follower节点复制前,leader节点确认记录后立即失败的话,记录将会丢失.
|
||||
//acks=all,acks=-1,leader节点将等待所有同步复制副本完成再确认记录,这保证了只要至少有一个同步复制副本存活,记录就不会丢失.
|
||||
configs.put("acks", "-1");
|
||||
//指定key使用的序列化类
|
||||
Serializer keySerializer = new StringSerializer();
|
||||
//指定value使用的序列化类
|
||||
Serializer valueSerializer = new StringSerializer();
|
||||
//创建Kafka生产者
|
||||
KafkaProducer kafkaProducer = new KafkaProducer(configs, keySerializer, valueSerializer);
|
||||
return kafkaProducer;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.muyu.common.kafka.constants;
|
||||
|
||||
|
||||
public class KafkaConstants {
|
||||
|
||||
public final static String KafkaTopic = "carJsons";
|
||||
|
||||
// public final static String KafkaGrop = "kafka_grop";
|
||||
}
|
|
@ -17,7 +17,8 @@ import java.util.HashMap;
|
|||
* @Date:2024/9/28 12:19
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaConfig {
|
||||
public class
|
||||
KafkaConfig {
|
||||
|
||||
@Bean
|
||||
public KafkaProducer kafkaProducer(){
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
package com.muyu.common.rabbit;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
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.context.annotation.Primary;
|
||||
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||
|
||||
@Configuration
|
||||
public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer {
|
||||
|
||||
|
||||
static {
|
||||
System.setProperty("spring.amqp.deserialization.trust.all", "true");
|
||||
}
|
||||
|
|
|
@ -255,4 +255,14 @@ public class RedisService {
|
|||
public Collection<String> keys (final String pattern) {
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取使用的对象的次数
|
||||
// * @param key Redis键
|
||||
// * @param hKey Hash键
|
||||
// */
|
||||
// public void getNumber (final String key, final String hKey){
|
||||
// Object o = redisTemplate.opsForHash().get(key, hKey);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import com.muyu.cloud.common.saas.domain.model.EntInfo;
|
|||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
|
@ -36,16 +37,17 @@ public class ManyDataSource implements ApplicationRunner{
|
|||
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
RemoteUserService remoteUserService = SpringUtils.getBean(RemoteUserService.class);
|
||||
Result<List<SysUser>> tableDataInfoResult = remoteUserService.companyList();
|
||||
Result<List<Firm>> tableDataInfoResult = remoteUserService.selectAll();
|
||||
if (tableDataInfoResult==null){
|
||||
throw new SaaSException("saas远调数据源错误");
|
||||
}
|
||||
List<SysUser> data = tableDataInfoResult.getData();
|
||||
List<Firm> data = tableDataInfoResult.getData();
|
||||
if (tableDataInfoResult.getCode() ==Result.SUCCESS && data !=null){
|
||||
List<EntInfo> list = new ArrayList<>();
|
||||
for (SysUser row : data) {
|
||||
for (Firm row : data) {
|
||||
list.add(
|
||||
EntInfo.builder()
|
||||
.firmKey(row.getFirmName())
|
||||
.entCode(row.getDatabaseName())
|
||||
.ip(DatasourceContent.IP)
|
||||
.port(DatasourceContent.PORT)
|
||||
|
@ -82,7 +84,8 @@ public class ManyDataSource implements ApplicationRunner{
|
|||
public void run(ApplicationArguments args) {
|
||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||
for (EntInfo entInfo : dataSourceInfoList()) {
|
||||
List<EntInfo> entInfos = this.dataSourceInfoList();
|
||||
for (EntInfo entInfo : entInfos) {
|
||||
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(
|
||||
entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort()
|
||||
);
|
||||
|
|
|
@ -8,7 +8,6 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 数据源实体类
|
||||
* @Date 2023-8-1 上午 11:15
|
||||
*/
|
||||
|
|
|
@ -19,7 +19,6 @@ public class DruidDataSourceFactory {
|
|||
|
||||
/**
|
||||
* @Description: 根据传递的数据源信息测试数据库连接
|
||||
* @Author Dongzl
|
||||
*/
|
||||
public DruidDataSource create(DataSourceInfo dataSourceInfo) {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
|
@ -33,7 +32,7 @@ public class DruidDataSourceFactory {
|
|||
log.info("{} -> 数据源连接成功", dataSourceInfo.getKey());
|
||||
return druidDataSource;
|
||||
} catch (SQLException throwables) {
|
||||
log.error("数据源 {} 连接失败,用户名:{},密码 {}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword());
|
||||
log.error("数据源 {} 连接失败,用户名:{},密码 {}, 四百原因:{}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword(),throwables);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,5 +8,5 @@ package com.muyu.cloud.common.saas.contents;
|
|||
*/
|
||||
public class SaaSConstant {
|
||||
|
||||
public final static String SAAS_KEY = "ent-code";
|
||||
public final static String SAAS_KEY = "saas_key";
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import lombok.NoArgsConstructor;
|
|||
@AllArgsConstructor
|
||||
public class EntInfo {
|
||||
|
||||
private String firmKey;
|
||||
|
||||
private String entCode;
|
||||
|
||||
private String ip;
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
|
|||
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
||||
import com.muyu.cloud.common.saas.contents.SaaSConstant;
|
||||
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
import com.muyu.common.core.utils.ServletUtils;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -25,8 +26,11 @@ public class SaaSInterceptor implements AsyncHandlerInterceptor {
|
|||
return true;
|
||||
}
|
||||
|
||||
// SaaSConstant.SAAS_KEY
|
||||
// SecurityConstants.SAAS_KEY
|
||||
|
||||
String SaaSKey = ServletUtils.getHeader(request, SaaSConstant.SAAS_KEY);
|
||||
if (SaaSKey == null) {
|
||||
if (SaaSKey == null || "".equals(SaaSKey)) {
|
||||
throw new SaaSException("SaaS非法访问");
|
||||
}else {
|
||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||
|
|
|
@ -62,6 +62,7 @@ public class TokenService {
|
|||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
||||
rspMap.put("expires_in", expireTime);
|
||||
rspMap.put("saas_key", loginUser.getSysUser().getDatabaseName());
|
||||
|
||||
return rspMap;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.common.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
@ -21,6 +22,7 @@ public class Firm {
|
|||
/**
|
||||
* 公司编号
|
||||
*/
|
||||
@TableId(value = "firm_id")
|
||||
private Integer firmId;
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,4 +63,14 @@ public class LoginUser implements Serializable {
|
|||
*/
|
||||
private SysUser sysUser;
|
||||
|
||||
/**
|
||||
* 企业
|
||||
*/
|
||||
private Firm firm;
|
||||
|
||||
/**
|
||||
* 公司名称
|
||||
*/
|
||||
private String firmName;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.common.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.common.core.annotation.Excel.ColumnType;
|
||||
import com.muyu.common.core.annotation.Excel.Type;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.common.system.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**用户登录时用来查询的信息
|
||||
* @Author:weiran
|
||||
* @Package:com.muyu.system.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:SysUserMessage
|
||||
* @Date:2024/10/2 10:25
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SysUserMessage {
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 数据库名
|
||||
*/
|
||||
private String databaseName;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.muyu.common.system.remote;
|
||||
|
||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.remote.factory.RemoteFirmFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.system.remote
|
||||
* @Project:cloud-server-8
|
||||
* @name:RemoteFirmService
|
||||
* @Date:2024/9/25 22:21
|
||||
*/
|
||||
@FeignClient(contextId = "remoteFirmService", value = ServiceNameConstants.SYSTEM_SERVICE,fallbackFactory = RemoteFirmFallbackFactory.class)
|
||||
public interface RemoteFirmService {
|
||||
|
||||
@RequestMapping("/firm/findByFirmName/{firmName}")
|
||||
public Result<Firm> findByFirmName(@PathVariable("firmName") String firmName);
|
||||
}
|
|
@ -3,7 +3,9 @@ package com.muyu.common.system.remote;
|
|||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.SysUserMessage;
|
||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
@ -42,4 +44,27 @@ public interface RemoteUserService {
|
|||
|
||||
@GetMapping("/user/companyList")
|
||||
public Result<List<SysUser>> companyList ();
|
||||
|
||||
@GetMapping("/user/selectByfirmName/{firmName}")
|
||||
public Result<String> selectByfirmName(@PathVariable("firmName") String firmName);
|
||||
|
||||
/**
|
||||
* 查询这个数据源中的登录账号和密码
|
||||
* @param sysUserMessage
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/user/selectuser")
|
||||
public Result<LoginUser> selectuser(@RequestBody SysUserMessage sysUserMessage );
|
||||
|
||||
/**
|
||||
* 根据企业码查询对应数据源
|
||||
* @param firmName
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/firm/findByFirmName/{firmName}")
|
||||
public Result<Firm> findByFirmName(@PathVariable("firmName") String firmName);
|
||||
|
||||
|
||||
@RequestMapping("/firm/selectAll")
|
||||
public Result<List<Firm>> selectAll();
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package com.muyu.common.system.remote.factory;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.remote.RemoteFirmService;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.system.remote.factory
|
||||
* @Project:cloud-server-8
|
||||
* @name:RemoteFirmFallbackFactory
|
||||
* @Date:2024/9/25 22:22
|
||||
*/
|
||||
@Component
|
||||
public class RemoteFirmFallbackFactory implements FallbackFactory<RemoteFirmService> {
|
||||
@Override
|
||||
public RemoteFirmService create(Throwable cause) {
|
||||
|
||||
return new RemoteFirmService() {
|
||||
@Override
|
||||
public Result<Firm> findByFirmName(String firmName) {
|
||||
throw new ServiceException(cause.getCause().toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package com.muyu.common.system.remote.factory;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.Firm;
|
||||
import com.muyu.common.system.domain.SysUserMessage;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
|
@ -38,6 +40,26 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
public Result<List<SysUser>> companyList() {
|
||||
return Result.error("发现用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> selectByfirmName(String firmName) {
|
||||
return Result.error("信息查询失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<LoginUser> selectuser(SysUserMessage sysUserMessage) {
|
||||
return Result.error("信息查询失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Firm> findByFirmName(String firmName) {
|
||||
return Result.error("信息查询失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<Firm>> selectAll() {
|
||||
return Result.error("信息查询失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
||||
com.muyu.common.system.remote.factory.RemoteFirmFallbackFactory
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-saas</module>
|
||||
<module>cloud-common-wechat</module>
|
||||
<module>cloud-common-cache</module>
|
||||
<module>cloud-common-kafka</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 159.75.188.178:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: xxy
|
||||
namespace: eight
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-Saas-Service</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.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-electronic-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>clod-Saas-Service</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- <!– 加入maven deploy插件,当在deploy时,忽略些model–> -->
|
||||
<!-- <plugin> -->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId> -->
|
||||
<!-- <artifactId>maven-deploy-plugin</artifactId> -->
|
||||
<!-- <version>3.1.1</version> -->
|
||||
<!-- <configuration> -->
|
||||
<!-- <skip>true</skip> -->
|
||||
<!-- </configuration> -->
|
||||
<!-- </plugin> -->
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,124 @@
|
|||
<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-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<description>
|
||||
cloud-modules-car-gateway车辆网关模块
|
||||
</description>
|
||||
<artifactId>cloud-modules-car-gateway</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cloud-modules-car-gateway</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>5.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.car;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car
|
||||
* @Project:cloud-server-8
|
||||
* @name:CloudCarGatewayApplication
|
||||
* @Date:2024/9/29 上午10:50
|
||||
*/
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class CloudCarGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudCarGatewayApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.muyu.car;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
public class MqttPublishSample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String topic = "vehicle";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://120.55.62.0:1883";
|
||||
String clientId = "JavaSample";
|
||||
|
||||
try {
|
||||
// 第三个参数为空,默认持久化策略
|
||||
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
System.out.println("Connecting to broker: "+broker);
|
||||
sampleClient.connect(connOpts);
|
||||
sampleClient.subscribe(topic,0);
|
||||
sampleClient.setCallback(new MqttCallback() {
|
||||
// 连接丢失
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
|
||||
}
|
||||
// 连接成功
|
||||
@Override
|
||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||
System.out.println(new String(mqttMessage.getPayload()));
|
||||
}
|
||||
// 接收信息
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch(MqttException me) {
|
||||
System.out.println("reason "+me.getReasonCode());
|
||||
System.out.println("msg "+me.getMessage());
|
||||
System.out.println("loc "+me.getLocalizedMessage());
|
||||
System.out.println("cause "+me.getCause());
|
||||
System.out.println("excep "+me);
|
||||
me.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.muyu.car.domain.api.req;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆连接请求参数
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.api.req
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleConnectionReq
|
||||
* @Date:2024/10/2 下午4:12
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VehicleConnectionReq {
|
||||
|
||||
/**
|
||||
* {
|
||||
* "vehicleVin": "VIN1234567894",
|
||||
* "timestamp": "11111",
|
||||
* "username": "你好",
|
||||
* "nonce": "33"
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* vin
|
||||
*/
|
||||
@JSONField(name = "vehicleVin")
|
||||
private String vehicleVin;
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private String timestamp;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@JSONField(name = "username")
|
||||
private String username;
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.car.domain.example;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实例基础信息
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:ExampleInformation
|
||||
* @Date:2024/9/29 下午10:01
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ExampleInformation {
|
||||
|
||||
/**
|
||||
* 实例ID
|
||||
*/
|
||||
private String InstanceId;
|
||||
/**
|
||||
* 实例IP
|
||||
*/
|
||||
private String IpAddress;
|
||||
/**
|
||||
* 实例状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.car.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model
|
||||
* @Project:cloud-server-8
|
||||
* @name:MqttServerModel
|
||||
* @Date:2024/10/7 下午6:40
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MqttServerModel {
|
||||
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.muyu.car.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model
|
||||
* @Project:cloud-server-8
|
||||
* @name:Vehicle
|
||||
* @Date:2024/10/6 上午10:33
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VehicleInformation {
|
||||
|
||||
/**
|
||||
* 车辆ID
|
||||
*/
|
||||
private String carInformationId ;
|
||||
/**
|
||||
* 车辆唯一VIN
|
||||
*/
|
||||
private String carInformationVIN ;
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
private String carInformationLicensePlate ;
|
||||
/**
|
||||
* 车辆品牌
|
||||
*/
|
||||
private String carInformationBrand ;
|
||||
/**
|
||||
* 车辆颜色
|
||||
*/
|
||||
private String carInformationColor ;
|
||||
/**
|
||||
* 车辆驾驶员
|
||||
*/
|
||||
private String carInformationDriver ;
|
||||
/**
|
||||
* 车检到期日期
|
||||
*/
|
||||
private String carInformationExamineEnddata ;
|
||||
/**
|
||||
* 车辆电机厂商
|
||||
*/
|
||||
private String carInformationMotorManufacturer ;
|
||||
/**
|
||||
* 车辆电机型号
|
||||
*/
|
||||
private String carInformationMotorModel ;
|
||||
/**
|
||||
* 车辆电池厂商
|
||||
*/
|
||||
private String carInformationBatteryManufacturer ;
|
||||
/**
|
||||
* 车辆电池型号
|
||||
*/
|
||||
private String carInformationBatteryModel ;
|
||||
/**
|
||||
* 车辆电子围栏外键ID
|
||||
*/
|
||||
private String carInformationFence ;
|
||||
/**
|
||||
* 车辆类型外键ID
|
||||
*/
|
||||
private String carInformationType ;
|
||||
/**
|
||||
* 是否重点车辆 (0否默认 1是 )
|
||||
*/
|
||||
private String carInformationFocus ;
|
||||
/**
|
||||
* 车辆策略id
|
||||
*/
|
||||
private String carStrategyId ;
|
||||
/**
|
||||
* 启用状态(1.在线 2.离线 3.已断开 4.待连接 5.维修中)
|
||||
*/
|
||||
private String carInformationState ;
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.muyu.car.domain.model.properties;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model.properties
|
||||
* @Project:cloud-server-8
|
||||
* @name:MqttProperties
|
||||
* @Date:2024/10/6 下午8:24
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MqttProperties {
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 上报级别
|
||||
*/
|
||||
private int qos = 0;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.car.domain.model.properties;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain.model.properties
|
||||
* @Project:cloud-server-8
|
||||
* @name:MqttServerModel
|
||||
* @Date:2024/10/6 下午8:25
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MqttServerModel {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MqttServerModel.class);
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
public String getBroker () {
|
||||
log.info("broker: {}", broker);
|
||||
return broker.contains("tcp://") ? broker : "tcp://" + broker + ":1883";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.car.gateway.controller;
|
||||
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import com.muyu.car.domain.model.MqttServerModel;
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInformationService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 车辆获取信息
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationController
|
||||
* @Date:2024/10/6 下午2:39
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/verify")
|
||||
public class VehicleInformationController {
|
||||
|
||||
@Autowired
|
||||
private VehicleInformationService vehicleInformationService;
|
||||
|
||||
@PostMapping("/vehicleConnection")
|
||||
public Result<MqttServerModel> getVehicleData(
|
||||
@Validated @RequestBody VehicleConnectionReq vehicleConnectionReq
|
||||
) {
|
||||
|
||||
return Result.success(vehicleInformationService.getVehicleData(vehicleConnectionReq));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.car.gateway.controller;
|
||||
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInstanceService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 车辆实例控制层
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformation
|
||||
* @Date:2024/10/4 上午9:40
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/vehicle")
|
||||
public class VehicleInstanceController {
|
||||
|
||||
@Autowired private VehicleInstanceService vehicleInstanceService;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.car.gateway.mq;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.mq
|
||||
* @Project:cloud-server-8
|
||||
* @name:CreateExchange
|
||||
* @Date:2024/10/7 下午8:53
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class CreateExchange implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("=====>开始创建交换机");
|
||||
|
||||
try {
|
||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||
|
||||
// 创建Fanout类型的交换机
|
||||
FanoutExchange exchange = new FanoutExchange("ONLINE_EXCHANGE", true, false);
|
||||
|
||||
rabbitAdmin.declareExchange(exchange);
|
||||
|
||||
// 创建队列
|
||||
Queue queue = new Queue("GO_ONLINE", true, false, false);
|
||||
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
|
||||
// Fanout交换机绑定
|
||||
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange));
|
||||
|
||||
log.info("=====>交换机创建成功");
|
||||
log.info("=====>队列创建成功并绑定到交换机");
|
||||
}catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.car.gateway.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import com.muyu.car.domain.model.MqttServerModel;
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationService
|
||||
* @Date:2024/10/6 下午2:40
|
||||
*/
|
||||
public interface VehicleInformationService{
|
||||
MqttServerModel getVehicleData(VehicleConnectionReq vehicleConnectionReq);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.muyu.car.gateway.service;
|
||||
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInstanceService
|
||||
* @Date:2024/10/6 上午10:05
|
||||
*/
|
||||
public interface VehicleInstanceService {
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package com.muyu.car.gateway.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import com.muyu.car.domain.model.MqttServerModel;
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInformationService;
|
||||
import com.muyu.car.mapper.VehicleInformationMapper;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service.impl
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationServiceImpl
|
||||
* @Date:2024/10/6 下午2:41
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleInformationServiceImpl implements VehicleInformationService{
|
||||
|
||||
@Autowired private VehicleInformationMapper vehicleInformationMapper;
|
||||
|
||||
@Autowired private RedisService redisService;
|
||||
|
||||
@Override
|
||||
public MqttServerModel getVehicleData(VehicleConnectionReq vehicleConnectionReq) {
|
||||
log.info("车辆连接请求:[{}]",vehicleConnectionReq);
|
||||
vehicleConnectionReq.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce());
|
||||
|
||||
List<String> selectVehicle =vehicleInformationMapper.selectVehicleVin(vehicleConnectionReq.getVehicleVin());
|
||||
if(selectVehicle.isEmpty()) {
|
||||
vehicleInformationMapper.addVehicleConnection(vehicleConnectionReq);
|
||||
log.info("车辆预上线成功");
|
||||
}else {
|
||||
log.info("车辆无法重复预上线");
|
||||
}
|
||||
|
||||
// 获取名为 "ipList" 的列表
|
||||
List<String> ipList = redisService.getCacheList("ipList");
|
||||
if (ipList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// 获取当前使用的索引位置
|
||||
String indexStr = redisService.getCacheObject("currentIndex");
|
||||
int index = indexStr!= null? Integer.parseInt(indexStr) : 0;
|
||||
String selectedIp = ipList.get(index);
|
||||
// 获取该 IP 的使用次数
|
||||
String countStr = redisService.getCacheMapValue("ipCounts", selectedIp);
|
||||
log.info("IP:[{}]车辆连接数:[{}]",selectedIp,countStr);
|
||||
int count = countStr!= null? Integer.parseInt(countStr) : 0;
|
||||
if (count < 12) {
|
||||
// 使用次数加一
|
||||
count++;
|
||||
redisService.setCacheMapValue("ipCounts", selectedIp, String.valueOf(count));
|
||||
// 更新索引
|
||||
index = (index + 1) % ipList.size();
|
||||
redisService.setCacheObject("currentIndex", String.valueOf(index));
|
||||
return new MqttServerModel("tcp://"+selectedIp.substring(1,selectedIp.length()-1)+":1883","vehicle");
|
||||
} else {
|
||||
// 如果使用次数达到 12 次,跳过该 IP 并更新索引
|
||||
index = (index + 1) % ipList.size();
|
||||
redisService.setCacheObject("currentIndex", String.valueOf(index));
|
||||
return getVehicleData(vehicleConnectionReq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.car.gateway.service.impl;
|
||||
|
||||
import com.muyu.car.domain.model.VehicleInformation;
|
||||
import com.muyu.car.gateway.service.VehicleInstanceService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.gateway.service.impl
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInstanceServceImpl
|
||||
* @Date:2024/10/6 上午10:06
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* 阿里云AccessKey ID Secret
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:CreateClient
|
||||
* @Date:2024/9/29 上午10:41
|
||||
*/
|
||||
@Component
|
||||
public class CreateClient {
|
||||
|
||||
/**
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @return Client
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId("LTAI5tFtQk1KbwRBXM5pHVWw")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("GLByUZqUqgR600eTpGmfb52ZT93mu9");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponseBody;
|
||||
import com.aliyun.tea.*;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 项目关闭清除实例
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:DelInstance
|
||||
* @Date:2024/9/29 上午10:42
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
@Tag(name = "程序停止删除实例")
|
||||
public class DelInstance implements DisposableBean {
|
||||
|
||||
public static void delInstance() throws Exception {
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
com.aliyun.ecs20140526.Client client = CreateClient.createClient();
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-hangzhou");
|
||||
//创建运行时选择对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||
|
||||
//获取实例列表
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
|
||||
|
||||
//提取实例ID集合
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
list.add(instance.getInstanceId());
|
||||
}
|
||||
log.info("Instance IDs: " + list);
|
||||
// 创建删除实例请求对象,并设置请求参数
|
||||
com.aliyun.ecs20140526.models.DeleteInstancesRequest deleteInstancesRequest = new com.aliyun.ecs20140526.models.DeleteInstancesRequest()
|
||||
//设置地域ID,指定删除实例的地域
|
||||
.setRegionId("cn-hangzhou")
|
||||
// 设置DryRun为true,用于验证请求是否可以成功,但不实际执行删除操作
|
||||
.setDryRun(false)
|
||||
// 设置Force为true,表示即使实例有正在运行的任务,也强制删除实例
|
||||
.setForce(true)
|
||||
// 设置TerminateSubscription为true,表示删除按订阅付费的实例时终止订阅
|
||||
.setTerminateSubscription(true)
|
||||
.setInstanceId(list);
|
||||
|
||||
//创建运行时选项对象,用于配置运行时的选项参数
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
log.info("===============>开始执行删除实例方法");
|
||||
delInstance();
|
||||
// 连接到Redis服务器
|
||||
Jedis jedis = new Jedis("159.75.188.178", 6379);
|
||||
// 指定要删除的文件夹(命名空间)
|
||||
String namespace = "InstanceIdKey:";
|
||||
// 获取所有以namespace为前缀的键
|
||||
Set<String> keys = jedis.keys(namespace + "*");
|
||||
// 如果存在键,则删除它们
|
||||
if (keys.size() > 0) {
|
||||
jedis.del(keys.toArray(new String[0]));
|
||||
}
|
||||
// 关闭连接
|
||||
jedis.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import com.aliyun.ecs20140526.models.*;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.muyu.car.domain.example.ExampleInformation;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 项目启动创建实例
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.domain
|
||||
* @Project:cloud-server-8
|
||||
* @name:GenerateInstance
|
||||
* @Date:2024/9/29 上午10:42
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
@Tag(name = "启动时创建实例")
|
||||
public class GenerateInstance implements ApplicationRunner {
|
||||
|
||||
@Autowired private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 启动自动创建实例
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<String> generateInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
com.aliyun.ecs20140526.Client client = CreateClient.createClient();
|
||||
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
|
||||
// 设置地域ID
|
||||
.setRegionId("cn-hangzhou")
|
||||
// 设置镜像ID
|
||||
.setImageId("m-bp1hkxfctk751s62jqhq")
|
||||
// 设置实例类型
|
||||
.setInstanceType("ecs.t6-c1m1.large")
|
||||
// 设置安全组ID
|
||||
.setSecurityGroupId("sg-bp1a7fk8js5pn3fw9p2m")
|
||||
// 设置虚拟交换机ID
|
||||
.setVSwitchId("vsw-bp193np7r01vssqxhh24e")
|
||||
// 设置实例名称
|
||||
.setInstanceName("server-mqtt")
|
||||
// 设置实例付费类型为后付费按量付费
|
||||
.setInstanceChargeType("PostPaid")
|
||||
// 设置互联网最大出带宽为1 Mbps
|
||||
.setInternetMaxBandwidthOut(1)
|
||||
// 设置系统盘配置
|
||||
.setSystemDisk(systemDisk)
|
||||
// 设置主机名
|
||||
.setHostName("root")
|
||||
// 设置实例密码
|
||||
.setPassword("EightGroup123.")
|
||||
// 设置创建实例的数量
|
||||
.setAmount(2);
|
||||
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtime);
|
||||
// 获取body返回值对象
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 得到实例ID数组
|
||||
for (String instance : body.getInstanceIdSets().getInstanceIdSet()) {
|
||||
list.add(instance);
|
||||
}
|
||||
log.info("实例ID:{}",list);
|
||||
return list;
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
List<String> InstanceIds = generateInstance();
|
||||
log.info("创建实例成功");
|
||||
log.info("正在加载实例");
|
||||
Thread.sleep(30000);
|
||||
List<ExampleInformation> exampleInformations = QueryInstance.queryInstance(InstanceIds);
|
||||
log.info("加载成功");
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
for (ExampleInformation exampleInformation : exampleInformations) {
|
||||
redisService.setCacheObject("InstanceIdKey:"+exampleInformation.getInstanceId(),exampleInformation);
|
||||
list.add(exampleInformation.getIpAddress());
|
||||
}
|
||||
redisService.setCacheList("ipList",list);
|
||||
log.info("实例信息:{}",exampleInformations);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package com.muyu.car.instance;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.muyu.car.domain.example.ExampleInformation;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 启动后查询实例信息
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.instance
|
||||
* @Project:cloud-server-8
|
||||
* @name:QueryInstance
|
||||
* @Date:2024/9/29 下午8:58
|
||||
*/
|
||||
@Log4j2
|
||||
public class QueryInstance {
|
||||
|
||||
public static List<ExampleInformation> queryInstance(List<String> instanceIds) throws Exception {
|
||||
com.aliyun.ecs20140526.Client client = CreateClient.createClient();
|
||||
|
||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||
.setInstanceIds(JSON.toJSONString(instanceIds))
|
||||
.setRegionId("cn-hangzhou");
|
||||
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
ArrayList<ExampleInformation> exampleInformations = new ArrayList<>();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
ExampleInformation exampleInformation = new ExampleInformation();
|
||||
exampleInformation.setInstanceId(instance.getInstanceId());
|
||||
log.info("实例ID:{}",exampleInformation.getInstanceId());
|
||||
exampleInformation.setStatus(instance.getStatus());
|
||||
log.info("实例状态:{}",exampleInformation.getStatus());
|
||||
exampleInformation.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
log.info("实例IP:{}",exampleInformation.getIpAddress());
|
||||
exampleInformations.add(exampleInformation);
|
||||
}
|
||||
log.info("实例信息:{}",exampleInformations);
|
||||
return exampleInformations;
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.car.mapper;
|
||||
|
||||
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.car.mapper
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleInformationMapper
|
||||
* @Date:2024/10/6 下午2:19
|
||||
*/
|
||||
@Mapper
|
||||
public interface VehicleInformationMapper {
|
||||
void addVehicleConnection(VehicleConnectionReq vehicleConnectionReq);
|
||||
|
||||
List<String> selectVehicleVin(@Param("vehicleVin") String vehicleVin);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.car.util;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@Log4j2
|
||||
public class MD5Util {
|
||||
|
||||
private static final Integer SALT_LENGTH = 12;
|
||||
|
||||
/**
|
||||
* 将指定byte数组转换成16进制字符串
|
||||
* @param b 字节数组
|
||||
* @return 返回结果字符串
|
||||
*/
|
||||
public static String byteToHexString(byte[] b) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte value : b) {
|
||||
String hex = Integer.toHexString(value & 0xFF);
|
||||
if (hex.length() == 1) {
|
||||
hex = '0' + hex;
|
||||
}
|
||||
hexString.append(hex.toUpperCase());
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得加密后的口令
|
||||
* @param str 需要加密的字符串
|
||||
* @return 加密后的字符串
|
||||
*/
|
||||
public static String encrypted (String str) {
|
||||
try {
|
||||
// 声明加密后的口令数组变量
|
||||
byte[] pwd = null;
|
||||
// 随机数生成器
|
||||
SecureRandom random = new SecureRandom();
|
||||
// 声明盐数组变量
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
// 将随机数放入盐变量中
|
||||
random.nextBytes(salt);
|
||||
|
||||
// 声明消息摘要对象
|
||||
MessageDigest md = null;
|
||||
// 创建消息摘要
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
// 将盐数据传入消息摘要对象
|
||||
md.update(salt);
|
||||
// 将口令的数据传给消息摘要对象
|
||||
md.update(str.getBytes(StandardCharsets.UTF_8));
|
||||
// 获得消息摘要的字节数组
|
||||
byte[] digest = md.digest();
|
||||
|
||||
// 因为要在口令的字节数组中存放盐,所以加上盐的字节长度
|
||||
pwd = new byte[digest.length + SALT_LENGTH];
|
||||
// 将盐的字节拷贝到生成的加密口令字节数组的前12个字节,以便在验证口令时取出盐
|
||||
System.arraycopy(salt, 0, pwd, 0, SALT_LENGTH);
|
||||
// 将消息摘要拷贝到加密口令字节数组从第13个字节开始的字节
|
||||
System.arraycopy(digest, 0, pwd, SALT_LENGTH, digest.length);
|
||||
// 将字节数组格式加密后的口令转化为16进制字符串格式的口令
|
||||
return byteToHexString(pwd);
|
||||
}catch (Exception exception){
|
||||
log.info("md5加密失败:[{}]", str, exception);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-car-gateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-wechat"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-wechat"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
<!-- 控制台输出 -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.sky.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/info.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>INFO</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- 日志文件名格式 -->
|
||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
<!-- 匹配时的操作:接收(记录) -->
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||
<Pattern>${log.sky.pattern}</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.muyu" level="info"/>
|
||||
<!-- Spring日志级别控制 -->
|
||||
<logger name="org.springframework" level="warn"/>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="GRPC_LOG"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info"/>
|
||||
<appender-ref ref="file_error"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.@//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.car.mapper.VehicleInformationMapper">
|
||||
<insert id="addVehicleConnection">
|
||||
INSERT INTO `vehicle_connection` (`vin`, `timestamp`, `username`, `nonce`,`password`) VALUES (#{vehicleVin}, #{timestamp}, #{username}, #{nonce},#{password});
|
||||
</insert>
|
||||
<select id="selectVehicleVin" resultType="java.lang.String">
|
||||
select
|
||||
`vin`, `timestamp`, `username`, `nonce`,`password`
|
||||
from
|
||||
`vehicle_connection`
|
||||
where `vin` = #{vehicleVin}
|
||||
</select>
|
||||
</mapper>
|
|
@ -8,12 +8,10 @@
|
|||
<artifactId>cloud-modules</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-modules-carData</artifactId>
|
||||
|
||||
<description>
|
||||
数据处理模块
|
||||
cloud-modules-carData数据处理模块
|
||||
</description>
|
||||
<artifactId>cloud-modules-carData</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
|
@ -21,7 +19,10 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -99,5 +100,11 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.muyu.carData;
|
||||
|
||||
import com.muyu.carData.listener.MyListener;
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
|
@ -14,11 +16,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
*/
|
||||
@SpringBootApplication
|
||||
@EnableMyFeignClients
|
||||
@EnableCustomConfig
|
||||
@EnableAsync
|
||||
@EnableCaching
|
||||
public class CarDataApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication application = new SpringApplication(CarDataApplication.class);
|
||||
application.addListeners(new MyListener());
|
||||
application.run(args);
|
||||
SpringApplication.run(CarDataApplication.class,args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
package com.muyu.carData.config.lotdbconfig;
|
||||
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
import org.apache.iotdb.session.Session;
|
||||
import org.apache.iotdb.session.SessionDataSet;
|
||||
import org.apache.iotdb.session.pool.SessionPool;
|
||||
import org.apache.iotdb.tsfile.read.common.Field;
|
||||
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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 org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -76,6 +83,66 @@ public class IotDBSessionConfig {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加操作
|
||||
* @param deviceId
|
||||
* @param time 时间戳
|
||||
* @param measurements
|
||||
* @param values 值
|
||||
*/
|
||||
public void execute(String deviceId,long time,List<String> measurements,List<String> values){
|
||||
if (CollectionUtils.isEmpty(measurements) && !CollectionUtils.isEmpty(values)){
|
||||
try {
|
||||
iotSession().insertAlignedRecord(deviceId,time,measurements,values);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询操作
|
||||
* @param sql
|
||||
* @return
|
||||
*/
|
||||
public List<HashMap<String,Object>> executeQuery(String sql){
|
||||
logger.info("sql:{}",sql);
|
||||
List<HashMap<String,Object>> list = new ArrayList<>();
|
||||
|
||||
try {
|
||||
SessionDataSet sessionDataSet = iotSession().executeQueryStatement(sql);
|
||||
int fetchSize = sessionDataSet.getFetchSize();
|
||||
List<String> columnNames = sessionDataSet.getColumnNames();
|
||||
logger.info("columnNames:{}",columnNames);
|
||||
List<String> columnTypes = sessionDataSet.getColumnTypes();
|
||||
logger.info("columnTypes:{}",columnTypes);
|
||||
if (fetchSize > 0){
|
||||
while (sessionDataSet.hasNext()){
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
RowRecord next = sessionDataSet.next();
|
||||
List<Field> fields = next.getFields();
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
Field field = fields.get(i);
|
||||
String key = field.getStringValue();
|
||||
Object value = field.getObjectValue(field.getDataType());
|
||||
map.put(key,value);
|
||||
}
|
||||
list.add(map);
|
||||
}
|
||||
|
||||
sessionDataSet.closeOperationHandle();
|
||||
}
|
||||
} catch (StatementExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IoTDBConnectionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import com.muyu.carData.util.CacheUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 车辆下线消费者
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.consumer
|
||||
* @Project:cloud-server-8
|
||||
* @name:CarOffConsumer
|
||||
* @Date:2024/10/4 14:30
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class CarOffConsumer {
|
||||
|
||||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(value = "CAR_OFFLINE",durable = "true"),
|
||||
exchange = @Exchange(value = "CAR_OFF_EXCHANGE",type = "fanout")
|
||||
))
|
||||
public void inline(String vin){
|
||||
log.info("车辆vin:{},车辆下线成功!开始消费...");
|
||||
cacheUtil.remove(vin);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import com.muyu.carData.util.CacheUtil;
|
||||
import com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**车辆上线消费者
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.consumer
|
||||
* @Project:cloud-server-8
|
||||
* @name:CarOnlineConsumer
|
||||
* @Date:2024/10/4 14:27
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class CarOnlineConsumer {
|
||||
|
||||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
@Autowired
|
||||
private VehicleCacheFaultCodeAddService vehicleCacheCarInformationAddService;
|
||||
|
||||
|
||||
@RabbitListener(queues = "myQueue",containerFactory = "rabbitListenerContainerFactory")
|
||||
public void consumeMessage(String message) {
|
||||
// 处理接收到的消息
|
||||
log.info("接收到消息======>>" + message);
|
||||
}
|
||||
|
||||
/*
|
||||
@Bean
|
||||
public DirectExchange initVehicleGatewayExchange(){
|
||||
return new DirectExchange(VehicleGatewayConstants.VEHICLE_GETAWAY_EXCHANGE);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/*@Bean
|
||||
@Primary
|
||||
public Queue initQueue(){
|
||||
return new Queue("gateway", true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding binding1a(DirectExchange initVehicleGatewayExchange,
|
||||
Queue initQueue) {
|
||||
return BindingBuilder.bind(initQueue)
|
||||
.to(initVehicleGatewayExchange)
|
||||
.with(VehicleGatewayConstants.VEHICLE_GETAWAY_ROUTING_KEY);
|
||||
}
|
||||
|
||||
@RabbitListener(queues = "gateway")
|
||||
public void msg(@RequestBody WebHookConnection webHookConnection){
|
||||
log.info("消费者接收到车辆上线信息:{}",webHookConnection);
|
||||
}*/
|
||||
}
|
|
@ -1,19 +1,23 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.common.collect.Lists;
|
||||
import com.muyu.carData.pojo.Student;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.event.EventPublisher;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**卡夫卡消费者
|
||||
* @Author:张腾
|
||||
|
@ -24,33 +28,43 @@ import java.util.Collection;
|
|||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class MyKafkaConsumer implements InitializingBean {
|
||||
public class MyKafkaConsumer implements ApplicationRunner, ApplicationListener<ContextClosedEvent> {
|
||||
|
||||
@Autowired
|
||||
private KafkaConsumer kafkaConsumer;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher eventPublisher;
|
||||
|
||||
private final String topicName = "carJsons";
|
||||
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
log.info("启动线程开始监听topic:{}",topicName);
|
||||
Thread thread = new Thread(() -> {
|
||||
ThreadUtil.sleep(1000);
|
||||
Collection<String> topics = Lists.newArrayList(topicName);
|
||||
kafkaConsumer.subscribe(topics);
|
||||
while (true){
|
||||
ConsumerRecords<String,String> consumerRecords = kafkaConsumer.poll(Duration.ofMillis(1000));
|
||||
for (ConsumerRecord<String, String> consumerRecord : consumerRecords) {
|
||||
//从consumerRecord中获取消费数据
|
||||
String value = consumerRecord.value();
|
||||
log.info("从Kafka中消费的原始数据===============>>:{}",value);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("开始监听kafka-topic:{}",topicName);
|
||||
List<String> topics = Collections.singletonList(topicName);
|
||||
kafkaConsumer.subscribe(topics);
|
||||
|
||||
log.info("启动线程结束监听topic:{}",topicName);
|
||||
while (true){
|
||||
ConsumerRecords<String,String> consumerRecords = kafkaConsumer.poll(Duration.ofMillis(100));
|
||||
consumerRecords.forEach(record ->{
|
||||
executorService.submit(() -> handleRecord(record));
|
||||
log.info("数据为:{},消费成功!",record);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRecord(ConsumerRecord<String,String> record) {
|
||||
String value = record.value();
|
||||
JSONObject jsonObject = JSONObject.parseObject(value);
|
||||
eventPublisher.publishEvent(jsonObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent event) {
|
||||
log.info("关闭kafka和线程");
|
||||
kafkaConsumer.close();
|
||||
executorService.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.common.rabbit.contants
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleGatewayContantsA
|
||||
* @Date:2024/10/10 上午9:02
|
||||
*/
|
||||
public class VehicleGatewayConstants {
|
||||
|
||||
/**
|
||||
* 车辆网关交换机
|
||||
*/
|
||||
public final static String VEHICLE_GETAWAY_EXCHANGE = "vehicle.getaway";
|
||||
|
||||
/**
|
||||
* 车辆网关交换机上线路由键A
|
||||
*/
|
||||
public final static String VEHICLE_GETAWAY_ROUTING_KEY = "vehicle.getaway.online";
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
package com.muyu.carData.controller;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
|
@ -8,13 +9,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
*/
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.controller
|
||||
* @Project:cloud-server-8
|
||||
* @name:TestController
|
||||
* @Date:2024/9/26 23:56
|
||||
*/
|
||||
*//*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/testCache")
|
||||
@Log4j2
|
||||
|
@ -42,3 +45,4 @@ public class CacheController {
|
|||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
package com.muyu.carData.controller;
|
||||
|
||||
import com.muyu.carData.config.lotdbconfig.IotDBSessionConfig;
|
||||
|
@ -17,13 +18,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
*/
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.testcontroller
|
||||
* @Project:cloud-server-8
|
||||
* @name:IotDBController
|
||||
* @Date:2024/9/28 23:58
|
||||
*/
|
||||
*//*
|
||||
|
||||
@RequestMapping("/iotdb")
|
||||
@RestController
|
||||
@Log4j2
|
||||
|
@ -33,14 +36,16 @@ public class IotDBController {
|
|||
@Autowired
|
||||
private IotDBSessionConfig iotDBSessionConfig;
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* 批量插入数据
|
||||
* @param insertSize 每次插入的条数
|
||||
* @param count 插入的总条数
|
||||
* @return
|
||||
* @throws IoTDBConnectionException
|
||||
* @throws StatementExecutionException
|
||||
*/
|
||||
*//*
|
||||
|
||||
@GetMapping("/insertData/{insertSize}/{count}")
|
||||
public String insert(@PathVariable(name = "insertSize") int insertSize,@PathVariable(name = "count") int count) throws IoTDBConnectionException, StatementExecutionException {
|
||||
Session session = iotDBSessionConfig.iotSession();
|
||||
|
@ -82,7 +87,7 @@ public class IotDBController {
|
|||
}
|
||||
|
||||
|
||||
/* @GetMapping("/batchInsertRecords/{num}")
|
||||
@GetMapping("/batchInsertRecords/{num}")
|
||||
public String batchInsertRecords(@PathVariable Integer num){
|
||||
String deviceId = "root.yang";
|
||||
|
||||
|
@ -109,5 +114,6 @@ public class IotDBController {
|
|||
for (int i = 0; i < num; i++) {
|
||||
deviceIds.add()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
package com.muyu.carData.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
@ -9,13 +10,15 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
*/
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.testcontroller
|
||||
* @Project:cloud-server-8
|
||||
* @name:KafkaProducerController
|
||||
* @Date:2024/9/28 15:10
|
||||
*/
|
||||
*//*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/produce")
|
||||
@Log4j2
|
||||
|
@ -43,3 +46,4 @@ public class KafkaProducerController {
|
|||
|
||||
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -15,8 +15,12 @@ public class EsSaveEvent extends ApplicationEvent {
|
|||
private JSONObject data;
|
||||
|
||||
|
||||
public EsSaveEvent(JSONObject source) {
|
||||
public EsSaveEvent(Object source,JSONObject data) {
|
||||
super(source);
|
||||
this.data = source;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public JSONObject getData(){
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.carData.event;
|
||||
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
/** 事件监听接口
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.event
|
||||
* @Project:cloud-server-8
|
||||
* @name:EventListener
|
||||
* @Date:2024/10/4 10:39
|
||||
*/
|
||||
public interface EventListener extends ApplicationListener<EsSaveEvent> {
|
||||
|
||||
void onEvent(EsSaveEvent event);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.carData.event;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 策略发送事件
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.event
|
||||
* @Project:cloud-server-8
|
||||
* @name:EventPublisher
|
||||
* @Date:2024/10/4 10:40
|
||||
*/
|
||||
@Component
|
||||
public class EventPublisher implements ApplicationEventPublisherAware {
|
||||
|
||||
private ApplicationEventPublisher publisher;
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.publisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
public void publishEvent(JSONObject message){
|
||||
EsSaveEvent esSaveEvent = new EsSaveEvent(this, message);
|
||||
publisher.publishEvent(esSaveEvent);
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:CustomEventListener
|
||||
* @Date:2024/9/29 23:49
|
||||
*/
|
||||
@Component
|
||||
public class CustomEventListener {
|
||||
|
||||
@EventListener
|
||||
public void handMyEvent(EsSaveEvent event){
|
||||
//处理事件详情
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import com.muyu.carData.event.EventListener;
|
||||
import com.muyu.carData.util.CacheUtil;
|
||||
import com.muyu.domain.FaultCodeCache;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 判断故障信息
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:IdentifyingFailuresListener
|
||||
* @Date:2024/10/8 11:22
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class IdentifyingFailuresListener implements EventListener {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
@Override
|
||||
public void onEvent(EsSaveEvent event) {
|
||||
log.info("规则预警事件开始...");
|
||||
JSONObject data = event.getData();
|
||||
String vin = (String) data.get("vin");
|
||||
String str = cacheUtil.get(vin).toString();
|
||||
FaultCodeCache faultCodeCache = JSON.parseObject(str, FaultCodeCache.class);
|
||||
log.info("规则预警事件结束...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EsSaveEvent event) {
|
||||
onEvent(event);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.config.lotdbconfig.IotDBSessionConfig;
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import com.muyu.carData.event.EventListener;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** 数据持久化事件
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:InsertIotDBListener
|
||||
* @Date:2024/10/6 9:25
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class InsertIotDBListener implements EventListener {
|
||||
@Override
|
||||
public void onEvent(EsSaveEvent event) {
|
||||
JSONObject jsonObject = event.getData();
|
||||
log.info("持久化:监听到数据:{}", jsonObject);
|
||||
List<String> keys = new ArrayList<>();
|
||||
List<String> values = new ArrayList<>();
|
||||
|
||||
jsonObject.forEach((key,value) -> {
|
||||
keys.add(key);
|
||||
values.add((String) value);
|
||||
});
|
||||
|
||||
IotDBSessionConfig iotDBSessionConfig = new IotDBSessionConfig();
|
||||
long time = System.currentTimeMillis();
|
||||
iotDBSessionConfig.execute("root.vehicle",time,keys,values);
|
||||
log.info("数据写入成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EsSaveEvent event) {
|
||||
onEvent(event);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
/**自定义监听器
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:MyListener
|
||||
* @Date:2024/9/29 21:18
|
||||
*/
|
||||
@Log4j2
|
||||
public class MyListener implements ApplicationListener<EsSaveEvent> {
|
||||
@Override
|
||||
public void onApplicationEvent(EsSaveEvent event) {
|
||||
log.info("监听到自定义事件........");
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.muyu.carData.pojo;
|
||||
|
||||
import com.muyu.carData.config.cacheconfig.ExpiryTime;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.pojo
|
||||
* @Project:cloud-server-8
|
||||
* @name:Student
|
||||
* @Date:2024/9/27 0:40
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Student extends ExpiryTime{
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 插入时间
|
||||
*/
|
||||
private long time = System.currentTimeMillis();
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.muyu.carData.pulisher;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**事件发布测试
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.pulisher
|
||||
* @Project:cloud-server-8
|
||||
* @name:CustomEventPublisher
|
||||
* @Date:2024/9/29 23:51
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class CustomEventPublisher {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
public void publish(JSONObject data){
|
||||
EsSaveEvent esSaveEvent = new EsSaveEvent(data);
|
||||
applicationEventPublisher.publishEvent(esSaveEvent);
|
||||
log.info("事件发布成功 - 消息是:{}",data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.carData.util;
|
||||
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 缓存工具类
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.util
|
||||
* @Project:cloud-server-8
|
||||
* @name:CacheUtil
|
||||
* @Date:2024/10/4 10:42
|
||||
*/
|
||||
@Component
|
||||
public class CacheUtil<T> {
|
||||
|
||||
private final Cache<String,T> cache;
|
||||
|
||||
public CacheUtil() {
|
||||
this.cache = Caffeine.newBuilder()
|
||||
.maximumSize(500L)
|
||||
.build();
|
||||
}
|
||||
|
||||
public T get(String key) {
|
||||
return (T)cache.getIfPresent(key);
|
||||
}
|
||||
|
||||
public void put(String key, T value) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
|
||||
public void remove(String key) {
|
||||
cache.invalidate(key);
|
||||
}
|
||||
}
|
|
@ -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-modules-enterprise</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
<description>
|
||||
cloud-modules-enterprise-cache 缓存模块
|
||||
</description>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.enterprise.cache.car;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.req.CarInformationAddReq;
|
||||
|
||||
/**
|
||||
* 添加车辆信息
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheCarInformationAddService extends CacheAbsBasic<String, CarInformationAddReq> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarInformationAddReq:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.enterprise.cache.car;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.resp.CarInformationResp;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 车辆缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheCarInformationService extends CacheAbsBasic<String, List<CarInformationResp>> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarInformation:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.enterprise.cache.car;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.req.CarInformationUpdReq;
|
||||
|
||||
/**
|
||||
* 车辆管理修改缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheCarInformationUpdService extends CacheAbsBasic<String, CarInformationUpdReq> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarInformationUpdReq:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.enterprise.cache.car;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.CarFence;
|
||||
import com.muyu.domain.CarType;
|
||||
|
||||
/**
|
||||
* 车辆类型表缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheCarTypeService extends CacheAbsBasic<String, CarType> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarType:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.enterprise.cache.fault;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.FaultCode;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
|
||||
/**
|
||||
* 故障码缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheFaultService extends CacheAbsBasic<String, FaultCode> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "FaultCode:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.enterprise.cache.faultCode;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.FaultCodeCache;
|
||||
import com.muyu.domain.req.CarInformationAddReq;
|
||||
import com.muyu.domain.req.FaultCodeAddReq;
|
||||
|
||||
/**
|
||||
* 添加故障码缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheFaultCodeAddService extends CacheAbsBasic<String, FaultCodeCache> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "FaultCodeCache:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.enterprise.cache.fence;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.CarFence;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
|
||||
/**
|
||||
* 电子围栏add缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheFenceAddService extends CacheAbsBasic<String, CarFence> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarFenceAdd:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.enterprise.cache.fence;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.CarFence;
|
||||
import com.muyu.domain.CarInformation;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 电子围栏缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheFenceService extends CacheAbsBasic<String, CarFenceResp> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "CarFenceResp:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.enterprise.cache.warn;
|
||||
|
||||
import com.muyu.common.cache.CacheAbsBasic;
|
||||
import com.muyu.domain.WarnStrategy;
|
||||
import com.muyu.domain.resp.CarFenceResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 电子围栏缓存
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.cache
|
||||
* @Project:cloud-server-8
|
||||
* @name:VehicleCacheService
|
||||
* @Date:2024/9/30 11:50
|
||||
*/
|
||||
public class VehicleCacheWarnService extends CacheAbsBasic<String, List<WarnStrategy>> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "WarnStrategy:info:";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("vehicle:info:","");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationAddService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarInformationUpdService
|
||||
com.muyu.enterprise.cache.car.VehicleCacheCarTypeService
|
||||
com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService
|
||||
com.muyu.enterprise.cache.fence.VehicleCacheFenceService
|
||||
com.muyu.enterprise.cache.fence.VehicleCacheFenceAddService
|
||||
com.muyu.enterprise.cache.fault.VehicleCacheFaultService
|
||||
com.muyu.enterprise.cache.warn.VehicleCacheWarnService
|
|
@ -15,8 +15,8 @@
|
|||
cloud-modules-enterprise-common 企业业务common
|
||||
</description>
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.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.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -25,6 +27,7 @@ public class CarFenceClazz {
|
|||
/**
|
||||
* 业务类型ID
|
||||
*/
|
||||
@TableId(value = "clazz_id",type = IdType.AUTO)
|
||||
private Integer clazzId;
|
||||
/**
|
||||
* 业务类型名称
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.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.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -25,6 +27,7 @@ public class CarFenceType {
|
|||
/**
|
||||
* 围栏类型ID
|
||||
*/
|
||||
@TableId(value = "type_id",type = IdType.AUTO)
|
||||
private Integer typeId;
|
||||
/**
|
||||
* 围栏类型名称
|
||||
|
|
|
@ -71,8 +71,8 @@ public class CarInformation {
|
|||
/**
|
||||
* 车辆类型外键ID
|
||||
*/
|
||||
@Schema(title = "车辆类型外键ID", type = "Integer")
|
||||
private Integer carInformationType;
|
||||
// @Schema(title = "车辆类型外键ID", type = "Long")
|
||||
private Long carInformationType;
|
||||
/**
|
||||
* 车辆品牌
|
||||
*/
|
||||
|
@ -107,6 +107,13 @@ public class CarInformation {
|
|||
*/
|
||||
private Integer carInformationState;
|
||||
|
||||
/**
|
||||
* 车辆策略id
|
||||
*/
|
||||
private Integer carStrategyId;
|
||||
|
||||
|
||||
|
||||
public static CarInformation carInformationBuilder(CarInformation carInformation) {
|
||||
return CarInformation.builder()
|
||||
.carInformationId(carInformation.getCarInformationId())
|
||||
|
@ -147,4 +154,23 @@ public class CarInformation {
|
|||
.carInformationMotorModel(carInformation.getCarInformationMotorModel())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CarInformation carInformationListBuilder(CarInformation carInformation) {
|
||||
return CarInformation.builder()
|
||||
.carInformationId(carInformation.getCarInformationId())
|
||||
.carInformationVIN(carInformation.getCarInformationVIN())
|
||||
.carInformationLicensePlate(carInformation.getCarInformationLicensePlate())
|
||||
.carInformationBrand(carInformation.getCarInformationBrand())
|
||||
.carInformationColor(carInformation.getCarInformationColor())
|
||||
.carInformationDriver(carInformation.getCarInformationDriver())
|
||||
.carInformationMotorManufacturer(carInformation.getCarInformationMotorManufacturer())
|
||||
.carInformationMotorModel(carInformation.getCarInformationMotorModel())
|
||||
.carInformationBatteryManufacturer(carInformation.getCarInformationBatteryManufacturer())
|
||||
.carInformationBatteryModel(carInformation.getCarInformationBatteryModel())
|
||||
.carInformationFence(carInformation.getCarInformationFence())
|
||||
.carInformationType(carInformation.getCarInformationType())
|
||||
.carInformationMotorModel(carInformation.getCarInformationMotorModel())
|
||||
.carStrategyId(carInformation.getCarStrategyId())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.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.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -25,6 +27,7 @@ public class CarMessage {
|
|||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
@TableId(value = "message_type_id",type = IdType.AUTO)
|
||||
private Long messageTypeId;
|
||||
/**
|
||||
* 报文编码
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.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.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -26,7 +28,8 @@ public class CarType {
|
|||
/**
|
||||
* 车辆类型ID
|
||||
*/
|
||||
private long carTypeId;
|
||||
@TableId(value = "car_type_id",type = IdType.AUTO)
|
||||
private Long carTypeId;
|
||||
/**
|
||||
* 车辆类型名
|
||||
*/
|
||||
|
|
|
@ -36,7 +36,7 @@ public class FaultCode {
|
|||
*故障码Id
|
||||
*/
|
||||
@TableId(value = "faultcode_id",type = IdType.AUTO)
|
||||
private long faultcodeId;
|
||||
private Long faultcodeId;
|
||||
/**
|
||||
*故障名称Id
|
||||
*/
|
||||
|
@ -85,7 +85,7 @@ public class FaultCode {
|
|||
|
||||
public static FaultCode addfaultcode(FaultCodeAddReq faultCodeAddReq){
|
||||
return FaultCode.builder()
|
||||
.faultcodeId(0)
|
||||
.faultcodeId(faultCodeAddReq.getFaultcodeId())
|
||||
.messageTypeId(faultCodeAddReq.getMessageTypeId())
|
||||
.faultcodeNumber(faultCodeAddReq.getFaultcodeNumber())
|
||||
.faultGroup(faultCodeAddReq.getFaultGroup())
|
||||
|
@ -97,7 +97,7 @@ public class FaultCode {
|
|||
|
||||
public static FaultCode updfaultcode(FaultCodeUpdReq faultCodeUpdReq){
|
||||
return FaultCode.builder()
|
||||
.faultcodeId(0)
|
||||
.faultcodeId(0L)
|
||||
.messageTypeId(faultCodeUpdReq.getMessageTypeId())
|
||||
.faultcodeNumber(faultCodeUpdReq.getFaultcodeNumber())
|
||||
.faultGroup(faultCodeUpdReq.getFaultGroup())
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue