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