修改故障类

server_five_liuyunhu
dongxiaodong 2024-04-06 09:11:03 +08:00
parent 1b88d35574
commit 1db40b4db2
1 changed files with 96 additions and 98 deletions

View File

@ -4,7 +4,6 @@ import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.service.IncidentService; import com.couplet.analyze.msg.service.IncidentService;
import com.couplet.common.core.exception.analyze.AnalyzeException; import com.couplet.common.core.exception.analyze.AnalyzeException;
import com.couplet.common.core.utils.SpringUtils; import com.couplet.common.core.utils.SpringUtils;
import com.couplet.common.domain.CoupletTroubleCode;
import com.couplet.common.system.remote.RemoteCodeService; import com.couplet.common.system.remote.RemoteCodeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.*;
@ -16,7 +15,6 @@ import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import static com.couplet.analyze.msg.contents.MsgContent.BROKER_URL; import static com.couplet.analyze.msg.contents.MsgContent.BROKER_URL;
import static com.couplet.analyze.msg.contents.MsgContent.CLIENT_ID; import static com.couplet.analyze.msg.contents.MsgContent.CLIENT_ID;
@ -82,33 +80,33 @@ public class ModelMessage {
for (CoupletMsgData msgData : coupletMsgDataList) { for (CoupletMsgData msgData : coupletMsgDataList) {
log.info("解析到车辆数据:{}", msgData); log.info("解析到车辆数据:{}", msgData);
// 使用CompletableFuture.runAsync()方法创建一个异步任务,该任务会在一个新的线程中执行 // // 使用CompletableFuture.runAsync()方法创建一个异步任务,该任务会在一个新的线程中执行
CompletableFuture.runAsync(() ->{ // CompletableFuture.runAsync(() ->{
// 创建一个CoupletTroubleLog对象用于记录故障日志 // // 创建一个CoupletTroubleLog对象用于记录故障日志
CoupletTroubleCode troubleCode = new CoupletTroubleCode(); // CoupletTroubleCode troubleCode = new CoupletTroubleCode();
//判断状态是否为异常 // //判断状态是否为异常
if (msgData.getVehicleStatus() !=1 || msgData.getEasStatus() !=1 || msgData.getHeatingStatus() !=1){ // if (msgData.getVehicleStatus() !=1 || msgData.getEasStatus() !=1 || msgData.getHeatingStatus() !=1){
String code = generateGTA(); // String code = generateGTA();
troubleCode.setTroubleCode(code); // troubleCode.setTroubleCode(code);
String vin = msgData.getVin(); // String vin = msgData.getVin();
troubleCode.setTroubleVin(vin); // troubleCode.setTroubleVin(vin);
String position = getPosition(); // String position = getPosition();
troubleCode.setTroublePosition(position); // troubleCode.setTroublePosition(position);
troubleCode.setTroubleValue("00"); // troubleCode.setTroubleValue("00");
String tag = getTag(); // String tag = getTag();
troubleCode.setTroubleTag(tag); // troubleCode.setTroubleTag(tag);
String type = getType(); // String type = getType();
troubleCode.setTroubleType(type); // troubleCode.setTroubleType(type);
troubleCode.setTroubleStartTime(new Date()); // troubleCode.setTroubleStartTime(new Date());
// 如果车辆状态为正常状态为1则添加结束时间为当前时间 // // 如果车辆状态为正常状态为1则添加结束时间为当前时间
if (msgData.getVehicleStatus() == 1){ // if (msgData.getVehicleStatus() == 1){
troubleCode.setTroubleEndTime(new Date()); // troubleCode.setTroubleEndTime(new Date());
} // }
} // }
// 调用远程服务插入故障日志信息 // // 调用远程服务插入故障日志信息
remoteCodeService.insertCode(troubleCode); // remoteCodeService.insertCode(troubleCode);
}); // });
log.info("记录异常成功"); // log.info("记录异常成功");
for (String string : strings) { for (String string : strings) {
IncidentService incidentService = SpringUtils.getBean(string); IncidentService incidentService = SpringUtils.getBean(string);
incidentService.incident(msgData); incidentService.incident(msgData);
@ -135,75 +133,75 @@ public class ModelMessage {
} }
} }
/** // /**
* // *
* GTA // * 拼接GTA字符串
* @return // * @return
*/ // */
public static String generateGTA() { // public static String generateGTA() {
// 生成以GTA开头的字符串 // // 生成以GTA开头的字符串
String codefix = "GTA"; // String codefix = "GTA";
// 删除4位数随机数字 // // 删除4位数随机数字
String s = generateRandomNumber(4); // String s = generateRandomNumber(4);
//拼接 // //拼接
return codefix + s; // return codefix + s;
} // }
//
/** // /**
* 110 // * 随机生成1到10位的数字
* @param length // * @param length
* @return // * @return
*/ // */
public static String generateRandomNumber(int length) { // public static String generateRandomNumber(int length) {
Random random = new Random(); // Random random = new Random();
StringBuilder builder = new StringBuilder(); // StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) { // for (int i = 0; i < length; i++) {
builder.append(random.nextInt(10)); // builder.append(random.nextInt(10));
} // }
return builder.toString(); // return builder.toString();
} // }
//
/** // /**
* 190 209 // * 生成 190 到 209 之间的随机数
* @param // * @param
* @return // * @return
*/ // */
public static String getPosition() { // public static String getPosition() {
// 生成随机数对象 // // 生成随机数对象
Random rand = new Random(); // Random rand = new Random();
//
// 生成 190 到 209 之间的随机数 // // 生成 190 到 209 之间的随机数
int randomNumber = rand.nextInt(20) + 190; // int randomNumber = rand.nextInt(20) + 190;
//
// 将随机数转换为字符串形式 // // 将随机数转换为字符串形式
return String.valueOf(randomNumber); // return String.valueOf(randomNumber);
} // }
//
public static String getTag() { // public static String getTag() {
// 创建一个字符串数组存储三个状态 // // 创建一个字符串数组存储三个状态
String[] statuses = {"车辆状态", "EAS(汽车防盗系统)状态", "DCDC(电力交换系统)"}; // String[] statuses = {"车辆状态", "EAS(汽车防盗系统)状态", "DCDC(电力交换系统)"};
//
// 生成随机数对象 // // 生成随机数对象
Random rand = new Random(); // Random rand = new Random();
//
// 生成一个范围在 0 到 2 之间的随机整数 // // 生成一个范围在 0 到 2 之间的随机整数
int randomIndex = rand.nextInt(3); // int randomIndex = rand.nextInt(3);
//
return statuses[randomIndex]; // return statuses[randomIndex];
} // }
//
public static String getType() { // public static String getType() {
// 创建一个字符串数组存储三个状态 // // 创建一个字符串数组存储三个状态
String[] statuses = {"电池故障", "车体故障", "车尾故障","抽轮故障"}; // String[] statuses = {"电池故障", "车体故障", "车尾故障","抽轮故障"};
//
// 生成随机数对象 // // 生成随机数对象
Random rand = new Random(); // Random rand = new Random();
//
// 生成一个范围在 0 到 2 之间的随机整数 // // 生成一个范围在 0 到 2 之间的随机整数
int randomIndex = rand.nextInt(4); // int randomIndex = rand.nextInt(4);
//
return statuses[randomIndex]; // return statuses[randomIndex];
} // }