车务管理第一版
parent
0a3cfa13da
commit
d44049758d
|
@ -1,6 +1,6 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 8080
|
||||
port: 8081
|
||||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
|
|
|
@ -83,6 +83,12 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>1.70</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.muyu.car.constant;
|
||||
|
||||
public class RedisConstant {
|
||||
|
||||
public static final String MESSAGE_DETAIL = "messageDetail";
|
||||
|
||||
public static final String VEHICLE_ENTERPRISE = "vehicleEnterprise";
|
||||
|
||||
public static final String INDEX_WARNING = "indexWarning";
|
||||
}
|
|
@ -52,6 +52,12 @@ public class SysCarMessageController extends BaseController
|
|||
@GetMapping("/test")
|
||||
public Result test() throws InterruptedException, ExecutionException {
|
||||
List<SysCarMessage> list = (List<SysCarMessage>) session.getAttribute("list");
|
||||
|
||||
// 检查 list 是否为空
|
||||
if (list == null || list.isEmpty()) {
|
||||
return Result.success(new String[0]); // 或者返回一个适当的错误消息
|
||||
}
|
||||
|
||||
String[] test = TEST.split(" ");
|
||||
String[] results = new String[list.size()];
|
||||
|
||||
|
@ -62,16 +68,20 @@ public class SysCarMessageController extends BaseController
|
|||
int startIndex = Integer.parseInt(carMessage.getMessageStartIndex()) - 1;
|
||||
int endIndex = Integer.parseInt(carMessage.getMessageEndIndex());
|
||||
StringBuilder hexBuilder = new StringBuilder();
|
||||
|
||||
for (int j = startIndex; j < endIndex; j++) {
|
||||
hexBuilder.append(test[j]);
|
||||
}
|
||||
|
||||
String hex = hexBuilder.toString();
|
||||
char[] result = new char[hex.length() / 2];
|
||||
|
||||
for (int x = 0; x < hex.length(); x += 2) {
|
||||
int high = Character.digit(hex.charAt(x), 16);
|
||||
int low = Character.digit(hex.charAt(x + 1), 16);
|
||||
result[x / 2] = (char) ((high << 4) + low);
|
||||
}
|
||||
|
||||
return new String(result);
|
||||
}));
|
||||
}
|
||||
|
@ -83,6 +93,7 @@ public class SysCarMessageController extends BaseController
|
|||
return Result.success(results);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询车辆报文记录列表
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,205 @@
|
|||
package com.muyu.car.domain;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class VehicleMessage extends BaseEntity {
|
||||
|
||||
/**
|
||||
* VIN码
|
||||
*/
|
||||
private String carVin;
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private Long startTime;
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private String latitude;
|
||||
/**
|
||||
* 车速
|
||||
*/
|
||||
private String speed;
|
||||
/**
|
||||
* 总里程
|
||||
*/
|
||||
private String totalMileage;
|
||||
/**
|
||||
* 总电压
|
||||
*/
|
||||
private String totalVoltage;
|
||||
/**
|
||||
* 总电流
|
||||
*/
|
||||
private String combinedCurrent;
|
||||
/**
|
||||
* 绝缘电阻
|
||||
*/
|
||||
private String insulationResistance;
|
||||
/**
|
||||
* 档位
|
||||
*/
|
||||
private String gearPosition;
|
||||
/**
|
||||
* 加速踏板行程值
|
||||
*/
|
||||
private String acceleratorPedalTravelValue;
|
||||
/**
|
||||
* 制动踏板行程值
|
||||
*/
|
||||
private String brakePedalTravelValue;
|
||||
/**
|
||||
* 燃料消耗率
|
||||
*/
|
||||
private String specificFuelConsumption;
|
||||
/**
|
||||
* 电机控制器温度
|
||||
*/
|
||||
private String motorControllerTemperature;
|
||||
/**
|
||||
* 电机转速
|
||||
*/
|
||||
private String motorSpeed;
|
||||
/**
|
||||
* 电机转矩
|
||||
*/
|
||||
private String motorTorque;
|
||||
/**
|
||||
* 电机温度
|
||||
*/
|
||||
private String motorTemperature;
|
||||
/**
|
||||
* 电机电压
|
||||
*/
|
||||
private String motorVoltage;
|
||||
/**
|
||||
* 电机电流
|
||||
*/
|
||||
private String motorCurrent;
|
||||
/**
|
||||
* 动力电池剩余电量SOC
|
||||
*/
|
||||
private String powerBatteryRemainingSOC;
|
||||
/**
|
||||
* 当前状态允许的最大反馈功率
|
||||
*/
|
||||
private String maximumPower;
|
||||
/**
|
||||
* 当前状态允许最大放电功率
|
||||
*/
|
||||
private String maximumDischargePower;
|
||||
/**
|
||||
* BMS自检计数器
|
||||
*/
|
||||
private String BMSSelfCheckCounter;
|
||||
/**
|
||||
* 动力电池充放电电流
|
||||
*/
|
||||
private String electricCurrent;
|
||||
/**
|
||||
* 动力电池负载端总电压V3
|
||||
*/
|
||||
private String totalVoltageV3;
|
||||
/**
|
||||
* 单次最大电压
|
||||
*/
|
||||
private String singleMaximumVoltage;
|
||||
/**
|
||||
* 单体电池最低电压
|
||||
*/
|
||||
private String minimumVoltageOfABattery;
|
||||
/**
|
||||
* 单体电池最高温度
|
||||
*/
|
||||
private String maximumBatteryTemperature;
|
||||
/**
|
||||
* 单体电池最低温度
|
||||
*/
|
||||
private String minimumBatteryTemperature;
|
||||
/**
|
||||
* 动力电池可用容量
|
||||
*/
|
||||
private String powerBatteryAvailableCapacity;
|
||||
/**
|
||||
* 车辆状态
|
||||
*/
|
||||
private String vehicleStatus;
|
||||
/**
|
||||
* 充电状态
|
||||
*/
|
||||
private String chargingState;
|
||||
/**
|
||||
* 运行状态
|
||||
*/
|
||||
private String runningState;
|
||||
/**
|
||||
* SOC
|
||||
*/
|
||||
private String SOC;
|
||||
/**
|
||||
* 可充电储能装置工作状态
|
||||
*/
|
||||
private String workStatus;
|
||||
/**
|
||||
* 驱动电机状态
|
||||
*/
|
||||
private String driveMotorCondition;
|
||||
/**
|
||||
* 定位是否有效
|
||||
*/
|
||||
private String orientation;
|
||||
/**
|
||||
* EAS
|
||||
*/
|
||||
private String eas;
|
||||
/**
|
||||
* PTC
|
||||
*/
|
||||
private String ptc;
|
||||
/**
|
||||
* EPS
|
||||
*/
|
||||
private String eps;
|
||||
/**
|
||||
* ABS
|
||||
*/
|
||||
private String abs;
|
||||
/**
|
||||
* MCU
|
||||
*/
|
||||
private String mcu;
|
||||
/**
|
||||
* 动力电池加热状态
|
||||
*/
|
||||
private String heatingState;
|
||||
/**
|
||||
* 动力电池当前状态
|
||||
*/
|
||||
private String currentStatus;
|
||||
/**
|
||||
* 动力电池保温状态
|
||||
*/
|
||||
private String insulationState;
|
||||
/**
|
||||
* DCDC
|
||||
*/
|
||||
private String dcdc;
|
||||
/**
|
||||
* CHG
|
||||
*/
|
||||
private String chg;
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package com.muyu.car.redis;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
import com.muyu.car.constant.RedisConstant;
|
||||
import com.muyu.car.domain.VehicleMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class RedisInitialize {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String,String>redisTemplate;
|
||||
|
||||
@PostConstruct
|
||||
public void a() {
|
||||
|
||||
new Thread(()->{
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}catch (Exception exception){
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
});
|
||||
VehicleMessage message1 = new VehicleMessage();
|
||||
message1.setStartTime(System.currentTimeMillis());
|
||||
message1.setSpeed("50");
|
||||
message1.setLongitude("126.397428");
|
||||
message1.setLatitude("37.90923");
|
||||
message1.setTotalMileage("1010");
|
||||
message1.setTotalVoltage("22.5");
|
||||
message1.setAcceleratorPedalTravelValue("1.5");
|
||||
message1.setBrakePedalTravelValue("1.2");
|
||||
message1.setSpecificFuelConsumption("1.8");
|
||||
message1.setMotorControllerTemperature("59");
|
||||
message1.setMotorSpeed("850");
|
||||
message1.setMotorTorque("110");
|
||||
message1.setMotorTemperature("53");
|
||||
message1.setMotorVoltage("12.5");
|
||||
message1.setMotorCurrent("1.1");
|
||||
message1.setPowerBatteryRemainingSOC("88");
|
||||
message1.setMaximumPower("999");
|
||||
message1.setMaximumDischargePower("950");
|
||||
message1.setDcdc("2");
|
||||
message1.setChg("2");
|
||||
message1.setBMSSelfCheckCounter("2");
|
||||
message1.setElectricCurrent("2.3");
|
||||
message1.setTotalVoltageV3("13.1");
|
||||
message1.setSingleMaximumVoltage("14.1");
|
||||
message1.setMinimumVoltageOfABattery("12.2");
|
||||
message1.setMaximumBatteryTemperature("85");
|
||||
message1.setMinimumBatteryTemperature("51");
|
||||
message1.setPowerBatteryAvailableCapacity("560");
|
||||
message1.setCombinedCurrent("1.1");
|
||||
message1.setRunningState("2");
|
||||
message1.setWorkStatus("2");
|
||||
message1.setDriveMotorCondition("1");
|
||||
message1.setVehicleStatus("1");
|
||||
message1.setChargingState("1");
|
||||
message1.setHeatingState("1");
|
||||
message1.setCarVin("1HGCM826X3A004352");
|
||||
|
||||
redisTemplate.opsForValue().set(RedisConstant.VEHICLE_ENTERPRISE + message1.getCarVin(), JSON.toJSONString(message1));
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
|
||||
|
||||
//
|
||||
// new Thread(() -> {
|
||||
// try {
|
||||
// Thread.sleep(500);
|
||||
// } catch (InterruptedException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// List<VehicleMessageMiddle> vehicleMessageMiddleList = vehicleMessageMiddleService.list();
|
||||
// vehicleMessageMiddleList.forEach(vehicleMessageMiddle -> {
|
||||
// List<MessageDetail> messageDetailList = messageDetailService.list(new LambdaQueryWrapper<>() {{
|
||||
// in(MessageDetail::getId, Arrays.asList(vehicleMessageMiddle.getMessageIds().split(",")));
|
||||
// }});
|
||||
// String jsonString = JSON.toJSONString(messageDetailList);
|
||||
// redisTemplate.opsForHash().put(RedisConstant.MESSAGE_DETAIL, vehicleMessageMiddle.getCarVin(), jsonString);
|
||||
// });
|
||||
// });
|
||||
|
||||
// MessageDetail messageDetail = new MessageDetail();
|
||||
// messageDetail.setKeyCode("1");
|
||||
// messageDetail.setLabel("测试");
|
||||
// messageDetail.setStartBit(0);
|
||||
// messageDetail.setStopBit(8);
|
||||
// messageDetail.setType("1");
|
||||
|
||||
// List<VehicleMessageMiddle> list = vehicleMessageMiddleService.list();
|
||||
// list.forEach(vehicleMessageMiddle -> {
|
||||
// List<MessageDetail> messageDetailList = messageDetailService.list(new LambdaQueryWrapper<>() {{
|
||||
// in(MessageDetail::getId, Arrays.asList(vehicleMessageMiddle.getMessageIds().split(",")));
|
||||
// });
|
||||
// String jsonString = JSON.toJSONString(messageDetailList);
|
||||
// redisTemplate.opsForHash().put(RedisConstant.VEHICLE_ENTERPRISE, message1.getCarVin(), String.valueOf(jsonString));
|
||||
|
||||
new Thread(()->{
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
}catch (Exception exception){
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
});
|
||||
VehicleMessage message1 = new VehicleMessage();
|
||||
message1.setStartTime(System.currentTimeMillis());
|
||||
message1.setSpeed("50");
|
||||
message1.setLongitude("116.397428");
|
||||
message1.setLatitude("39.90923");
|
||||
message1.setTotalMileage("1000");
|
||||
message1.setTotalVoltage("12.5");
|
||||
message1.setAcceleratorPedalTravelValue("0.5");
|
||||
message1.setBrakePedalTravelValue("0.2");
|
||||
message1.setSpecificFuelConsumption("0.8");
|
||||
message1.setMotorControllerTemperature("60");
|
||||
message1.setMotorSpeed("800");
|
||||
message1.setMotorTorque("100");
|
||||
message1.setMotorTemperature("70");
|
||||
message1.setMotorVoltage("12.6");
|
||||
message1.setMotorCurrent("1.2");
|
||||
message1.setPowerBatteryRemainingSOC("80");
|
||||
message1.setMaximumPower("1000");
|
||||
message1.setMaximumDischargePower("900");
|
||||
message1.setDcdc("1");
|
||||
message1.setChg("1");
|
||||
message1.setBMSSelfCheckCounter("1");
|
||||
message1.setElectricCurrent("2.5");
|
||||
message1.setTotalVoltageV3("13.5");
|
||||
message1.setSingleMaximumVoltage("14.5");
|
||||
message1.setMinimumVoltageOfABattery("12.0");
|
||||
message1.setMaximumBatteryTemperature("80");
|
||||
message1.setMinimumBatteryTemperature("50");
|
||||
message1.setPowerBatteryAvailableCapacity("800");
|
||||
message1.setCombinedCurrent("1.5");
|
||||
message1.setRunningState("1");
|
||||
message1.setWorkStatus("1");
|
||||
message1.setDriveMotorCondition("1");
|
||||
message1.setVehicleStatus("1");
|
||||
message1.setChargingState("1");
|
||||
message1.setHeatingState("1");
|
||||
message1.setCarVin("1HGCM826X3A004352");
|
||||
|
||||
redisTemplate.opsForValue().set(RedisConstant.VEHICLE_ENTERPRISE + message1.getCarVin(), JSON.toJSONString(message1));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.muyu.car.util;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.openssl.PEMKeyPair;
|
||||
import org.bouncycastle.openssl.PEMParser;
|
||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyStore;
|
||||
import java.security.Security;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
public class SSLUtils {
|
||||
public static SSLSocketFactory getSocketFactory(final String caCrtFile,
|
||||
final String crtFile, final String keyFile, final String password)
|
||||
throws Exception {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
// load CA certificate
|
||||
X509Certificate caCert = null;
|
||||
|
||||
FileInputStream fis = new FileInputStream(caCrtFile);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
CertificateFactory cf = CertificateFactory.getInstance("X.509");
|
||||
|
||||
while (bis.available() > 0) {
|
||||
caCert = (X509Certificate) cf.generateCertificate(bis);
|
||||
}
|
||||
|
||||
// load client certificate
|
||||
bis = new BufferedInputStream(new FileInputStream(crtFile));
|
||||
X509Certificate cert = null;
|
||||
while (bis.available() > 0) {
|
||||
cert = (X509Certificate) cf.generateCertificate(bis);
|
||||
}
|
||||
|
||||
// load client private key
|
||||
PEMParser pemParser = new PEMParser(new FileReader(keyFile));
|
||||
Object object = pemParser.readObject();
|
||||
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
|
||||
KeyPair key = converter.getKeyPair((PEMKeyPair) object);
|
||||
pemParser.close();
|
||||
|
||||
// CA certificate is used to authenticate server
|
||||
KeyStore caKs = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
caKs.load(null, null);
|
||||
caKs.setCertificateEntry("ca-certificate", caCert);
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
|
||||
tmf.init(caKs);
|
||||
|
||||
// client key and certificates are sent to server so it can authenticate
|
||||
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
ks.load(null, null);
|
||||
ks.setCertificateEntry("certificate", cert);
|
||||
ks.setKeyEntry("private-key", key.getPrivate(), password.toCharArray(),
|
||||
new java.security.cert.Certificate[]{cert});
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory
|
||||
.getDefaultAlgorithm());
|
||||
kmf.init(ks, password.toCharArray());
|
||||
|
||||
// finally, create SSL socket factory
|
||||
SSLContext context = SSLContext.getInstance("TLSv1.2");
|
||||
context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
|
||||
return context.getSocketFactory();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue