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.java
dev.gateway
王鑫 2024-10-07 20:41:04 +08:00
commit 2b159662db
24 changed files with 360 additions and 991 deletions

View File

@ -24,6 +24,12 @@
<dependencies>
<!-- &lt;!&ndash; rabbitmq模块 &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.muyu</groupId>-->
<!-- <artifactId>cloud-common-rabbit</artifactId>-->
<!-- </dependency>-->
<!-- MQTT -->
<dependency>
<groupId>org.eclipse.paho</groupId>

View File

@ -1,6 +1,5 @@
package com.muyu.vehicle.gateway.aliyun.controller;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.vehicle.gateway.aliyun.service.InstanceService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
@ -28,7 +27,7 @@ public class InstanceController {
/**
*
*/
@PostConstruct
// @PostConstruct
public void createInstance(){
instanceService.createInstance();
}
@ -36,7 +35,7 @@ public class InstanceController {
/**
*
*/
@PreDestroy
// @PreDestroy
public void cleanInstance(){
instanceService.cleanInstance();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,7 +1,5 @@
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;
/**

View File

@ -1,9 +1,5 @@
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
*

View File

@ -4,6 +4,8 @@ import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.*;
import com.aliyun.tea.TeaException;
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.service.InstanceService;
import lombok.extern.log4j.Log4j2;
@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* ECS
@ -33,7 +36,7 @@ public class InstanceServiceImpl implements InstanceService {
private final static String Size = "40"; // 请替换成您的实例系统盘大小单位为GB
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 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 SecurityGroupId = "sg-2ze63acc0bas9vjm5gtv"; // 请替换成您的安全组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 String InternetChargeType = "PayByTraffic"; // 请替换成您的实例网络计费类型可选值PayByBandwidth、PayByTraffic
private final static Integer InternetMaxBandwidthOut = 5; // 请替换成您的实例网络出带宽单位为Mbps
@Autowired
private RedisService redisService;
/**
* description
@ -107,7 +112,18 @@ public class InstanceServiceImpl implements InstanceService {
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtime);
RunInstancesResponseBody body = runInstancesResponse.getBody();
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) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
@ -196,4 +212,53 @@ public class InstanceServiceImpl implements InstanceService {
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;
}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -1,68 +1,68 @@
package com.muyu.vehicle.gateway.vehicle;
import com.muyu.vehicle.gateway.vehicle.model.VehicleData;
import com.muyu.vehicle.gateway.vehicle.thread.VehicleThread;
import com.muyu.vehicle.gateway.web.domain.VehicleInfo;
import com.muyu.vehicle.gateway.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();
}
}
//package com.muyu.vehicle.gateway.vehicle;
//
//import com.muyu.vehicle.gateway.vehicle.model.VehicleData;
//import com.muyu.vehicle.gateway.vehicle.thread.VehicleThread;
//import com.muyu.vehicle.gateway.web.domain.VehicleInfo;
//import com.muyu.vehicle.gateway.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();
// }
//
//
//}

View File

@ -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;
*/
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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> {
}

View File

@ -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;
}

View File

@ -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));
}
}