Merge remote-tracking branch 'origin/dev.gateway' into dev.gateway
# Conflicts: # cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/vehicleGateway/vehicle/model/VehicleData.java # cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/vehicleGateway/vehicle/thread/VehicleThread.java # cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/vehicleGateway/web/domain/VehicleInfo.java # cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/vehicleGateway/web/domain/model/PositionModel.java # cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/vehicleGateway/web/mapper/VehicleInfoMapper.java # cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/vehicleGateway/web/service/impl/VechileInfoServiceImpl.java # cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/vehicleGateway/web/util/VehicleUtils.javadev.gateway
commit
2b159662db
|
@ -24,6 +24,12 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- <!– rabbitmq模块 –>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.muyu</groupId>-->
|
||||||
|
<!-- <artifactId>cloud-common-rabbit</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<!-- MQTT -->
|
<!-- MQTT -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.paho</groupId>
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.vehicle.gateway.aliyun.controller;
|
package com.muyu.vehicle.gateway.aliyun.controller;
|
||||||
|
|
||||||
import com.muyu.common.core.web.controller.BaseController;
|
|
||||||
import com.muyu.vehicle.gateway.aliyun.service.InstanceService;
|
import com.muyu.vehicle.gateway.aliyun.service.InstanceService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -28,7 +27,7 @@ public class InstanceController {
|
||||||
/**
|
/**
|
||||||
* 创建实例
|
* 创建实例
|
||||||
*/
|
*/
|
||||||
@PostConstruct
|
// @PostConstruct
|
||||||
public void createInstance(){
|
public void createInstance(){
|
||||||
instanceService.createInstance();
|
instanceService.createInstance();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +35,7 @@ public class InstanceController {
|
||||||
/**
|
/**
|
||||||
* 清理实例
|
* 清理实例
|
||||||
*/
|
*/
|
||||||
@PreDestroy
|
// @PreDestroy
|
||||||
public void cleanInstance(){
|
public void cleanInstance(){
|
||||||
instanceService.cleanInstance();
|
instanceService.cleanInstance();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.aliyun.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ECS实例信息
|
|
||||||
*
|
|
||||||
* @author LiHD
|
|
||||||
* @ClassName Instance
|
|
||||||
* @Date 2024/9/29 22:04
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@SuperBuilder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@TableName("instance")
|
|
||||||
public class Instance {
|
|
||||||
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
}
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.vehicle.gateway.aliyun.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例属性信息
|
||||||
|
*
|
||||||
|
* @author LiHD
|
||||||
|
* @ClassName InstanceInformation
|
||||||
|
* @Date 2024/10/2
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class InstanceInformation {
|
||||||
|
/**
|
||||||
|
* 实例ID
|
||||||
|
*/
|
||||||
|
private String InstanceId;
|
||||||
|
/**
|
||||||
|
* 实例IP
|
||||||
|
*/
|
||||||
|
private String IpAddress;
|
||||||
|
/**
|
||||||
|
* 实例状态
|
||||||
|
*/
|
||||||
|
private String Status;
|
||||||
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
package com.muyu.vehicle.gateway.aliyun.mapper;
|
package com.muyu.vehicle.gateway.aliyun.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.muyu.vehicle.gateway.aliyun.domain.Instance;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.muyu.vehicle.gateway.aliyun.service;
|
package com.muyu.vehicle.gateway.aliyun.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.muyu.vehicle.gateway.aliyun.domain.Instance;
|
|
||||||
import org.apache.catalina.Service;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ECS实例服务
|
* ECS实例服务
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.aliyun.ecs20140526.Client;
|
||||||
import com.aliyun.ecs20140526.models.*;
|
import com.aliyun.ecs20140526.models.*;
|
||||||
import com.aliyun.tea.TeaException;
|
import com.aliyun.tea.TeaException;
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import com.muyu.common.redis.service.RedisService;
|
||||||
|
import com.muyu.vehicle.gateway.aliyun.domain.InstanceInformation;
|
||||||
import com.muyu.vehicle.gateway.aliyun.mapper.InstanceMapper;
|
import com.muyu.vehicle.gateway.aliyun.mapper.InstanceMapper;
|
||||||
import com.muyu.vehicle.gateway.aliyun.service.InstanceService;
|
import com.muyu.vehicle.gateway.aliyun.service.InstanceService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ECS实例服务 实现类
|
* ECS实例服务 实现类
|
||||||
|
@ -33,7 +36,7 @@ public class InstanceServiceImpl implements InstanceService {
|
||||||
private final static String Size = "40"; // 请替换成您的实例系统盘大小,单位为GB
|
private final static String Size = "40"; // 请替换成您的实例系统盘大小,单位为GB
|
||||||
private final static String Category = "cloud_essd"; // 请替换成您的实例系统盘类型,可选值:cloud_efficiency、cloud_ssd、cloud_essd
|
private final static String Category = "cloud_essd"; // 请替换成您的实例系统盘类型,可选值:cloud_efficiency、cloud_ssd、cloud_essd
|
||||||
private final static String RegionId = "cn-beijing"; // 请替换成您的实例所在地域ID
|
private final static String RegionId = "cn-beijing"; // 请替换成您的实例所在地域ID
|
||||||
private final static String ImageId = "m-2ze801i45fclmf1qwes5"; // 请替换成您的实例镜像ID
|
private final static String ImageId = "m-2zehkv4epys91571e38r"; // 请替换成您的实例镜像ID
|
||||||
private final static String InstanceType = "ecs.e-c1m1.large"; // 请替换成您的实例类型
|
private final static String InstanceType = "ecs.e-c1m1.large"; // 请替换成您的实例类型
|
||||||
private final static String SecurityGroupId = "sg-2ze63acc0bas9vjm5gtv"; // 请替换成您的安全组ID
|
private final static String SecurityGroupId = "sg-2ze63acc0bas9vjm5gtv"; // 请替换成您的安全组ID
|
||||||
private final static String VSwitchId = "vsw-2ze028qk4xpwk3i0ggket"; // 请替换成您的虚拟交换机ID
|
private final static String VSwitchId = "vsw-2ze028qk4xpwk3i0ggket"; // 请替换成您的虚拟交换机ID
|
||||||
|
@ -44,6 +47,8 @@ public class InstanceServiceImpl implements InstanceService {
|
||||||
private final static Integer Amount = 1; // 请替换成您要创建的实例数量
|
private final static Integer Amount = 1; // 请替换成您要创建的实例数量
|
||||||
private final static String InternetChargeType = "PayByTraffic"; // 请替换成您的实例网络计费类型,可选值:PayByBandwidth、PayByTraffic
|
private final static String InternetChargeType = "PayByTraffic"; // 请替换成您的实例网络计费类型,可选值:PayByBandwidth、PayByTraffic
|
||||||
private final static Integer InternetMaxBandwidthOut = 5; // 请替换成您的实例网络出带宽,单位为Mbps
|
private final static Integer InternetMaxBandwidthOut = 5; // 请替换成您的实例网络出带宽,单位为Mbps
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* description
|
* description
|
||||||
|
@ -107,7 +112,18 @@ public class InstanceServiceImpl implements InstanceService {
|
||||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtime);
|
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtime);
|
||||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||||
ArrayList<String> list = new ArrayList<>(body.getInstanceIdSets().getInstanceIdSet());
|
ArrayList<String> list = new ArrayList<>(body.getInstanceIdSets().getInstanceIdSet());
|
||||||
log.info("创建的实例ID:{}", list);
|
ArrayList<InstanceInformation> returnList = new ArrayList<>();
|
||||||
|
log.info("创建的实例:{}", list);
|
||||||
|
log.info("开始加载实例");
|
||||||
|
Thread.sleep(30000);
|
||||||
|
for (String s : list) {
|
||||||
|
InstanceInformation instanceInformation = selectInstance(s);
|
||||||
|
log.info("加载的实例:{}", instanceInformation);
|
||||||
|
returnList.add(instanceInformation);
|
||||||
|
}
|
||||||
|
log.info("实例加载完成");
|
||||||
|
redisService.setCacheObject("instanceList", returnList);
|
||||||
|
|
||||||
} catch (TeaException error) {
|
} catch (TeaException error) {
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
// 错误 message
|
// 错误 message
|
||||||
|
@ -196,4 +212,53 @@ public class InstanceServiceImpl implements InstanceService {
|
||||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询实例信息
|
||||||
|
* @param instance
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public InstanceInformation selectInstance(String instance) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
com.aliyun.ecs20140526.Client client = this.createClient();
|
||||||
|
com.aliyun.ecs20140526.models.DescribeInstanceAttributeRequest describeInstanceAttributeRequest = new com.aliyun.ecs20140526.models.DescribeInstanceAttributeRequest()
|
||||||
|
.setInstanceId(instance);
|
||||||
|
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
DescribeInstanceAttributeResponse describeInstanceAttributeResponse = client.describeInstanceAttributeWithOptions(describeInstanceAttributeRequest, runtime);
|
||||||
|
// 获取返回值
|
||||||
|
DescribeInstanceAttributeResponseBody body = describeInstanceAttributeResponse.getBody();
|
||||||
|
// 获取公网IP地址
|
||||||
|
List<String> ipAddress = body.publicIpAddress.ipAddress;
|
||||||
|
//获取的实例ID
|
||||||
|
String instanceId = body.instanceId;
|
||||||
|
//获取的公网IP地址
|
||||||
|
String ip = ipAddress.get(0);
|
||||||
|
//获取服务器状态
|
||||||
|
String status = body.status;
|
||||||
|
InstanceInformation build = InstanceInformation.builder()
|
||||||
|
.Status(status)
|
||||||
|
.InstanceId(instanceId)
|
||||||
|
.IpAddress(ip).build();
|
||||||
|
//返回获取的服务器信息
|
||||||
|
return build;
|
||||||
|
} 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,40 @@
|
||||||
|
package com.muyu.vehicle.gateway.vehicle.controller;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.domain.MqttServerModel;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.domain.VehicleConnectionReq;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.service.ConnectService;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接车辆控制层
|
||||||
|
*
|
||||||
|
* @author LiHD
|
||||||
|
* @ClassName ConnectController
|
||||||
|
* @Date 2024/10/6
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/vehicle")
|
||||||
|
@Tag(name = "连接车辆控制层")
|
||||||
|
public class ConnectController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConnectService connectService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆连接
|
||||||
|
* @param vehicleConnectionReq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/receiveMsg/connect")
|
||||||
|
private Result<MqttServerModel> receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
||||||
|
log.info("接收到车辆连接请求:" + vehicleConnectionReq);
|
||||||
|
MqttServerModel mqttServerModel = connectService.receiveMsg(vehicleConnectionReq);
|
||||||
|
return Result.success(mqttServerModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.muyu.vehicle.gateway.vehicle.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT服务节点模型
|
||||||
|
*
|
||||||
|
* @author LiHD
|
||||||
|
* @ClassName MqttServerModel
|
||||||
|
* @Date 2024/10/6
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class MqttServerModel {
|
||||||
|
/**
|
||||||
|
* MQTT服务节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT订阅主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.muyu.vehicle.gateway.vehicle.domain;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆连接请求对象
|
||||||
|
*
|
||||||
|
* @author LiHD
|
||||||
|
* @ClassName VehicleConnectionReq
|
||||||
|
* @Date 2024/10/6
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class VehicleConnectionReq {
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
/**
|
||||||
|
* 车辆vin码
|
||||||
|
*/
|
||||||
|
private String vehicleVin;
|
||||||
|
/**
|
||||||
|
*时间戳
|
||||||
|
*/
|
||||||
|
private String timestamp;
|
||||||
|
/**
|
||||||
|
* 随机字符串
|
||||||
|
*/
|
||||||
|
private String nonce;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.muyu.vehicle.gateway.vehicle.mapper;
|
||||||
|
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.domain.VehicleConnectionReq;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接车辆数据Mapper接口
|
||||||
|
*
|
||||||
|
* @author LiHD
|
||||||
|
* @ClassName ConnectMapper
|
||||||
|
* @Date 2024/10/7 09:35
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ConnectMapper {
|
||||||
|
void addVehicle(VehicleConnectionReq vehicleConnectionReq);
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.muyu.vehicle.gateway.vehicle.service;
|
||||||
|
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.domain.MqttServerModel;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.domain.VehicleConnectionReq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接车辆服务接口
|
||||||
|
*
|
||||||
|
* @author LiHD
|
||||||
|
* @ClassName ConnectService
|
||||||
|
* @Date 2024/10/6
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface ConnectService {
|
||||||
|
MqttServerModel receiveMsg(VehicleConnectionReq vehicleConnectionReq);
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.muyu.vehicle.gateway.vehicle.service.impl;
|
||||||
|
|
||||||
|
import com.muyu.common.redis.service.RedisService;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.domain.MqttServerModel;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.domain.VehicleConnectionReq;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.mapper.ConnectMapper;
|
||||||
|
import com.muyu.vehicle.gateway.vehicle.service.ConnectService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接车辆服务实现类
|
||||||
|
*
|
||||||
|
* @author LiHD
|
||||||
|
* @ClassName ConnectServiceImpl
|
||||||
|
* @Date 2024/10/6
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Service
|
||||||
|
public class ConnectServiceImpl implements ConnectService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConnectMapper connectMapper;
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MqttServerModel receiveMsg(VehicleConnectionReq vehicleConnectionReq) {
|
||||||
|
//发送消息队列
|
||||||
|
// rabbitTemplate.convertAndSend("VIN", vehicleConnectionReq.getVehicleVin(),message1 -> {
|
||||||
|
// message1.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||||
|
// return message1;
|
||||||
|
// });
|
||||||
|
//生成密码
|
||||||
|
vehicleConnectionReq.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()
|
||||||
|
+vehicleConnectionReq.getNonce());
|
||||||
|
connectMapper.addVehicle(vehicleConnectionReq);
|
||||||
|
//保存密码到redis
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,68 +1,68 @@
|
||||||
package com.muyu.vehicle.gateway.vehicle;
|
//package com.muyu.vehicle.gateway.vehicle;
|
||||||
|
//
|
||||||
import com.muyu.vehicle.gateway.vehicle.model.VehicleData;
|
//import com.muyu.vehicle.gateway.vehicle.model.VehicleData;
|
||||||
import com.muyu.vehicle.gateway.vehicle.thread.VehicleThread;
|
//import com.muyu.vehicle.gateway.vehicle.thread.VehicleThread;
|
||||||
import com.muyu.vehicle.gateway.web.domain.VehicleInfo;
|
//import com.muyu.vehicle.gateway.web.domain.VehicleInfo;
|
||||||
import com.muyu.vehicle.gateway.web.domain.model.PositionModel;
|
//import com.muyu.vehicle.gateway.web.domain.model.PositionModel;
|
||||||
import lombok.AllArgsConstructor;
|
//import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
//import lombok.Builder;
|
||||||
import lombok.Data;
|
//import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
//import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.log4j.Log4j2;
|
//import lombok.extern.log4j.Log4j2;
|
||||||
|
//
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
//import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 车辆实例
|
// * 车辆实例
|
||||||
* @className VehicleInstance
|
// * @className VehicleInstance
|
||||||
* @author LiHD
|
// * @author LiHD
|
||||||
* @date 2024/9/27 20:37
|
// * @date 2024/9/27 20:37
|
||||||
*/
|
// */
|
||||||
@Data
|
//@Data
|
||||||
@Log4j2
|
//@Log4j2
|
||||||
@Builder
|
//@Builder
|
||||||
@NoArgsConstructor
|
//@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
//@AllArgsConstructor
|
||||||
public class VehicleInstance {
|
//public class VehicleInstance {
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 路线轨迹编码
|
// * 路线轨迹编码
|
||||||
*/
|
// */
|
||||||
private String postitionCode;
|
// private String postitionCode;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 路径队列
|
// * 路径队列
|
||||||
*/
|
// */
|
||||||
@Builder.Default
|
// @Builder.Default
|
||||||
private LinkedBlockingQueue<PositionModel> positionQueue = new LinkedBlockingQueue<>();
|
// private LinkedBlockingQueue<PositionModel> positionQueue = new LinkedBlockingQueue<>();
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 车辆
|
// * 车辆
|
||||||
*/
|
// */
|
||||||
private VehicleInfo vehicleInfo;
|
// private VehicleInfo vehicleInfo;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 实例数据
|
// * 实例数据
|
||||||
*/
|
// */
|
||||||
private VehicleData vehicleData;
|
// private VehicleData vehicleData;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 上一次定位点
|
// * 上一次定位点
|
||||||
*/
|
// */
|
||||||
private PositionModel lastPosition;
|
// private PositionModel lastPosition;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 车辆工作线程
|
// * 车辆工作线程
|
||||||
*/
|
// */
|
||||||
private VehicleThread vehicleThread;
|
// private VehicleThread vehicleThread;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取当前车辆VIN
|
// * 获取当前车辆VIN
|
||||||
* @return VIN
|
// * @return VIN
|
||||||
*/
|
// */
|
||||||
public String getVin() {
|
// public String getVin() {
|
||||||
return this.vehicleInfo.getVin();
|
// return this.vehicleInfo.getVin();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
|
@ -1,539 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.vehicle.model;
|
|
||||||
|
|
||||||
import com.muyu.vehicle.gateway.web.domain.VehicleInfo;
|
|
||||||
import com.muyu.vehicle.gateway.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;
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.vehicle.thread;
|
|
||||||
|
|
||||||
import com.muyu.vehicle.gateway.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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,126 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.web.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
|
||||||
import com.muyu.vehicle.gateway.vehicle.VehicleInstance;
|
|
||||||
import com.muyu.vehicle.gateway.vehicle.model.VehicleData;
|
|
||||||
import com.muyu.vehicle.gateway.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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.web.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.muyu.vehicle.gateway.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> {
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.web.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.muyu.vehicle.gateway.web.domain.VehicleInfo;
|
|
||||||
import com.muyu.vehicle.gateway.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;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,99 +0,0 @@
|
||||||
package com.muyu.vehicle.gateway.web.util;
|
|
||||||
|
|
||||||
import com.muyu.vehicle.gateway.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));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue