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 9d911e9..714d4ba 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 @@ -79,33 +79,6 @@ 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("记录异常成功"); for (String string : strings) { IncidentService incidentService = SpringUtils.getBean(string); incidentService.incident(msgData); @@ -133,78 +106,6 @@ 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]; -// } - - - /** * 将16进制字符串转换为ASCII字符串 * @param s 16进制字符串 diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java index da5b482..2d40fd1 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java @@ -9,6 +9,7 @@ import com.couplet.common.domain.CoupletTroubleGrade; import com.couplet.common.domain.request.TroubleResp; import com.couplet.common.log.annotation.Log; import com.couplet.common.log.enums.BusinessType; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -23,6 +24,7 @@ import java.util.List; */ @RestController @RequestMapping("trouble") +@Slf4j public class SysTroubleController extends BaseController { @Autowired private SysTroubleService troubleService; @@ -74,7 +76,32 @@ public class SysTroubleController extends BaseController { } /** - * 删除故障码数据 + * 故障数据入库 + * @param coupletTroubleCode + * @return + */ + @PostMapping("insertCode") + public Result insertCode(@RequestBody CoupletTroubleCode coupletTroubleCode){ + long start = System.currentTimeMillis(); + int i = troubleService.insertMsgResq(coupletTroubleCode); + + long end = System.currentTimeMillis(); + log.info("记录异常信息成功,耗时:{}",(end-start)); + + return Result.success(i); + } + + /** + * 清空故障码信息 + */ + @PostMapping("cleanTroubleCode") + public Result cleanTroubleCode(){ + troubleService.cleanTroubleCode(); + return Result.success(); + } + + /** + * 新增故障码数据 */ @Log(title = "新增故障码",businessType = BusinessType.INSERT) @PostMapping("/newFaultData") diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java index d3fdc00..05f02e8 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java @@ -3,7 +3,6 @@ package com.couplet.business.server.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; -import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import org.apache.ibatis.annotations.Mapper; @@ -19,8 +18,6 @@ import java.util.List; public interface SysTroubleMapper extends BaseMapper { List selectTroubleList(TroubleResp troubleReq); - List selectTroubleListByType(); - List selectTroubleListByGrade(); /** @@ -29,8 +26,7 @@ public interface SysTroubleMapper extends BaseMapper { */ void newFaultData(CoupletTroubleCode code); + int insertMsgResq(CoupletTroubleCode coupletTroubleCode); -// int addTrouble(TroubleAddReq troubleAddReq); - -// int updateTrouble(TroubleUpdReq troubleUpdReq); + void cleanTroubleCode(); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java index ef889b1..ee332bb 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java @@ -25,8 +25,7 @@ public interface SysTroubleService extends IService { */ void newFaultData(CoupletTroubleCode code); + int insertMsgResq(CoupletTroubleCode coupletTroubleCode); -// int addTrouble (TroubleAddReq troubleAddReq); - -// int updateTrouble(TroubleUpdReq troubleUpdReq); + void cleanTroubleCode(); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java index e3c5632..93ea904 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java @@ -51,24 +51,21 @@ public class SysTroubleServiceImpl extends ServiceImpl + + + + + +