commit
1f98e4ea26
|
@ -25,11 +25,7 @@
|
|||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>enterpise-common</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.domain;
|
|||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.domain.req.MessageTemplateAddReq;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.domain.req.MessageTemplateAddReq;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
|
|
@ -5,19 +5,18 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 车辆类型实体类
|
||||
* *@ClassName SysCarType
|
||||
* * @Description TODO
|
||||
* * @Author Li HD
|
||||
* * @Date 2024/9/22 15:48
|
||||
* @ClassName SysCarType
|
||||
* @Description TODO
|
||||
* @Author Li HD
|
||||
* @Date 2024/9/22 15:48
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
<?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</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-modules-vehicleGateway</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-modules-vehicleGateway车辆网关模块
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mqtt.version>1.2.5</mqtt.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- MQTT -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>${mqtt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 阿里云 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>5.1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-console</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– Cloud Gateway –>-->
|
||||
<!-- <!– SpringCloud Gateway –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-starter-gateway</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– SpringCloud Alibaba Sentinel Gateway –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– Sentinel Datasource Nacos –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.alibaba.csp</groupId>-->
|
||||
<!-- <artifactId>sentinel-datasource-nacos</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– SpringCloud Loadbalancer –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.cloud</groupId>-->
|
||||
<!-- <artifactId>spring-cloud-loadbalancer</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– MuYu Common Redis–>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.muyu</groupId>-->
|
||||
<!-- <artifactId>cloud-common-redis</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.xiaoymin</groupId>-->
|
||||
<!-- <artifactId>knife4j-gateway-spring-boot-starter</artifactId>-->
|
||||
<!-- <version>4.5.0</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringBoot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MuYu Common 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>
|
||||
|
||||
</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,22 @@
|
|||
package com.muyu;
|
||||
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 车辆网关启动程序
|
||||
*
|
||||
* @author LiHD
|
||||
*/
|
||||
@Log4j2
|
||||
@EnableCustomConfig
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class CloudVehicleGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudVehicleGatewayApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package com.muyu.vehicleGateway;
|
||||
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 清除阿里云ECS实例
|
||||
* @ClassName ClearInstance
|
||||
* @author LiHD
|
||||
* @Date 2024/9/28 22:29
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ClearInstance implements DisposableBean {
|
||||
|
||||
/**
|
||||
* <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("LTAI5tM4LSerzWQ9wUPXgybq")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("hkiPr0QwkKMZauhXucgg1SDriXUW0Q");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-beijing.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
public static void clearInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
com.aliyun.ecs20140526.Client client = ClearInstance.createClient();
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-beijing");
|
||||
|
||||
//创建运行时选择对象,用于配置运行时的选项参数
|
||||
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-beijing")
|
||||
// 设置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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
log.info("开始执行删除实例方法");
|
||||
clearInstance();
|
||||
log.info("删除实例方法执行完毕");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package com.muyu.vehicleGateway;
|
||||
|
||||
import com.aliyun.tea.TeaException;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 创建阿里云ECS实例
|
||||
* @className Sample
|
||||
* @author LiHD
|
||||
* @date 2024/9/28 19:02
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class CreateInstance implements ApplicationRunner{
|
||||
|
||||
/**
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @return Client
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId("LTAI5tM4LSerzWQ9wUPXgybq")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("hkiPr0QwkKMZauhXucgg1SDriXUW0Q");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-beijing.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 本程序的入口点
|
||||
* 主要功能是创建阿里云ECS实例
|
||||
*
|
||||
* @throws Exception 如果执行过程中发生错误则抛出异常
|
||||
*/
|
||||
public static void sample() throws Exception {
|
||||
|
||||
// 创建阿里云ECS客户端
|
||||
com.aliyun.ecs20140526.Client client = CreateInstance.createClient();
|
||||
|
||||
// 配置系统盘参数
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40") // 设置系统盘大小为40GB
|
||||
.setCategory("cloud_essd"); // 设置系统盘类型为cloud_essd
|
||||
|
||||
// 创建创建实例请求对象并设置参数
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
|
||||
.setRegionId("cn-beijing") // 设置地域ID
|
||||
.setImageId("m-2ze801i45fclmf1qwes5") // 设置镜像ID
|
||||
.setInstanceType("ecs.e-c1m1.large") // 设置实例类型
|
||||
.setSecurityGroupId("sg-2ze63acc0bas9vjm5gtv") // 设置安全组ID
|
||||
.setVSwitchId("vsw-2ze028qk4xpwk3i0ggket") // 设置虚拟交换机ID
|
||||
.setInstanceName("server-mqtt") // 设置实例名称
|
||||
.setInstanceChargeType("PostPaid") // 设置实例付费类型为后付费按量付费
|
||||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("Lhd.123456") // 设置实例密码
|
||||
.setAmount(1) // 设置创建实例的数量
|
||||
.setInternetChargeType("PayByTraffic") // 设置互联网计费类型为按流量计费
|
||||
.setInternetMaxBandwidthOut(5); // 设置最大出带宽为5Mbps
|
||||
|
||||
// 创建运行时选项对象
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.runInstancesWithOptions(runInstancesRequest, runtime);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("开始执行创建实例方法");
|
||||
sample();
|
||||
log.info("创建实例方法执行完毕");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.muyu.vehicleGateway;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
|
||||
@Log4j2
|
||||
@Slf4j
|
||||
public class MqttPublishSample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 定义一个用于MQTT消息发布的示例程序
|
||||
String topic = "vehicleGateway";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://123.57.152.124:1883";
|
||||
String clientId = "JavaSample";
|
||||
|
||||
try {
|
||||
// 创建MQTT客户端并连接到指定的broker
|
||||
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) {
|
||||
// 处理MQTT异常
|
||||
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,68 @@
|
|||
package com.muyu.vehicleGateway.vehicle;
|
||||
|
||||
import com.muyu.vehicleGateway.vehicle.model.VehicleData;
|
||||
import com.muyu.vehicleGateway.vehicle.thread.VehicleThread;
|
||||
import com.muyu.vehicleGateway.web.domain.VehicleInfo;
|
||||
import com.muyu.vehicleGateway.web.domain.model.PositionModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* 车辆实例
|
||||
* @className VehicleInstance
|
||||
* @author LiHD
|
||||
* @date 2024/9/27 20:37
|
||||
*/
|
||||
@Data
|
||||
@Log4j2
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleInstance {
|
||||
|
||||
/**
|
||||
* 路线轨迹编码
|
||||
*/
|
||||
private String postitionCode;
|
||||
|
||||
/**
|
||||
* 路径队列
|
||||
*/
|
||||
@Builder.Default
|
||||
private LinkedBlockingQueue<PositionModel> positionQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
/**
|
||||
* 车辆
|
||||
*/
|
||||
private VehicleInfo vehicleInfo;
|
||||
|
||||
/**
|
||||
* 实例数据
|
||||
*/
|
||||
private VehicleData vehicleData;
|
||||
|
||||
/**
|
||||
* 上一次定位点
|
||||
*/
|
||||
private PositionModel lastPosition;
|
||||
|
||||
/**
|
||||
* 车辆工作线程
|
||||
*/
|
||||
private VehicleThread vehicleThread;
|
||||
|
||||
/**
|
||||
* 获取当前车辆VIN
|
||||
* @return VIN
|
||||
*/
|
||||
public String getVin() {
|
||||
return this.vehicleInfo.getVin();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,539 @@
|
|||
package com.muyu.vehicleGateway.vehicle.model;
|
||||
|
||||
import com.muyu.vehicleGateway.web.domain.VehicleInfo;
|
||||
import com.muyu.vehicleGateway.web.util.VehicleUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @ClassName VehicleData
|
||||
* @Description 车辆模拟数据对象
|
||||
* @Author LiHD
|
||||
* @Date 2024/9/27 22:11
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VehicleData {
|
||||
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* 行驶路线
|
||||
*/
|
||||
private String drivingRoute;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
|
||||
/**
|
||||
* 维度
|
||||
*/
|
||||
private String latitude;
|
||||
|
||||
/**
|
||||
* 速度
|
||||
*/
|
||||
private String speed;
|
||||
|
||||
/**
|
||||
* 里程
|
||||
*/
|
||||
private BigDecimal mileage;
|
||||
|
||||
/**
|
||||
* 总电压
|
||||
*/
|
||||
private String voltage;
|
||||
|
||||
/**
|
||||
* 总电流
|
||||
*/
|
||||
private String current;
|
||||
|
||||
/**
|
||||
* 绝缘电阻
|
||||
*/
|
||||
private String resistance;
|
||||
|
||||
/**
|
||||
* 档位
|
||||
*/
|
||||
@Builder.Default
|
||||
private String gear = "P";
|
||||
|
||||
/**
|
||||
* 加速踏板行程值
|
||||
*/
|
||||
private String accelerationPedal;
|
||||
|
||||
/**
|
||||
* 制动踏板行程值
|
||||
*/
|
||||
private String brakePedal;
|
||||
|
||||
/**
|
||||
* 燃料消耗率
|
||||
*/
|
||||
private String fuelConsumptionRate;
|
||||
|
||||
/**
|
||||
* 电机控制器温度
|
||||
*/
|
||||
private String motorControllerTemperature;
|
||||
|
||||
/**
|
||||
* 电机转速
|
||||
*/
|
||||
private String motorSpeed;
|
||||
|
||||
/**
|
||||
* 电机转矩
|
||||
*/
|
||||
private String motorTorque;
|
||||
|
||||
/**
|
||||
* 电机温度
|
||||
*/
|
||||
private String motorTemperature;
|
||||
|
||||
/**
|
||||
* 电机电压
|
||||
*/
|
||||
private String motorVoltage;
|
||||
|
||||
/**
|
||||
* 电机电流
|
||||
*/
|
||||
private String motorCurrent;
|
||||
|
||||
/**
|
||||
* 动力电池剩余电量SOC
|
||||
*/
|
||||
private BigDecimal remainingBattery;
|
||||
|
||||
/**
|
||||
* 电池总容量
|
||||
*/
|
||||
private BigDecimal batteryLevel;
|
||||
|
||||
/**
|
||||
* 当前状态允许的最大反馈功率
|
||||
*/
|
||||
private String maximumFeedbackPower;
|
||||
|
||||
/**
|
||||
* 当前状态允许最大放电功率
|
||||
*/
|
||||
private String maximumDischargePower;
|
||||
|
||||
/**
|
||||
* BMS自检计数器
|
||||
*/
|
||||
private String selfCheckCounter;
|
||||
|
||||
/**
|
||||
* 动力电池充放电电流
|
||||
*/
|
||||
private String totalBatteryCurrent;
|
||||
|
||||
/**
|
||||
* 动力电池负载端总电压V3
|
||||
*/
|
||||
private String totalBatteryVoltage;
|
||||
|
||||
/**
|
||||
* 单次最大电压
|
||||
*/
|
||||
private String singleBatteryMaxVoltage;
|
||||
|
||||
/**
|
||||
* 单体电池最低电压
|
||||
*/
|
||||
private String singleBatteryMinVoltage;
|
||||
|
||||
/**
|
||||
* 单体电池最高温度
|
||||
*/
|
||||
private String singleBatteryMaxTemperature;
|
||||
|
||||
/**
|
||||
* 单体电池最低温度
|
||||
*/
|
||||
private String singleBatteryMinTemperature;
|
||||
|
||||
/**
|
||||
* 动力电池可用容量
|
||||
*/
|
||||
private String availableBatteryCapacity;
|
||||
|
||||
/**
|
||||
* 车辆状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int vehicleStatus = 1;
|
||||
|
||||
/**
|
||||
* 充电状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int chargingStatus = 1;
|
||||
|
||||
/**
|
||||
* 运行状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int operatingStatus = 1;
|
||||
|
||||
/**
|
||||
* SOC
|
||||
*/
|
||||
@Builder.Default
|
||||
private int socStatus = 1;
|
||||
|
||||
/**
|
||||
* 可充电储能装置工作状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int chargingEnergyStorageStatus = 1;
|
||||
|
||||
/**
|
||||
* 驱动电机状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int driveMotorStatus = 1;
|
||||
|
||||
/**
|
||||
* 定位是否有效
|
||||
*/
|
||||
@Builder.Default
|
||||
private int positionStatus = 1;
|
||||
|
||||
/**
|
||||
* EAS(汽车防盗系统)状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int easStatus = 1;
|
||||
|
||||
/**
|
||||
* PTC(电动加热器)状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int ptcStatus = 1;
|
||||
|
||||
/**
|
||||
* EPS(电动助力系统)状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int epsStatus = 1;
|
||||
|
||||
/**
|
||||
* ABS(防抱死)状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int absStatus = 1;
|
||||
|
||||
/**
|
||||
* MCU(电机/逆变器)状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int mcuStatus = 1;
|
||||
|
||||
/**
|
||||
* 动力电池加热状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int heatingStatus = 1;
|
||||
|
||||
/**
|
||||
* 动力电池当前状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int batteryStatus = 1;
|
||||
|
||||
/**
|
||||
* 动力电池保温状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int batteryInsulationStatus = 1;
|
||||
|
||||
/**
|
||||
* DCDC(电力交换系统)状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int dcdcStatus = 1;
|
||||
|
||||
/**
|
||||
* CHG(充电机)状态
|
||||
*/
|
||||
@Builder.Default
|
||||
private int chgStatus = 1;
|
||||
|
||||
/**
|
||||
* 车辆状态 报文
|
||||
*/
|
||||
private String vehicleStatusMsg;
|
||||
/**
|
||||
* 智能硬件 报文
|
||||
*/
|
||||
private String smartHardwareMsg;
|
||||
/**
|
||||
* 电池报文
|
||||
*/
|
||||
private String batteryMsg;
|
||||
|
||||
public String getMsg(){
|
||||
//第一位VIN
|
||||
return vin +
|
||||
// 当前时间戳
|
||||
System.currentTimeMillis() +
|
||||
//第二位经度 longitude latitude
|
||||
getValue(longitude, 11) +
|
||||
//第三位维度 longitude latitude
|
||||
getValue(latitude, 10) +
|
||||
//车速
|
||||
getValue(speed, 6) +
|
||||
//总里程
|
||||
getValue(mileage == null ? "" : mileage.toString(), 11) +
|
||||
// 总电压
|
||||
getValue(voltage, 6) +
|
||||
//总电流
|
||||
getValue(current, 5) +
|
||||
//绝缘电阻 79 - 87
|
||||
getValue(resistance, 9) +
|
||||
//档位
|
||||
(gear == null ? "D" : gear) +
|
||||
// 加速踏板行程值
|
||||
getValue(accelerationPedal, 2) +
|
||||
// 制动踏板行程值
|
||||
getValue(brakePedal, 2) +
|
||||
// 燃料消耗率
|
||||
getValue(fuelConsumptionRate, 5) +
|
||||
//电机控制器温度
|
||||
getValue(motorControllerTemperature, 6) +
|
||||
//电机转速
|
||||
getValue(motorSpeed, 5) +
|
||||
//点击转矩
|
||||
getValue(motorTorque, 4) +
|
||||
//电机温度
|
||||
getValue(motorTemperature, 6) +
|
||||
//电机电压
|
||||
getValue(motorVoltage, 5) +
|
||||
//电机电流
|
||||
getValue(motorCurrent, 8) +
|
||||
//动力电池剩余电量SOC
|
||||
getValue(remainingBattery == null ? "" : remainingBattery.toString(), 6) +
|
||||
//当前状态允许的最大反馈功率
|
||||
getValue(maximumFeedbackPower, 6) +
|
||||
//当前状态允许最大放电功率
|
||||
getValue(maximumDischargePower, 6) +
|
||||
//BMS自检计数器
|
||||
getValue(selfCheckCounter, 2) +
|
||||
//动力电池充放电电流
|
||||
getValue(totalBatteryCurrent, 5) +
|
||||
//动力电池负载端总电压V3
|
||||
getValue(totalBatteryVoltage, 6) +
|
||||
//单次最大电压
|
||||
getValue(singleBatteryMaxVoltage, 4) +
|
||||
//单体电池最低电压
|
||||
getValue(singleBatteryMinVoltage, 4) +
|
||||
//单体电池最高温度
|
||||
getValue(singleBatteryMaxTemperature, 6) +
|
||||
//单体电池最低温度
|
||||
getValue(singleBatteryMinTemperature, 6) +
|
||||
//动力电池可用容量
|
||||
getValue(availableBatteryCapacity, 6) +
|
||||
//车辆状态
|
||||
vehicleStatus +
|
||||
//充电状态
|
||||
chargingStatus +
|
||||
//运行状态
|
||||
operatingStatus +
|
||||
//SOC
|
||||
socStatus +
|
||||
//可充电储能装置工作状态
|
||||
chargingEnergyStorageStatus +
|
||||
//驱动电机状态
|
||||
driveMotorStatus +
|
||||
//定位是否有效
|
||||
positionStatus +
|
||||
//EAS
|
||||
easStatus +
|
||||
//PTC
|
||||
ptcStatus +
|
||||
//EPS
|
||||
epsStatus +
|
||||
//ABS
|
||||
absStatus +
|
||||
//MCU
|
||||
mcuStatus +
|
||||
//动力电池加热状态
|
||||
heatingStatus +
|
||||
//动力电池当前状态
|
||||
batteryStatus +
|
||||
//动力电池保温状态
|
||||
batteryInsulationStatus +
|
||||
//DCDC
|
||||
dcdcStatus +
|
||||
//CHG
|
||||
chgStatus;
|
||||
}
|
||||
|
||||
public String getValue(String val , int valLength){
|
||||
if(val == null){
|
||||
val = "";
|
||||
}
|
||||
int length = val.length();
|
||||
if (length > valLength){
|
||||
return val.substring( 0 , valLength);
|
||||
}
|
||||
val = val + "0".repeat(valLength - length);
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 汽车对象构造企业VIN
|
||||
* @param vehicleInfo 汽车对象
|
||||
* @return 汽车数据对象
|
||||
*/
|
||||
public static VehicleData vehicleBuild (VehicleInfo vehicleInfo) {
|
||||
return VehicleData.builder()
|
||||
.vin(vehicleInfo.getVin())
|
||||
.gear("P")
|
||||
.remainingBattery(vehicleInfo.getRemainingBattery())
|
||||
.batteryLevel(vehicleInfo.getBatteryLevel())
|
||||
.mileage(vehicleInfo.getTotalMileage())
|
||||
.vehicleStatus(1)
|
||||
.chargingStatus(1)
|
||||
.operatingStatus(1)
|
||||
.socStatus(1)
|
||||
.chargingEnergyStorageStatus(1)
|
||||
.driveMotorStatus(1)
|
||||
.positionStatus(1)
|
||||
.easStatus(1)
|
||||
.ptcStatus(1)
|
||||
.epsStatus(1)
|
||||
.absStatus(1)
|
||||
.mcuStatus(1)
|
||||
.heatingStatus(1)
|
||||
.batteryStatus(1)
|
||||
.batteryInsulationStatus(1)
|
||||
.dcdcStatus(1)
|
||||
.chgStatus(1)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟基础项
|
||||
*/
|
||||
public void imitateBase(){
|
||||
// 总电压
|
||||
this.voltage = VehicleUtils.genValue(110, 750);
|
||||
// 总电流
|
||||
this.current = VehicleUtils.genValue(3, 50);
|
||||
// 绝缘电阻
|
||||
this.resistance = VehicleUtils.genValue(0,30000);
|
||||
// 加速踏板行程值
|
||||
this.accelerationPedal = VehicleUtils.genValue(0, 10);
|
||||
// 制动踏板行程值
|
||||
this.brakePedal = VehicleUtils.genValue(0, 10);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 模拟电机数据
|
||||
*/
|
||||
public void imitateMotor(){
|
||||
// 电机控制器温度
|
||||
this.motorControllerTemperature = VehicleUtils.genValue(0, 100);
|
||||
// 电机转速
|
||||
this.motorSpeed = VehicleUtils.genValue(0, 99999);
|
||||
// 电机转矩
|
||||
this.motorTorque = VehicleUtils.genValue(0, 1000);
|
||||
// 电机温度
|
||||
this.motorTemperature = VehicleUtils.genValue(0, 150);
|
||||
// 电机电压
|
||||
this.motorVoltage = VehicleUtils.genValue(110, 300);
|
||||
// 电机电流
|
||||
this.motorCurrent = VehicleUtils.genValue(0, 15000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟电池包数据
|
||||
*/
|
||||
public void imitateBatteryPack(){
|
||||
// 当前状态允许的最大反馈功率
|
||||
this.maximumFeedbackPower = VehicleUtils.genValue(0, 100);
|
||||
// 当前状态允许最大放电功率
|
||||
this.maximumDischargePower = VehicleUtils.genValue(0, 100);
|
||||
// BMS自检计数器
|
||||
this.selfCheckCounter = VehicleUtils.genValue(0, 15);
|
||||
// 动力电池充放电电流
|
||||
this.totalBatteryCurrent = VehicleUtils.genValue(0, 15);
|
||||
// 动力电池负载端总电压V3
|
||||
this.totalBatteryVoltage = VehicleUtils.genValue(220, 750);
|
||||
// 单体电池最高电压
|
||||
this.singleBatteryMaxVoltage = VehicleUtils.genValue(3, 5);
|
||||
// 单体电池最低电压
|
||||
this.singleBatteryMinVoltage = VehicleUtils.genValue(3, 5);
|
||||
// 单体电池最高温度
|
||||
this.singleBatteryMaxTemperature = VehicleUtils.genValue(0, 100);
|
||||
// 单体电池最低温度
|
||||
this.singleBatteryMinTemperature = VehicleUtils.genValue(0, 100);
|
||||
// 动力电池可用容量
|
||||
this.availableBatteryCapacity = VehicleUtils.genValue(0,100 );
|
||||
}
|
||||
/**
|
||||
车辆状态
|
||||
vehicleStatus;
|
||||
充电状态
|
||||
chargingStatus;
|
||||
运行状态
|
||||
operatingStatus;
|
||||
SOC
|
||||
socStatus;
|
||||
可充电储能装置工作状态
|
||||
chargingEnergyStorageStatus;
|
||||
驱动电机状态
|
||||
driveMotorStatus;
|
||||
定位是否有效
|
||||
positionStatus;
|
||||
*/
|
||||
|
||||
/**
|
||||
EAS(汽车防盗系统)状态
|
||||
easStatus;
|
||||
PTC(电动加热器)状态
|
||||
ptcStatus;
|
||||
EPS(电动助力系统)状态
|
||||
epsStatus;
|
||||
ABS(防抱死)状态
|
||||
absStatus;
|
||||
MCU(电机/逆变器)状态
|
||||
mcuStatus;
|
||||
*/
|
||||
|
||||
/**
|
||||
动力电池加热状态
|
||||
heatingStatus;
|
||||
动力电池当前状态
|
||||
batteryStatus;
|
||||
动力电池保温状态
|
||||
batteryInsulationStatus;
|
||||
DCDC(电力交换系统)状态
|
||||
dcdcStatus;
|
||||
CHG(充电机)状态
|
||||
chgStatus;
|
||||
*/
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.muyu.vehicleGateway.vehicle.thread;
|
||||
|
||||
import com.muyu.vehicleGateway.vehicle.VehicleInstance;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
/**
|
||||
* @ClassName VehicleThread
|
||||
* @Description TODO
|
||||
* @Author LiHD
|
||||
* @Date 2024/9/27 22:44
|
||||
*/
|
||||
@Data
|
||||
@Log4j2
|
||||
public class VehicleThread implements Runnable {
|
||||
|
||||
/**
|
||||
* 是否停止线程
|
||||
*/
|
||||
private volatile boolean isStop = false;
|
||||
|
||||
/**
|
||||
* 车辆实例对象
|
||||
*/
|
||||
private VehicleInstance vehicleInstance;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (!isStop){
|
||||
log.info("{} - 上报数据",this.vehicleInstance.getVin());
|
||||
|
||||
}
|
||||
}catch (Throwable throwable){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void stop() {
|
||||
this.isStop = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package com.muyu.vehicleGateway.web.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.muyu.vehicleGateway.vehicle.VehicleInstance;
|
||||
import com.muyu.vehicleGateway.vehicle.model.VehicleData;
|
||||
import com.muyu.vehicleGateway.web.util.VehicleUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @ClassName VehicleInfo
|
||||
* @Description 车辆信息
|
||||
* @Author LiHD
|
||||
* @Date 2024/9/26 23:48
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("vehicle_info")
|
||||
public class VehicleInfo {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
@TableField(value = "tenant_id", fill = FieldFill.INSERT)
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 报文模板id
|
||||
*/
|
||||
@TableField("message_template_id")
|
||||
private Long messageTemplateId;
|
||||
|
||||
/**
|
||||
* 电池剩余电量
|
||||
*/
|
||||
@TableField("remaining_battery")
|
||||
private BigDecimal remainingBattery;
|
||||
|
||||
/**
|
||||
* 电池电量
|
||||
*/
|
||||
@TableField("battery_level")
|
||||
private BigDecimal batteryLevel;
|
||||
|
||||
/**
|
||||
* 上一次经度
|
||||
*/
|
||||
@TableField("last_longitude")
|
||||
private String lastLongitude;
|
||||
|
||||
/**
|
||||
* 上一次纬度
|
||||
*/
|
||||
@TableField("last_latitude")
|
||||
private String lastLatitude;
|
||||
|
||||
/**
|
||||
* 总里程
|
||||
*/
|
||||
@TableField("total_mileage")
|
||||
private BigDecimal totalMileage;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 生成车辆数据
|
||||
*
|
||||
* @param messageTemplateId 报文ID
|
||||
* @return 车辆数据
|
||||
*/
|
||||
public static VehicleInfo gen(Supplier<Long> messageTemplateId) {
|
||||
return VehicleInfo.create(VehicleUtils.genVin(), messageTemplateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成车辆数据
|
||||
*
|
||||
* @param vin
|
||||
* @param messageTemplateId
|
||||
* @return 车辆数据
|
||||
*/
|
||||
public static VehicleInfo create(String vin, Supplier<Long> messageTemplateId) {
|
||||
BigDecimal battery = VehicleUtils.genBattery();
|
||||
return VehicleInfo.builder()
|
||||
.vin(vin)
|
||||
.messageTemplateId(messageTemplateId.get())
|
||||
.createTime(new Date())
|
||||
.remainingBattery(battery)
|
||||
.batteryLevel(battery)
|
||||
.totalMileage(BigDecimal.ZERO)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static VehicleInfo instanceBuild(VehicleInstance vehicleInstance) {
|
||||
VehicleData vehicle = vehicleInstance.getVehicleData();
|
||||
return VehicleInfo.builder()
|
||||
.vin(vehicleInstance.getVin())
|
||||
.remainingBattery(vehicle.getRemainingBattery())
|
||||
.totalMileage(vehicle.getMileage())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.vehicleGateway.web.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @ClassName PositionModel
|
||||
* @Description 位置模型
|
||||
* @Author LiHD
|
||||
* @Date 2024/9/27 20:59
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PositionModel {
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private String latitude;
|
||||
|
||||
public static PositionModel strBuild(String positionStr) {
|
||||
String[] split = positionStr.split(",");
|
||||
return PositionModel.builder()
|
||||
.longitude(split[0])
|
||||
.latitude(split[1])
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.vehicleGateway.web.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.vehicleGateway.web.domain.VehicleInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @ClassName VehicleInfoMapper
|
||||
* @Description TODO
|
||||
* @Author LiHD
|
||||
* @Date 2024/9/26 23:47
|
||||
*/
|
||||
@Mapper
|
||||
public interface VehicleInfoMapper extends BaseMapper<VehicleInfo> {
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.vehicleGateway.web.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.vehicleGateway.web.domain.VehicleInfo;
|
||||
import com.muyu.vehicleGateway.web.mapper.VehicleInfoMapper;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ClassName VechileInfoServiceImpl
|
||||
* @Description TODO
|
||||
* @Author LiHD
|
||||
* @Date 2024/9/26 23:46
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VechileInfoServiceImpl extends ServiceImpl<VehicleInfoMapper, VehicleInfo> {
|
||||
|
||||
@Autowired
|
||||
private VehicleInfoMapper vehicleInfoMapper;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package com.muyu.vehicleGateway.web.util;
|
||||
|
||||
import com.muyu.vehicleGateway.web.domain.model.PositionModel;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @ClassName VehicleUtils
|
||||
* @Description TODO
|
||||
* @Author LiHD
|
||||
* @Date 2024/9/27 21:21
|
||||
*/
|
||||
|
||||
public class VehicleUtils {
|
||||
|
||||
/**
|
||||
* 生成VIN
|
||||
* @return 返回结果对象
|
||||
*/
|
||||
public static String genVin() {
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder(17);
|
||||
for (int i = 0; i < 17; i++) {
|
||||
int index = (int) (random.nextFloat() * characters.length());
|
||||
sb.append(characters.charAt(index));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
/**
|
||||
* 生成电池额度
|
||||
* @return 电池额度
|
||||
*/
|
||||
public static BigDecimal genBattery(){
|
||||
return BigDecimal.valueOf(random.nextInt(60, 80) * 1000L);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 两点之间的距离
|
||||
* @param startPositionModel 开始定位点
|
||||
* @param endPositionModel 结束定位点
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal distance(PositionModel startPositionModel, PositionModel endPositionModel){
|
||||
double lon1 = Double.parseDouble(startPositionModel.getLongitude());
|
||||
double lat1 = Double.parseDouble(startPositionModel.getLatitude());
|
||||
double lon2 = Double.parseDouble(endPositionModel.getLongitude());
|
||||
double lat2 = Double.parseDouble(endPositionModel.getLatitude());
|
||||
double lon1Rad = Math.toRadians(lon1);
|
||||
double lat1Rad = Math.toRadians(lat1);
|
||||
double lon2Rad = Math.toRadians(lon2);
|
||||
double lat2Rad = Math.toRadians(lat2);
|
||||
double earthRadius = 6371; // 地球半径(以公里为单位)
|
||||
|
||||
double latDiff = lat2Rad - lat1Rad;
|
||||
double lonDiff = lon2Rad - lon1Rad;
|
||||
|
||||
double a = Math.sin(latDiff / 2) * Math.sin(latDiff / 2) +
|
||||
Math.cos(lat1Rad) * Math.cos(lat2Rad) *
|
||||
Math.sin(lonDiff / 2) * Math.sin(lonDiff / 2);
|
||||
|
||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
|
||||
double distance = earthRadius * c;
|
||||
return BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成电池浮动
|
||||
* @return 电池浮动值
|
||||
*/
|
||||
public static BigDecimal batteryFloat(){
|
||||
Random rand = new Random();
|
||||
// 生成0.00-0.31之间的随机数
|
||||
double num = rand.nextDouble() * 0.31;
|
||||
// 加上0.90,得到0.90-1.21之间的随机数
|
||||
num += 0.90;
|
||||
// 保留两位小数
|
||||
num = (double) Math.round(num * 100) / 100;
|
||||
return BigDecimal.valueOf(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给予开始和结束的值生成数据
|
||||
* @param start 起始范围
|
||||
* @param end 截止范围
|
||||
* @return 返回结果
|
||||
*/
|
||||
public static String genValue(int start, int end){
|
||||
Random rand = new Random();
|
||||
return String.valueOf(rand.nextInt(start, end));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,56 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9703
|
||||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 123.57.152.124:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: lhd
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
amqp:
|
||||
deserialization:
|
||||
trust:
|
||||
all: true
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-vehicleGateway
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
config:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.addr}
|
||||
# nacos用户名
|
||||
username: ${nacos.user-name}
|
||||
# nacos密码
|
||||
password: ${nacos.password}
|
||||
# 命名空间
|
||||
namespace: ${nacos.namespace}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
# 系统共享配置
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统环境Config共享配置
|
||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.muyu.system.mapper: DEBUG
|
|
@ -0,0 +1,74 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-vehicleGateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<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-vehicleGateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<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-vehicleGateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<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>
|
Loading…
Reference in New Issue