From adab59900a9f78e4ac41eb05ad385681a3ef118a Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Mon, 8 Apr 2024 14:01:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/domain/CoupletTroubleCode.java | 5 + .../couplet-analyze-msg/pom.xml | 8 + .../analyze/msg/consumer/CodeConsumer.java | 219 ++++++++++------- .../analyze/msg/model/ModelsKafkaMessage.java | 21 +- .../service/impl/BreakdownServiceImpl.java | 225 +++++++++++------- .../test/java/com/couplet/msg/ParsingMsg.java | 30 +-- .../src/main/resources/bootstrap.yml | 2 + .../mapper/business/SysTroubleMapper.xml | 6 +- .../src/main/resources/bootstrap.yml | 4 +- 9 files changed, 321 insertions(+), 199 deletions(-) diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleCode.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleCode.java index 0ace253..180a756 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleCode.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleCode.java @@ -65,4 +65,9 @@ public class CoupletTroubleCode { */ @Excel(name = "故障位置") private String troublePosition; + + /** + * 处理状态 + */ + private Integer processingState; } diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml b/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml index 006bb88..8c1df47 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml @@ -92,11 +92,19 @@ com.couplet couplet-common-event + + org.springframework.kafka spring-kafka + + + org.springframework.boot + spring-boot-starter-amqp + + diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java index 15e4140..9dc7660 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java @@ -54,89 +54,142 @@ public class CodeConsumer { String faultCode = MsgUtils.generateGTA(); troubleCode.setTroubleCode(faultCode); - // 检查车辆状态,若为0,则设置故障位置为"190" - if(msgData.getVehicleStatus() == 0) { - troubleCode.setTroublePosition("190"); - } - - // 检查充电状态,若为0,则设置故障位置为"191" - if (msgData.getChargingStatus() == 0) { - troubleCode.setTroublePosition("191"); - } - - // 检查运行状态,若为0,则设置故障位置为"192" - if (msgData.getOperatingStatus() == 0) { - troubleCode.setTroublePosition("192"); - } - - // 检查电池荷电状态(SOC), 若为0,则设置故障位置为"193" - if (msgData.getSocStatus() == 0) { - troubleCode.setTroublePosition("193"); - } - - // 检查充电能源存储状态,若为0,则设置故障位置为"194" - if (msgData.getChargingEnergyStorageStatus() == 0) { - troubleCode.setTroublePosition("194"); - } - - // 检查驱动电机状态,若为0,则设置故障位置为"195" - if (msgData.getDriveMotorStatus() == 0) { - troubleCode.setTroublePosition("195"); - } - - // 检查定位状态,若为0,则设置故障位置为"196" - if (msgData.getPositionStatus() == 0) { - troubleCode.setTroublePosition("196"); - } - - // 检查电子驻车系统(EAS)状态,若为0,则设置故障位置为"197" - if (msgData.getEasStatus() == 0) { - troubleCode.setTroublePosition("197"); - } - - // 检查PTC(正温度系数热敏电阻)状态,若为0,则设置故障位置为"198" - if (msgData.getPtcStatus() == 0) { - troubleCode.setTroublePosition("198"); - } - - // 检查电动助力转向系统(EPS)状态,若为0,则设置故障位置为"199" - if (msgData.getEpsStatus() == 0) { - troubleCode.setTroublePosition("199"); - } - - // 检查防抱死制动系统(ABS)状态,若为0,则设置故障位置为"200" - if (msgData.getAbsStatus() == 0) { - troubleCode.setTroublePosition("200"); - } - - // 检查主控制器(MCU)状态,若为0,则设置故障位置为"201" - if (msgData.getMcuStatus() == 0) { - troubleCode.setTroublePosition("201"); - } - - // 检查加热状态,若为0,则设置故障位置为"202" - if (msgData.getHeatingStatus() == 0) { - troubleCode.setTroublePosition("202"); - } - - // 检查电池状态,若为0,则设置故障位置为"203" - if (msgData.getBatteryStatus() == 0) { - troubleCode.setTroublePosition("203"); - } - - // 检查电池绝缘状态,若为0,则设置故障位置为"204" - if (msgData.getBatteryInsulationStatus() == 0) { - troubleCode.setTroublePosition("204"); - } - - // 检查直流-直流转换器(DC/DC)状态,若为0,则设置故障位置为"205" - if (msgData.getDcdcStatus() == 0) { - troubleCode.setTroublePosition("205"); - } - - // 检查充电机(CHG)状态,若为0,则设置故障位置为"206" - if (msgData.getChgStatus() == 0) { - troubleCode.setTroublePosition("206"); + switch (msgData.getVehicleStatus()) { + case 0: + troubleCode.setTroublePosition("190"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getChargingStatus()) { + case 0: + troubleCode.setTroublePosition("191"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getOperatingStatus()) { + case 0: + troubleCode.setTroublePosition("192"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getSocStatus()) { + case 0: + troubleCode.setTroublePosition("193"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getChargingEnergyStorageStatus()) { + case 0: + troubleCode.setTroublePosition("194"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getDriveMotorStatus()) { + case 0: + troubleCode.setTroublePosition("195"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getPositionStatus()) { + case 0: + troubleCode.setTroublePosition("196"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getEasStatus()) { + case 0: + troubleCode.setTroublePosition("197"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getPtcStatus()) { + case 0: + troubleCode.setTroublePosition("198"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getEpsStatus()) { + case 0: + troubleCode.setTroublePosition("199"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getAbsStatus()) { + case 0: + troubleCode.setTroublePosition("200"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getMcuStatus()) { + case 0: + troubleCode.setTroublePosition("201"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getHeatingStatus()) { + case 0: + troubleCode.setTroublePosition("202"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getBatteryStatus()) { + case 0: + troubleCode.setTroublePosition("203"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getBatteryInsulationStatus()) { + case 0: + troubleCode.setTroublePosition("204"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getDcdcStatus()) { + case 0: + troubleCode.setTroublePosition("205"); + troubleCode.setProcessingState(0); + break; + default: + switch (msgData.getChgStatus()) { + case 0: + troubleCode.setTroublePosition("206"); + troubleCode.setProcessingState(0); + break; + default: + // do nothing + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; } remoteTroubleService.newFaultData(troubleCode); }); diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java index 84fbd01..d835fae 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java @@ -42,8 +42,8 @@ public class ModelsKafkaMessage { add("stored-event"); } }; - @Autowired - private RabbitTemplate rabbitTemplate; +// @Autowired +// private RabbitTemplate rabbitTemplate; /** * 消费者配置 @@ -74,16 +74,15 @@ public class ModelsKafkaMessage { List coupletMsgDataList = sendMsg(str); for (CoupletMsgData msgData : coupletMsgDataList) { log.info("解析到车辆数据:{}", msgData); -// for (String string : strings) { -// IncidentService incidentService = SpringUtils.getBean(string); -// incidentService.incident(msgData); -// } + for (String string : strings) { + IncidentService incidentService = SpringUtils.getBean(string); + incidentService.incident(msgData); + } //发送消息 - rabbitTemplate.convertAndSend("couplet-code-queue",msgData,message -> { - message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); - return message; - }); - +// rabbitTemplate.convertAndSend("couplet-code-queue",msgData,message -> { +// message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); +// return message; +// }); try { sleep(100); } catch (Exception e) { diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/BreakdownServiceImpl.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/BreakdownServiceImpl.java index 5563610..88e6fa3 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/BreakdownServiceImpl.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/BreakdownServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import java.util.Date; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; /** @@ -103,6 +104,7 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl for (CoupletMsgData member : members) { Set breakdownIds = redisService.getCacheSet(member.getVin()+":"+key); if (breakdownIds.size()==0){ + CompletableFuture.runAsync(() -> { CoupletTroubleCode troubleCode = new CoupletTroubleCode(); troubleCode.setTroubleStartTime(new Date()); troubleCode.setTroubleVin(member.getVin()); @@ -110,96 +112,149 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl String faultCode = MsgUtils.generateGTA(); troubleCode.setTroubleCode(faultCode); - // 检查车辆状态,若为0,则设置故障位置为"190" - if(member.getVehicleStatus() == 0) { - troubleCode.setTroublePosition("190"); - } - - // 检查充电状态,若为0,则设置故障位置为"191" - if (member.getChargingStatus() == 0) { - troubleCode.setTroublePosition("191"); - } - - // 检查运行状态,若为0,则设置故障位置为"192" - if (member.getOperatingStatus() == 0) { - troubleCode.setTroublePosition("192"); - } - - // 检查电池荷电状态(SOC), 若为0,则设置故障位置为"193" - if (member.getSocStatus() == 0) { - troubleCode.setTroublePosition("193"); - } - - // 检查充电能源存储状态,若为0,则设置故障位置为"194" - if (member.getChargingEnergyStorageStatus() == 0) { - troubleCode.setTroublePosition("194"); - } - - // 检查驱动电机状态,若为0,则设置故障位置为"195" - if (member.getDriveMotorStatus() == 0) { - troubleCode.setTroublePosition("195"); - } - - // 检查定位状态,若为0,则设置故障位置为"196" - if (member.getPositionStatus() == 0) { - troubleCode.setTroublePosition("196"); - } - - // 检查电子驻车系统(EAS)状态,若为0,则设置故障位置为"197" - if (member.getEasStatus() == 0) { - troubleCode.setTroublePosition("197"); - } - - // 检查PTC(正温度系数热敏电阻)状态,若为0,则设置故障位置为"198" - if (member.getPtcStatus() == 0) { - troubleCode.setTroublePosition("198"); - } - - // 检查电动助力转向系统(EPS)状态,若为0,则设置故障位置为"199" - if (member.getEpsStatus() == 0) { - troubleCode.setTroublePosition("199"); - } - - // 检查防抱死制动系统(ABS)状态,若为0,则设置故障位置为"200" - if (member.getAbsStatus() == 0) { - troubleCode.setTroublePosition("200"); - } - - // 检查主控制器(MCU)状态,若为0,则设置故障位置为"201" - if (member.getMcuStatus() == 0) { - troubleCode.setTroublePosition("201"); - } - - // 检查加热状态,若为0,则设置故障位置为"202" - if (member.getHeatingStatus() == 0) { - troubleCode.setTroublePosition("202"); - } - - // 检查电池状态,若为0,则设置故障位置为"203" - if (member.getBatteryStatus() == 0) { - troubleCode.setTroublePosition("203"); - } - - // 检查电池绝缘状态,若为0,则设置故障位置为"204" - if (member.getBatteryInsulationStatus() == 0) { - troubleCode.setTroublePosition("204"); - } - - // 检查直流-直流转换器(DC/DC)状态,若为0,则设置故障位置为"205" - if (member.getDcdcStatus() == 0) { - troubleCode.setTroublePosition("205"); - } - - // 检查充电机(CHG)状态,若为0,则设置故障位置为"206" - if (member.getChgStatus() == 0) { - troubleCode.setTroublePosition("206"); - } + switch (member.getVehicleStatus()) { + case 0: + troubleCode.setTroublePosition("190"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getChargingStatus()) { + case 0: + troubleCode.setTroublePosition("191"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getOperatingStatus()) { + case 0: + troubleCode.setTroublePosition("192"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getSocStatus()) { + case 0: + troubleCode.setTroublePosition("193"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getChargingEnergyStorageStatus()) { + case 0: + troubleCode.setTroublePosition("194"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getDriveMotorStatus()) { + case 0: + troubleCode.setTroublePosition("195"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getPositionStatus()) { + case 0: + troubleCode.setTroublePosition("196"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getEasStatus()) { + case 0: + troubleCode.setTroublePosition("197"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getPtcStatus()) { + case 0: + troubleCode.setTroublePosition("198"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getEpsStatus()) { + case 0: + troubleCode.setTroublePosition("199"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getAbsStatus()) { + case 0: + troubleCode.setTroublePosition("200"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getMcuStatus()) { + case 0: + troubleCode.setTroublePosition("201"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getHeatingStatus()) { + case 0: + troubleCode.setTroublePosition("202"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getBatteryStatus()) { + case 0: + troubleCode.setTroublePosition("203"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getBatteryInsulationStatus()) { + case 0: + troubleCode.setTroublePosition("204"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getDcdcStatus()) { + case 0: + troubleCode.setTroublePosition("205"); + troubleCode.setProcessingState(0); + break; + default: + switch (member.getChgStatus()) { + case 0: + troubleCode.setTroublePosition("206"); + troubleCode.setProcessingState(0); + break; + default: + // do nothing + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } + break; + } remoteTroubleService.newFaultData(troubleCode); + }); redisService.setCacheSet(member.getVin()+":"+key, member.getVin()+":"+member); long expireTime = 30; redisService.expire(member.getVin()+":"+key, expireTime, TimeUnit.MINUTES); } - } } diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/ParsingMsg.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/ParsingMsg.java index 697f79c..527a27f 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/ParsingMsg.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/ParsingMsg.java @@ -25,21 +25,21 @@ public class ParsingMsg { String hexStringWithoutSpaces = substring.replaceAll("\\s+", ""); String asciiString = hexToString(hexStringWithoutSpaces); System.out.println("16进制解析后的数据:"+asciiString); - //截取前17位 - String substring1 = asciiString.substring(0, 17); - System.out.println("VIN:"+substring1); - String substring2 = asciiString.substring(17, 30); - System.out.println("时间戳:"+substring2); - String substring3 = asciiString.substring(30, 40); - System.out.println("经度:" +substring3); - String substring4 = asciiString.substring(41, 50); - System.out.println("纬度:"+ substring4); - String substring5 = asciiString.substring(51, 56); - System.out.println("车速:"+ substring5); - String substring6 = asciiString.substring(57, 67); - System.out.println("总里程:"+ substring6); - String substring7 = asciiString.substring(68, 73); - System.out.println("总电压:"+ substring7); +// //截取前17位 +// String substring1 = asciiString.substring(0, 17); +// System.out.println("VIN:"+substring1); +// String substring2 = asciiString.substring(17, 30); +// System.out.println("时间戳:"+substring2); +// String substring3 = asciiString.substring(30, 40); +// System.out.println("经度:" +substring3); +// String substring4 = asciiString.substring(41, 50); +// System.out.println("纬度:"+ substring4); +// String substring5 = asciiString.substring(51, 56); +// System.out.println("车速:"+ substring5); +// String substring6 = asciiString.substring(57, 67); +// System.out.println("总里程:"+ substring6); +// String substring7 = asciiString.substring(68, 73); +// System.out.println("总电压:"+ substring7); String pattern = "(.{17})(.{10})(.{9})(.{8})(.{2})"; Pattern compile = Pattern.compile(pattern); Matcher matcher = compile.matcher(asciiString); diff --git a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml index d900876..6c75304 100644 --- a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml @@ -16,9 +16,11 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 config: # 配置中心地址 server-addr: 121.89.211.230:8848 + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/couplet-modules/couplet-business/src/main/resources/mapper/business/SysTroubleMapper.xml b/couplet-modules/couplet-business/src/main/resources/mapper/business/SysTroubleMapper.xml index 16b1277..9f9f3e5 100644 --- a/couplet-modules/couplet-business/src/main/resources/mapper/business/SysTroubleMapper.xml +++ b/couplet-modules/couplet-business/src/main/resources/mapper/business/SysTroubleMapper.xml @@ -8,9 +8,9 @@ - + @@ -19,9 +19,9 @@ INSERT INTO `couplet-cloud`.`couplet_trouble_code` - (`trouble_code`,`trouble_vin`,`trouble_position`,`trouble_start_time`) + (`trouble_code`,`trouble_vin`,`trouble_position`,`trouble_start_time`,`processing_state`) VALUES - (#{troubleCode},#{troubleVin}, #{troublePosition},#{troubleStartTime}) + (#{troubleCode},#{troubleVin}, #{troublePosition},#{troubleStartTime},#{processingState}) truncate table couplet_trouble_code diff --git a/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml index 16394e6..47d8323 100644 --- a/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml @@ -38,7 +38,7 @@ mqtt: # broker: mqtt://115.159.47.13:1883 username: password: - clientId: fluxMq + clientId: mq qos: 0 - topic: test + topic: dxd From adc2b877929133775cbb1845047b22e4062eb14b Mon Sep 17 00:00:00 2001 From: lijiayao <13831655+xiao-yao-charge-forward@user.noreply.gitee.com> Date: Mon, 8 Apr 2024 14:01:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E7=94=B5=E5=AD=90=E5=9B=B4?= =?UTF-8?q?=E6=A0=8F=E6=8A=A5=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../couplet/remote/RemoteRealTimeService.java | 19 +++++++++++++++++ .../couplet/remote/RemoteVehicleService.java | 7 ------- .../RemoteRealTimeFallbackFactory.java | 21 +++++++++++++++++++ .../common/contents/AnalyzeEventContents.java | 4 ++-- .../analyze/msg/mapper/IncidentMapper.java | 5 ++++- .../analyze/msg/model/ModelsKafkaMessage.java | 4 ---- .../service/impl/RealTimeDataServiceImpl.java | 18 ++++++++++++---- .../mapper/incident/SysIncidentMapper.xml | 2 +- 8 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteRealTimeService.java create mode 100644 couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteRealTimeFallbackFactory.java diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteRealTimeService.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteRealTimeService.java new file mode 100644 index 0000000..13cf4b6 --- /dev/null +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteRealTimeService.java @@ -0,0 +1,19 @@ +package com.couplet.remote; + +import com.couplet.common.core.constant.ServiceNameConstants; +import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleCode; +import com.couplet.remote.factory.RemoteRealTimeFallbackFactory; +import com.couplet.remote.factory.RemoteTroubleFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(contextId = "remoteRealTimeService" , + value = ServiceNameConstants.BUSINESS_SERVICE, + fallbackFactory = RemoteRealTimeFallbackFactory.class +) +public interface RemoteRealTimeService { + + +} diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java index 1b03483..ec9a53a 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java @@ -63,13 +63,6 @@ public interface RemoteVehicleService { */ @PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}") public Result> queryByLogoIds(@PathVariable("vehicleId") Long vehicleId); - /** - * 根据车辆id查询绑定的标识 - * @param - * @return - */ -// @PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}") -// public Result> queryByLogoIds(@PathVariable("vehicleId") Long vehicleId); @PostMapping("/list") public Result list(@RequestBody VehicleListParams listParams); diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteRealTimeFallbackFactory.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteRealTimeFallbackFactory.java new file mode 100644 index 0000000..16075fa --- /dev/null +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteRealTimeFallbackFactory.java @@ -0,0 +1,21 @@ +package com.couplet.remote.factory; + +import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleCode; +import com.couplet.remote.RemoteRealTimeService; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +/** + * @Author: LiJiaYao + * @Date: 2024/4/8 + * @Description: + */ +@Component +public class RemoteRealTimeFallbackFactory implements FallbackFactory { + + @Override + public RemoteRealTimeService create(Throwable cause) { + return null; + } +} diff --git a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java index cd18fcf..b457d29 100644 --- a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java +++ b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java @@ -1,5 +1,6 @@ package com.couplet.analyze.common.contents; +import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; /** @@ -8,8 +9,7 @@ import org.springframework.stereotype.Component; * @Description: 事件内容 */ -@Component -public class AnalyzeEventContents { +public interface AnalyzeEventContents { /** * 故障 diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java index 3f44416..aeb2c81 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java @@ -2,6 +2,9 @@ package com.couplet.analyze.msg.mapper; import com.couplet.analyze.msg.domain.CoupletMsgData; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; /** * @Author: LiJiaYao @@ -20,6 +23,6 @@ public interface IncidentMapper { * 查询是否存在该vin */ // CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest); - CoupletMsgData queryByIncident(String vin); + CoupletMsgData queryByIncident(@Param("vin") String vin, @Param("createTime") Date createTime); } diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java index da4c02d..2559a2c 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java @@ -35,12 +35,8 @@ public class ModelsKafkaMessage { private static final String TOPIC_NAME = "online"; private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092"; - @Autowired - private AnalyzeEventContents analyzeEventContents; @Autowired private AnalyzeEventCache analyzeEventCache; -// @Autowired -// private RabbitTemplate rabbitTemplate; /** * 消费者配置 diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java index 7ff9a1b..d625f8e 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java @@ -7,11 +7,14 @@ import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge; import com.couplet.common.core.utils.StringUtils; import com.couplet.common.domain.request.RealTimeDataRequest; import com.couplet.common.redis.service.RedisService; +import com.couplet.remote.RemoteRealTimeService; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import java.util.Date; + /** * @Author: LiJiaYao * @Date: 2024/4/2 @@ -29,6 +32,8 @@ public class RealTimeDataServiceImpl implements IncidentService { @Autowired private RedisService redisService; + @Autowired + private RemoteRealTimeService remoteRealTimeService; /** * 实时数据事件 @@ -41,11 +46,15 @@ public class RealTimeDataServiceImpl implements IncidentService { log.info("实时数据事件开始....."); RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin()); - if (StringUtils.isArray(cacheObject)){ - log.info("[{}]有缓存数据,值为:[{}]", coupletMsgData.getVin(), cacheObject); - + + if (RealTimeJudge.addRealTime(cacheObject)) { + log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); + CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin(), new Date()); + redisService.setCacheObject("vin:" + cacheObject.getVin(), query); + } else { + log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); } - if (RealTimeJudge.isJudge(coupletMsgData.getVin())){ + if (RealTimeJudge.isJudge(coupletMsgData.getVin())) { log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin()); } log.info("[{}]开始传输实时数据", coupletMsgData.getVin()); @@ -56,6 +65,7 @@ public class RealTimeDataServiceImpl implements IncidentService { /** * 实时数据事件 + * * @return */ @Override diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml index e53a115..29ccb3e 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml @@ -72,7 +72,7 @@