From 703997bd9bc292b9b090cc70b24a525d07ecf6d9 Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Wed, 3 Apr 2024 10:42:30 +0800 Subject: [PATCH 01/10] =?UTF-8?q?dxd=E8=A7=A3=E6=9E=90=E6=8A=A5=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/couplet/analyze/msg/model/ModelMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 201ff2a..c6c34ba 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 @@ -70,7 +70,7 @@ public class ModelMessage { for (CoupletMsgData msgData : coupletMsgDataList) { log.info("解析到车辆数据:{}", msgData); //发送日志到MQ - rabbitTemplate.convertAndSend("couplet-log-queue",msgData,message -> { + rabbitTemplate.convertAndSend("couplet-msg-queue",msgData,message -> { message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); return message; }); From 846073f5286442c5c7105e1015d5fde0b3dc17e2 Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Thu, 4 Apr 2024 14:45:07 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B2=A1=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/couplet/log/annotation/Record.java | 10 ----- .../java/com/couplet/log/aop/AopRecord.java | 10 ----- .../test/java/com/couplet/msg/Randoms.java | 36 ++++++++++++++++ couplet-modules/couplet-business/pom.xml | 5 +++ .../controller/TroubleLogController.java | 10 +++++ .../server/mapper/SysTroubleMapper.java | 7 ++-- .../server/mapper/TroubleLogMapper.java | 16 +++++++ .../server/service/SysTroubleService.java | 6 +-- .../server/service/TroubleLogService.java | 13 ++++++ .../service/impl/SysTroubleServiceImpl.java | 42 ++++++++++++------- .../service/impl/TroubleLogServiceImpl.java | 23 ++++++++++ .../mapper/business/SysTroubleMapper.xml | 4 ++ .../mapper/business/TroubleLogMapper.xml | 8 ++++ pom.xml | 7 ++++ 14 files changed, 153 insertions(+), 44 deletions(-) delete mode 100644 couplet-common/couplet-common-business/src/main/java/com/couplet/log/annotation/Record.java delete mode 100644 couplet-common/couplet-common-business/src/main/java/com/couplet/log/aop/AopRecord.java create mode 100644 couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Randoms.java create mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java create mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java create mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java create mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/TroubleLogServiceImpl.java create mode 100644 couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/log/annotation/Record.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/log/annotation/Record.java deleted file mode 100644 index 03f040a..0000000 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/log/annotation/Record.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.couplet.log.annotation; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/3/28 15:39 - * @description - */ -public @interface Record { -} diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/log/aop/AopRecord.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/log/aop/AopRecord.java deleted file mode 100644 index e4ff8b0..0000000 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/log/aop/AopRecord.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.couplet.log.aop; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/3/28 23:12 - * @description - */ -public class AopRecord { -} diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Randoms.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Randoms.java new file mode 100644 index 0000000..37a80f1 --- /dev/null +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Randoms.java @@ -0,0 +1,36 @@ +package com.couplet.msg; + +import java.util.Random; + +/** + * @author DongXiaoDong + * @version 1.0 + * @date 2024/4/4 11:34 + * @description + */ +public class Randoms { + public static void main(String[] args) { + String gtaNumber = generateGTA(); + System.out.println("随机生成的GTA开头的七位数字:" + gtaNumber); + } + + public static String generateGTA() { + // 生成四位以"GTA"开头的字符串 + String prefix = "GTA"; + // 生成三位随机数字 + String randomNumber = generateRandomNumber(4); + // 拼接字符串 + return prefix + randomNumber; + } + + public static String generateRandomNumber(int length) { + // 生成随机数 + Random random = new Random(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < length; i++) { + // 生成0到9之间的随机数字,并转换为字符串 + sb.append(random.nextInt(10)); + } + return sb.toString(); + } +} diff --git a/couplet-modules/couplet-business/pom.xml b/couplet-modules/couplet-business/pom.xml index cc7969f..1c43041 100644 --- a/couplet-modules/couplet-business/pom.xml +++ b/couplet-modules/couplet-business/pom.xml @@ -82,6 +82,11 @@ couplet-common-swagger + + com.couplet + couplet-analyze-msg + + diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java new file mode 100644 index 0000000..7ff88b5 --- /dev/null +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java @@ -0,0 +1,10 @@ +package com.couplet.business.server.controller; + +/** + * @author DongXiaoDong + * @version 1.0 + * @date 2024/4/4 10:37 + * @description + */ +public class TroubleLogController { +} 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 7f211bd..d4ddf4b 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 @@ -1,11 +1,14 @@ package com.couplet.business.server.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; +import com.couplet.common.domain.CoupletTroubleLog; import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -22,8 +25,4 @@ public interface SysTroubleMapper extends BaseMapper { List selectTroubleListByType(); List selectTroubleListByGrade(); - -// int addTrouble(TroubleAddReq troubleAddReq); - -// int updateTrouble(TroubleUpdReq troubleUpdReq); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java new file mode 100644 index 0000000..b686e7d --- /dev/null +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java @@ -0,0 +1,16 @@ +package com.couplet.business.server.mapper; + + +import com.couplet.analyze.msg.domain.CoupletMsgData; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author DongXiaoDong + * @version 1.0 + * @date 2024/4/4 10:38 + * @description + */ +@Mapper +public interface TroubleLogMapper { + +} 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 5018464..07dd7f4 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 @@ -1,11 +1,13 @@ package com.couplet.business.server.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.common.core.domain.PageResult; 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 io.swagger.models.auth.In; import java.util.List; @@ -22,8 +24,4 @@ public interface SysTroubleService extends IService { List selectTroubleListByType(); List selectTroubleListByGrade(); - -// int addTrouble (TroubleAddReq troubleAddReq); - -// int updateTrouble(TroubleUpdReq troubleUpdReq); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java new file mode 100644 index 0000000..d230dc6 --- /dev/null +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java @@ -0,0 +1,13 @@ +package com.couplet.business.server.service; + +import com.couplet.analyze.msg.domain.CoupletMsgData; + +/** + * @author DongXiaoDong + * @version 1.0 + * @date 2024/4/4 10:38 + * @description + */ +public interface TroubleLogService { + +} 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 48c34bb..acaf6c0 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 @@ -1,6 +1,7 @@ package com.couplet.business.server.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.business.server.mapper.SysTroubleMapper; import com.couplet.business.server.service.SysTroubleService; import com.couplet.common.core.domain.PageResult; @@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Random; /** * @author DongXiaoDong @@ -50,25 +52,33 @@ public class SysTroubleServiceImpl extends ServiceImpl select * from couplet_trouble_grade + + diff --git a/couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml b/couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml new file mode 100644 index 0000000..b2e17c4 --- /dev/null +++ b/couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/pom.xml b/pom.xml index 809fbfe..e259c7f 100644 --- a/pom.xml +++ b/pom.xml @@ -275,6 +275,13 @@ ${couplet.version} + + + com.couplet + couplet-analyze-msg + ${couplet.version} + + From 041aaa46544c2833b7c237f48f04a471d4062728 Mon Sep 17 00:00:00 2001 From: lijiayao <13831655+xiao-yao-charge-forward@user.noreply.gitee.com> Date: Thu, 4 Apr 2024 15:04:25 +0800 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20=E4=BA=8B=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../redis/configure/RedisListenerConfig.java | 33 ++++++++++ .../couplet-analyze-msg/pom.xml | 8 +++ .../analyze/msg/CoupletMsgApplication.java | 2 +- .../analyze/msg/consumer/MsgConsumer.java | 39 ++++++++++++ .../analyze/msg/contents/StateConstant.java | 60 +++++++++++++++++-- .../service/impl/BreakdownServiceImpl.java | 59 ++++++++++++++++-- .../service/impl/RealTimeDataServiceImpl.java | 13 +++- 7 files changed, 202 insertions(+), 12 deletions(-) create mode 100644 couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/configure/RedisListenerConfig.java create mode 100644 couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java diff --git a/couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/configure/RedisListenerConfig.java b/couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/configure/RedisListenerConfig.java new file mode 100644 index 0000000..41cf439 --- /dev/null +++ b/couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/configure/RedisListenerConfig.java @@ -0,0 +1,33 @@ +package com.couplet.common.redis.configure; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; + +/** + * @Author: LiJiaYao + * @Date: 2024/4/4 + * @Description: redis监听配置 + */ +@Configuration +public class RedisListenerConfig { + + @Bean + RedisMessageListenerContainer listenerContainer(RedisConnectionFactory redisConnectionFactory) { + + RedisMessageListenerContainer container = new RedisMessageListenerContainer(); + container.setConnectionFactory(redisConnectionFactory); + return container; + } + + @Bean + KeyExpirationEventMessageListener redisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { + return new KeyExpirationEventMessageListener(listenerContainer); + } + + + + +} diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml b/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml index 2dd1c32..2eb1549 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml @@ -86,6 +86,14 @@ org.eclipse.paho.client.mqttv3 1.2.5 + + com.couplet + couplet-modules-mq + + + com.couplet + couplet-common-business + diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/CoupletMsgApplication.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/CoupletMsgApplication.java index b37e7c8..2987420 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/CoupletMsgApplication.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/CoupletMsgApplication.java @@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; * @date 2024/4/2 8:39 * @description */ -@SpringBootApplication +@SpringBootApplication(scanBasePackages = "com.couplet") @EnableScheduling @EnableFeignClients(basePackages = "com.couplet.**") public class CoupletMsgApplication { diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java new file mode 100644 index 0000000..c7baf3d --- /dev/null +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java @@ -0,0 +1,39 @@ +package com.couplet.analyze.msg.consumer; + +import com.rabbitmq.client.Channel; + +import lombok.extern.log4j.Log4j2; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +/** + * @Author: LiJiaYao + * @Date: 2024/4/4 + * @Description: + */ +@Log4j2 +@Component +@RabbitListener(queues = "") +public class MsgConsumer { + + @Autowired + private StringRedisTemplate redisTemplate; + + @RabbitHandler + public void realTimeDataConsumer(Channel channel, Message message){ + +// log.info(); + + String messageId = message.getMessageProperties().getMessageId(); + long deliveryTag = message.getMessageProperties().getDeliveryTag(); + + + + + } + +} diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/contents/StateConstant.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/contents/StateConstant.java index b94c76a..a8221f0 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/contents/StateConstant.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/contents/StateConstant.java @@ -1,5 +1,6 @@ package com.couplet.analyze.msg.contents; +import io.swagger.models.auth.In; import org.springframework.stereotype.Component; /** @@ -13,27 +14,76 @@ public class StateConstant { /** * 车辆状态 */ - public static final Integer VEHICLE_STATUS = 0; + public static final Integer VEHICLE_STATUS = 1; /** * 充电状态 */ - public static final Integer CHARGING_STATUS = 0; + public static final Integer CHARGING_STATUS = 1; /** * 运行状态 */ - public static final Integer OPERATING_STATUS = 0; + public static final Integer OPERATING_STATUS = 1; /** * soc状态 */ - public static final Integer SOC_STATUS = 0; + public static final Integer SOC_STATUS = 1; /** * 可充电储能装置工作状态 */ - public static final Integer CHARGING_ENERGY_STORAGE_STATUS = 0 ; + public static final Integer CHARGING_ENERGY_STORAGE_STATUS = 1; + /** + * 驱动电机状态 + */ + public static final Integer DRIVE_MOTOR_STATUS = 1; + + /** + * 定位是否有效 + */ + public static final Integer POSITION_STATUS = 1; + + /** + * EAS(汽车防盗系统)状态 + */ + public static final Integer EAS_STATUS = 1; + + /** + * PTC(电动加热器)状态 + */ + public static final Integer PTC_STATUS = 1; + + /** + * ABS(防抱死)状态 + */ + public static final Integer ABS_STATUS = 1; + + /** + * MCU(电机/逆变器)状态 + */ + public static final Integer MCU_STATUS = 1; + /** + * 动力电池加热状态 + */ + public static final Integer HEATING_STATUS = 1; + /** + * 动力电池当前状态 + */ + public static final Integer BATTERY_STATUS = 1; + /** + * 动力电池保温状态 + */ + public static final Integer BATTERY_INSULATION_STATUS = 1; + /** + * DCDC(电力交换系统) 状态 + */ + public static final Integer DCDC_STATUS = 1; + /** + * CHG(充电机)状态 + */ + public static final Integer CHG_STATUS = 1; } 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 721046f..5be69e0 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 @@ -1,19 +1,43 @@ package com.couplet.analyze.msg.service.impl; +import com.alibaba.fastjson.JSON; +import com.couplet.analyze.msg.contents.StateConstant; import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.analyze.msg.service.IncidentService; -import com.couplet.common.log.annotation.Log; import lombok.extern.log4j.Log4j2; +import org.aspectj.bridge.Message; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.stereotype.Service; +import java.util.concurrent.TimeUnit; + /** * @Author: LiJiaYao * @Date: 2024/4/2 * @Description: 故障事件 */ @Service("breakdown") -@Log4j2 -public class BreakdownServiceImpl implements IncidentService { +public class BreakdownServiceImpl extends KeyExpirationEventMessageListener implements IncidentService { + + /** + * 设置redis存储 + */ + @Autowired + private StringRedisTemplate redisTemplate; + + private static Logger log = LoggerFactory.getLogger(BreakdownServiceImpl.class); + + public BreakdownServiceImpl(RedisMessageListenerContainer listenerContainer) { + super(listenerContainer); + } + + /** * 故障事件 * @@ -23,10 +47,35 @@ public class BreakdownServiceImpl implements IncidentService { public void incident(CoupletMsgData coupletMsgData) { log.info("故障事件开始....."); + long l = System.currentTimeMillis(); + log.info("开始时间是:"+l); + if (StateConstant.VEHICLE_STATUS != coupletMsgData.getVehicleStatus() + || StateConstant.CHARGING_STATUS!=coupletMsgData.getChgStatus() + || StateConstant.OPERATING_STATUS!=coupletMsgData.getOperatingStatus() + || StateConstant.SOC_STATUS!=coupletMsgData.getSocStatus() + || StateConstant.CHARGING_ENERGY_STORAGE_STATUS != coupletMsgData.getChargingEnergyStorageStatus() + || StateConstant.DRIVE_MOTOR_STATUS != coupletMsgData.getDriveMotorStatus() + || StateConstant.POSITION_STATUS != coupletMsgData.getPositionStatus() + || StateConstant.EAS_STATUS != coupletMsgData.getEasStatus() + || StateConstant.PTC_STATUS != coupletMsgData.getPtcStatus() + || StateConstant.ABS_STATUS != coupletMsgData.getAbsStatus() + || StateConstant.MCU_STATUS != coupletMsgData.getMcuStatus() + || StateConstant.HEATING_STATUS != coupletMsgData.getHeatingStatus() + || StateConstant.BATTERY_STATUS != coupletMsgData.getBatteryStatus() + || StateConstant.BATTERY_INSULATION_STATUS != coupletMsgData.getBatteryInsulationStatus() + || StateConstant.DCDC_STATUS != coupletMsgData.getDcdcStatus() + || StateConstant.CHG_STATUS != coupletMsgData.getChgStatus()){ + //获取过期的key + String expireKey = coupletMsgData.toString(); + redisTemplate.opsForValue().set(String.valueOf(coupletMsgData),JSON.toJSONString(coupletMsgData),10, TimeUnit.MINUTES); - log.info("故障事件结束....."); - + long timeMillis = System.currentTimeMillis(); + log.debug("失效+key is:"+ "coupletMsgData"); + log.info("故障事件结束时间:"+timeMillis); + log.info("故障事件检测结束....."); + } + log.info("故障事件检测结束....."); } /** 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 7bbcbb9..97135de 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 @@ -1,8 +1,10 @@ package com.couplet.analyze.msg.service.impl; import com.couplet.analyze.msg.domain.CoupletMsgData; +import com.couplet.analyze.msg.mapper.IncidentMapper; import com.couplet.analyze.msg.service.IncidentService; import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -14,6 +16,12 @@ import org.springframework.stereotype.Service; @Log4j2 public class RealTimeDataServiceImpl implements IncidentService { + /** + * 查询传入的数据是否存在 + */ + @Autowired + private IncidentMapper incidentMapper; + /** * 实时数据事件 * @@ -24,7 +32,10 @@ public class RealTimeDataServiceImpl implements IncidentService { log.info("实时数据事件开始....."); - + + + + log.info("实时数据事件结束....."); From 9e489bd4ec922e13ed54bf817e0ce1d54512ca19 Mon Sep 17 00:00:00 2001 From: lijiayao <13831655+xiao-yao-charge-forward@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 08:36:56 +0800 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20=E4=BA=8B=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/couplet/common/domain/Fence.java | 3 +- .../domain/request/RealTimeDataRequest.java | 2 +- .../analyze/msg/consumer/MsgConsumer.java | 67 ++++++++++++++++++- .../analyze/msg/mapper/IncidentMapper.java | 7 ++ .../analyze/msg/service/IncidentService.java | 2 + .../service/impl/BreakdownServiceImpl.java | 2 +- .../service/impl/RealTimeDataServiceImpl.java | 22 +++++- .../impl/realTimeData/RealTimeJudge.java | 45 +++++++++++++ .../mapper/incident/SysIncidentMapper.xml | 6 +- .../server/service/impl/FenceServiceImpl.java | 2 +- 10 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/Fence.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/Fence.java index 67504f0..de7c625 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/Fence.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/Fence.java @@ -84,10 +84,11 @@ public class Fence extends BaseEntity{ private Integer alarmStatus; - @TableField(exist = false) + /** * 标识 */ + @TableField(exist = false) private Integer logoId; @TableField(exist = false) private String logoName; diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java index 5135e00..512a86e 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java @@ -18,7 +18,7 @@ import lombok.ToString; public class RealTimeDataRequest { - private Integer userId; + private Long userId; private String vin; diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java index c7baf3d..53db614 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java @@ -1,5 +1,11 @@ package com.couplet.analyze.msg.consumer; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.couplet.analyze.msg.domain.CoupletMsgData; +import com.couplet.analyze.msg.mapper.IncidentMapper; +import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge; +import com.couplet.common.domain.request.RealTimeDataRequest; import com.rabbitmq.client.Channel; import lombok.extern.log4j.Log4j2; @@ -10,6 +16,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + /** * @Author: LiJiaYao * @Date: 2024/4/4 @@ -17,21 +30,69 @@ import org.springframework.stereotype.Component; */ @Log4j2 @Component -@RabbitListener(queues = "") +@RabbitListener(queues = "vinQueue") public class MsgConsumer { @Autowired private StringRedisTemplate redisTemplate; + @Autowired + private IncidentMapper incidentMapper; + private static final Map> setMap = new HashMap<>(); + @RabbitHandler - public void realTimeDataConsumer(Channel channel, Message message){ + public void realTimeDataConsumer(RealTimeDataRequest realTimeDataRequest, Channel channel, Message message) throws IOException { -// log.info(); + log.info("消息进入队列,传入的数据是:[{}]", realTimeDataRequest); String messageId = message.getMessageProperties().getMessageId(); long deliveryTag = message.getMessageProperties().getDeliveryTag(); + if (!redisTemplate.hasKey("消息不丢失:" + messageId)) { + redisTemplate.opsForValue().set("消息不丢失:" + messageId, "" + deliveryTag, 1, TimeUnit.MINUTES); + } + Long add = redisTemplate.opsForSet().add("消息不重复:" + messageId, messageId); + redisTemplate.expire("消息不重复:" + messageId, 5, TimeUnit.MINUTES); + try { + if (0 < add) { + JSONObject jsonObject = JSONObject.parseObject(String.valueOf(realTimeDataRequest)); + String vin = jsonObject.getString("vin"); + Long userId = jsonObject.getLong("userId"); + RealTimeDataRequest request = new RealTimeDataRequest(); + request.setVin(vin); + request.setUserId(userId); + RealTimeJudge.addRealTime(request); + //判断车辆是否有实时数据,如果没有则删除数据 + if (RealTimeJudge.isJudge(realTimeDataRequest.getVin())){ + log.info("开始实时数据传输:[{}]",realTimeDataRequest.getVin()); + } + CoupletMsgData incident = incidentMapper.queryByIncident(realTimeDataRequest.getVin()); + if (incident == null){ + log.error("没有数据......"); + } + redisTemplate.opsForList().rightPush("coupletMsgData", JSON.toJSONString(incident)); + + channel.basicAck(deliveryTag, false); + } else { + log.error("消息不能重复消费:[{}]", realTimeDataRequest); + channel.basicReject(deliveryTag, false); + } + } catch (IOException e) { + + log.error("消息未进入队列,传入的信息是:【{}】", realTimeDataRequest); + String s = redisTemplate.opsForValue().get("消息不丢失:" + messageId); + + Long o = Long.valueOf(s); + if (deliveryTag == o + 2) { + log.error("消息已丢失,无法传入的信息是:【{}】", realTimeDataRequest); + channel.basicNack(deliveryTag, false, false); + } else { + log.error("消息已丢失,已再次传入的信息是:【{}】", realTimeDataRequest); + channel.basicNack(deliveryTag, true, false); + } + + } } 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 e45bbfe..3f44416 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 @@ -15,4 +15,11 @@ public interface IncidentMapper { * @param coupletMsgData */ public void reportMapper(CoupletMsgData coupletMsgData); + + /** + * 查询是否存在该vin + */ +// CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest); + CoupletMsgData queryByIncident(String vin); + } diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/IncidentService.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/IncidentService.java index ed64aea..7538cd5 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/IncidentService.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/IncidentService.java @@ -2,6 +2,7 @@ package com.couplet.analyze.msg.service; import com.couplet.analyze.msg.contents.MsgContent; import com.couplet.analyze.msg.domain.CoupletMsgData; +import com.couplet.common.domain.request.RealTimeDataRequest; /** * @Author: LiJiaYao @@ -25,4 +26,5 @@ public interface IncidentService { + } 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 5be69e0..933d1f0 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 @@ -70,7 +70,7 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl redisTemplate.opsForValue().set(String.valueOf(coupletMsgData),JSON.toJSONString(coupletMsgData),10, TimeUnit.MINUTES); long timeMillis = System.currentTimeMillis(); - log.debug("失效+key is:"+ "coupletMsgData"); + log.debug("失效+key is:"+ expireKey); log.info("故障事件结束时间:"+timeMillis); log.info("故障事件检测结束....."); 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 97135de..eeb250f 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 @@ -1,12 +1,20 @@ package com.couplet.analyze.msg.service.impl; +import com.alibaba.fastjson.JSON; import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.analyze.msg.mapper.IncidentMapper; import com.couplet.analyze.msg.service.IncidentService; +import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge; 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.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + /** * @Author: LiJiaYao * @Date: 2024/4/2 @@ -22,6 +30,9 @@ public class RealTimeDataServiceImpl implements IncidentService { @Autowired private IncidentMapper incidentMapper; + @Autowired + private StringRedisTemplate redisTemplate; + /** * 实时数据事件 * @@ -32,8 +43,15 @@ public class RealTimeDataServiceImpl implements IncidentService { log.info("实时数据事件开始....."); - - + if (redisTemplate.hasKey("coupletMsgData")){ + redisTemplate.delete("coupletMsgData"); + } +// Set userId = setMap.get(coupletMsgData.getVin()); +// if (null == userId){ +// userId = new HashSet<>(); +// setMap.put(coupletMsgData.getVin(),userId); +// } +// userId.add(coupletMsgData.getUserId()); diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java new file mode 100644 index 0000000..af9dba3 --- /dev/null +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java @@ -0,0 +1,45 @@ +package com.couplet.analyze.msg.service.impl.realTimeData; + + +import com.couplet.analyze.msg.domain.CoupletMsgData; +import com.couplet.common.domain.request.RealTimeDataRequest; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @Author: LiJiaYao + * @Date: 2024/4/4 + * @Description: 判断实时数据 + */ +public class RealTimeJudge { + + + /** + * 常量 + */ + private static final Map> setMap = new HashMap<>(); + + public static boolean isJudge(String vin){ + return setMap.containsKey(vin); + } + + /** + * + * @param realTimeDataRequest + * @return + */ + public static boolean addRealTime(RealTimeDataRequest realTimeDataRequest){ + Set userIds = setMap.get(realTimeDataRequest.getVin()); + if (userIds == null){ + userIds = new HashSet<>(); + setMap.put(realTimeDataRequest.getVin(),userIds); + } + userIds.add(realTimeDataRequest.getUserId()); + return true; + } + + +} 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 39f16ee..e53a115 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 @@ -4,7 +4,6 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - INSERT INTO `couplet-cloud`.`couplet_msg_data` (`vin`, `create_time`, `longitude`, `latitude`, @@ -71,5 +70,10 @@ #{brakePedal} ); + + diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java index 732e658..d4ef80d 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java @@ -61,7 +61,7 @@ public class FenceServiceImpl extends ServiceImpl implements public void fenceInsert(HttpServletRequest request, FenceRequest fenceRequest) { //先添加围栏 - int a= fenceMapper.insertFence(fenceRequest); + fenceMapper.insertFence(fenceRequest); String[] logoIds = fenceRequest.getLogoIds(); String[] parts = new String[0]; for (String logoId : logoIds) { From f81f05ae1c8ef4715fb55517594ee876967e248f Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 08:38:19 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/domain/CoupletTroubleLog.java | 4 +- .../core/constant/ServiceNameConstants.java | 2 + couplet-common/couplet-common-system/pom.xml | 5 + .../system/remote/RemoteCodeService.java | 22 +++++ .../factory/RemoteCodeFallbackFactory.java | 32 ++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../couplet-analyze-msg/pom.xml | 6 ++ .../analyze/msg/model/ModelMessage.java | 16 +-- couplet-modules/couplet-business/pom.xml | 6 ++ .../server/CoupletBusinessApplication.java | 4 +- .../consumer/SendCodeQueueConsumer.java | 97 +++++++++++++++++++ .../controller/SysTroubleController.java | 14 +++ .../server/mapper/SysTroubleMapper.java | 5 +- .../server/service/SysTroubleService.java | 5 + .../service/impl/SysTroubleServiceImpl.java | 32 +++--- .../mapper/business/SysTroubleMapper.xml | 9 +- 16 files changed, 225 insertions(+), 35 deletions(-) create mode 100644 couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java create mode 100644 couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java create mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleLog.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleLog.java index 565ca22..4fc3902 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleLog.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleLog.java @@ -40,13 +40,13 @@ public class CoupletTroubleLog { */ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date troubleLogStartTime; + private Date troubleLogStart; /** * 结束预警时间 */ @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date troubleLogEndTime; + private Date troubleLogEnd; } diff --git a/couplet-common/couplet-common-core/src/main/java/com/couplet/common/core/constant/ServiceNameConstants.java b/couplet-common/couplet-common-core/src/main/java/com/couplet/common/core/constant/ServiceNameConstants.java index ed65064..3df67ab 100644 --- a/couplet-common/couplet-common-core/src/main/java/com/couplet/common/core/constant/ServiceNameConstants.java +++ b/couplet-common/couplet-common-core/src/main/java/com/couplet/common/core/constant/ServiceNameConstants.java @@ -30,4 +30,6 @@ public class ServiceNameConstants { * @date */ public static final String VEHICLE_SERVICE = "couplet-vehicle"; + + public static final String BUSINESS_SERVICE = "couplet-business"; } diff --git a/couplet-common/couplet-common-system/pom.xml b/couplet-common/couplet-common-system/pom.xml index 506f73d..5f98286 100644 --- a/couplet-common/couplet-common-system/pom.xml +++ b/couplet-common/couplet-common-system/pom.xml @@ -23,5 +23,10 @@ com.couplet couplet-common-core + + + com.couplet + couplet-common-business + diff --git a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java new file mode 100644 index 0000000..4307c75 --- /dev/null +++ b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java @@ -0,0 +1,22 @@ +package com.couplet.common.system.remote; + +import com.couplet.common.core.constant.ServiceNameConstants; +import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleLog; +import com.couplet.common.system.remote.factory.RemoteCodeFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +/** + * @author DongXiaoDong + * @version 1.0 + * @date 2024/4/4 16:00 + * @description + */ +@FeignClient(contextId = "remoteCodeService",value = ServiceNameConstants.BUSINESS_SERVICE, fallbackFactory = RemoteCodeFallbackFactory.class) +public interface RemoteCodeService { + + @PostMapping("insertCode") + public Result insertCode(@RequestBody CoupletTroubleLog coupletTroubleLog); +} diff --git a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java new file mode 100644 index 0000000..d71a4d9 --- /dev/null +++ b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java @@ -0,0 +1,32 @@ +package com.couplet.common.system.remote.factory; + +import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleLog; +import com.couplet.common.system.remote.RemoteCodeService; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +/** + * @author DongXiaoDong + * @version 1.0 + * @date 2024/4/4 16:03 + * @description + */ +@Slf4j +@Component +public class RemoteCodeFallbackFactory implements FallbackFactory { + @Override + public RemoteCodeService create(Throwable cause) { + log.error("调用日志服务异常:{}", cause.getMessage()); + return new RemoteCodeService() + { + @Override + public Result insertCode(CoupletTroubleLog coupletTroubleLog) { + return null; + } + }; + } +} diff --git a/couplet-common/couplet-common-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/couplet-common/couplet-common-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 428b4e8..8c98848 100644 --- a/couplet-common/couplet-common-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/couplet-common/couplet-common-system/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -3,3 +3,4 @@ com.couplet.common.system.remote.factory.RemoteLogFallbackFactory com.couplet.common.system.remote.factory.RemoteFileFallbackFactory com.couplet.common.system.remote.factory.RemoteDeptFallbackFactory com.couplet.common.system.remote.factory.RemoteEmployeeFallbackFactory +com.couplet.common.system.remote.factory.RemoteCodeFallbackFactory diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml b/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml index 2dd1c32..715187a 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml @@ -86,6 +86,12 @@ org.eclipse.paho.client.mqttv3 1.2.5 + + + + org.springframework.boot + spring-boot-starter-amqp + 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 0a53f09..78c0477 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 @@ -6,6 +6,7 @@ import com.couplet.common.core.utils.SpringUtils; import com.couplet.common.core.utils.uuid.IdUtils; import lombok.extern.slf4j.Slf4j; import org.eclipse.paho.client.mqttv3.*; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; @@ -35,13 +36,8 @@ import static io.lettuce.core.pubsub.PubSubOutput.Type.message; @Component public class ModelMessage { -// @Autowired -// private CoupletMsgService coupletMsgService; - -// @Autowired -// public ModelMessage(CoupletMsgService coupletMsgService){ -// this.coupletMsgService = coupletMsgService; -// } + @Autowired + private RabbitTemplate rabbitTemplate; static ArrayList strings = new ArrayList<>() { { add("breakdown"); @@ -87,7 +83,11 @@ public class ModelMessage { for (CoupletMsgData msgData : coupletMsgDataList) { log.info("解析到车辆数据:{}", msgData); - //发送日志到MQ + //发送消息到MQ + rabbitTemplate.convertAndSend("send-couplet-code",msgData,message -> { + message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); + return message; + }); for (String string : strings) { IncidentService incidentService = SpringUtils.getBean(string); incidentService.incident(msgData); diff --git a/couplet-modules/couplet-business/pom.xml b/couplet-modules/couplet-business/pom.xml index 1c43041..2cd4db9 100644 --- a/couplet-modules/couplet-business/pom.xml +++ b/couplet-modules/couplet-business/pom.xml @@ -87,6 +87,12 @@ couplet-analyze-msg + + + org.springframework.boot + spring-boot-starter-amqp + + diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java index e0beabf..a4f5624 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/CoupletBusinessApplication.java @@ -13,8 +13,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; */ @EnableCustomConfig @EnableCustomSwagger2 -@EnableMyFeignClients(basePackages = ("com.couplet")) -@SpringBootApplication(scanBasePackages = {"com.couplet"}) +@EnableMyFeignClients(basePackages = ("com.couplet.**")) +@SpringBootApplication(scanBasePackages = {"com.couplet.**"}) public class CoupletBusinessApplication { public static void main (String[] args) { SpringApplication.run(CoupletBusinessApplication.class, args); diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java new file mode 100644 index 0000000..9603263 --- /dev/null +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java @@ -0,0 +1,97 @@ +package com.couplet.business.server.consumer; + +import com.alibaba.fastjson.JSONObject; +import com.couplet.analyze.msg.domain.CoupletMsgData; +import com.couplet.common.domain.CoupletTroubleLog; +import com.couplet.common.system.remote.RemoteCodeService; +import com.rabbitmq.client.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.Random; +import java.util.concurrent.CompletableFuture; + +/** + * @author DongXiaoDong + * @version 1.0 + * @date 2024/3/14 22:09 + * @description + */ +@Component +@Slf4j +public class SendCodeQueueConsumer { + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private RemoteCodeService remoteCodeService; + + @RabbitListener(queuesToDeclare = {@Queue("send-couplet-code")}) + public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) { + log.info("日志队列:{},接收到的消息:{},开始消费...","send-couplet-code", JSONObject.toJSONString(msgData)); + long start = System.currentTimeMillis(); + + String messageId = message.getMessageProperties().getMessageId(); + + try { + Long aLong = redisTemplate.opsForSet().add("send-log-queue", messageId); + if (aLong==1) { + //异步保存日志 + CompletableFuture.runAsync(() -> { + CoupletTroubleLog coupletTroubleLog = new CoupletTroubleLog(); + //判断状态是否为异常 + if (msgData.getVehicleStatus() !=1){ + String code = generateGTA(); + coupletTroubleLog.setTroubleLogCode(code); + coupletTroubleLog.setTroubleLogStart(new Date()); + String vin = msgData.getVin(); + coupletTroubleLog.setTroubleLogVin(vin); + // 如果状态为正常1时添加结束时间 + if (msgData.getVehicleStatus() == 1){ + coupletTroubleLog.setTroubleLogEnd(new Date()); + } + } + remoteCodeService.insertCode(coupletTroubleLog); + }); + log.info(""); + } + long end = System.currentTimeMillis(); + log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","send-log-queue", JSONObject.toJSONString(msgData), (end-start)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + /** + * + * 拼接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(); + } +} 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 38f9a64..5777d97 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 @@ -6,10 +6,12 @@ import com.couplet.common.core.domain.Result; import com.couplet.common.core.web.controller.BaseController; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; +import com.couplet.common.domain.CoupletTroubleLog; import com.couplet.common.domain.CoupletTroubleType; 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.*; @@ -24,6 +26,7 @@ import java.util.List; */ @RestController @RequestMapping("trouble") +@Slf4j public class SysTroubleController extends BaseController { @Autowired private SysTroubleService troubleService; @@ -80,4 +83,15 @@ public class SysTroubleController extends BaseController { troubleService.removeById(troubleId); return success(); } + + @PostMapping("insertCode") + public Result insertCode(@RequestBody CoupletTroubleLog coupletTroubleLog){ + long start = System.currentTimeMillis(); + int i = troubleService.insertMsgResq(coupletTroubleLog); + + long end = System.currentTimeMillis(); + log.info("记录异常信息成功,耗时:{}",(end-start)); + + return Result.success(i); + } } 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 d4ddf4b..6ca3d4b 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 @@ -8,7 +8,6 @@ import com.couplet.common.domain.CoupletTroubleLog; import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import java.util.List; @@ -25,4 +24,8 @@ public interface SysTroubleMapper extends BaseMapper { List selectTroubleListByType(); List selectTroubleListByGrade(); + + List selectTroubleListByMsg(); + + int insertMsgResq(CoupletTroubleLog coupletTroubleLog); } 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 07dd7f4..0122c14 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 @@ -5,6 +5,7 @@ import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.common.core.domain.PageResult; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; +import com.couplet.common.domain.CoupletTroubleLog; import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import io.swagger.models.auth.In; @@ -24,4 +25,8 @@ public interface SysTroubleService extends IService { List selectTroubleListByType(); List selectTroubleListByGrade(); + + List selectTroubleListByMsg(); + + int insertMsgResq(CoupletTroubleLog coupletTroubleLog); } 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 acaf6c0..9c0321d 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 @@ -7,6 +7,7 @@ import com.couplet.business.server.service.SysTroubleService; import com.couplet.common.core.domain.PageResult; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; +import com.couplet.common.domain.CoupletTroubleLog; import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import com.github.pagehelper.PageHelper; @@ -14,6 +15,7 @@ import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; import java.util.Random; @@ -52,33 +54,23 @@ public class SysTroubleServiceImpl extends ServiceImpl selectTroubleListByMsg() { + return sysTroubleMapper.selectTroubleListByMsg(); } + /** - * 随机生成1到10位的数字 - * @param length + * 添加异常信息 + * @param coupletTroubleLog * @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(); + @Override + public int insertMsgResq(CoupletTroubleLog coupletTroubleLog) { + return sysTroubleMapper.insertMsgResq(coupletTroubleLog); } - } 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 aa2677d..4701557 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 @@ -19,6 +19,11 @@ LEFT JOIN couplet_trouble_grade g on t.grade_id = g.grade_id LEFT JOIN couplet_trouble_type y on t.type_id= y.type_id + + insert into couplet_trouble_log(trouble_log_code,toruble_log_vin,trouble_log_start,trouble_log_end) + values(#{troubleLogCode},#{troubleLogVin},#{troubleLogStart},#{troubleLogEnd}) + + select * from couplet_trouble_grade - + select * from couplet_msg_data From 371c80d110828e4c47670852ea033d93c141511d Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 11:37:29 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/remote/RemoteCodeService.java | 2 +- .../analyze/msg/model/ModelMessage.java | 28 +- .../src/main/resources/bootstrap.yml | 12 +- .../consumer/SendCodeQueueConsumer.java | 194 +++++------ .../src/main/resources/bootstrap.yml | 3 +- .../mapper/business/SysTroubleMapper.xml | 2 +- .../com/couplet/mq/config/RabbitMQConfig.java | 12 +- .../couplet/mq/controller/MqController.java | 110 +++--- .../java/com/couplet/mq/service/Consumer.java | 328 +++++++++--------- 9 files changed, 347 insertions(+), 344 deletions(-) diff --git a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java index 4307c75..1475af8 100644 --- a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java +++ b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java @@ -17,6 +17,6 @@ import org.springframework.web.bind.annotation.RequestBody; @FeignClient(contextId = "remoteCodeService",value = ServiceNameConstants.BUSINESS_SERVICE, fallbackFactory = RemoteCodeFallbackFactory.class) public interface RemoteCodeService { - @PostMapping("insertCode") + @PostMapping("trouble/insertCode") public Result insertCode(@RequestBody CoupletTroubleLog coupletTroubleLog); } 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 4a36271..50ed034 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 @@ -48,16 +48,16 @@ public class ModelMessage { } }; - @Value("${mq.queueName}") - public String queueName; - - //交换机 - @Value("${mq.exchangeName}") - public String exchangeName; - - //路由键 - @Value("${mq.routingKey}") - public String routingKey; +// @Value("${mq.queueName}") +// public String queueName; +// +// //交换机 +// @Value("${mq.exchangeName}") +// public String exchangeName; +// +// //路由键 +// @Value("${mq.routingKey}") +// public String routingKey; @Scheduled(cron = "0/5 * * * * ?") public void startMsg() { @@ -85,10 +85,10 @@ public class ModelMessage { for (CoupletMsgData msgData : coupletMsgDataList) { log.info("解析到车辆数据:{}", msgData); //发送消息到MQ - rabbitTemplate.convertAndSend("send-couplet-code",msgData,message -> { - message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); - return message; - }); +// rabbitTemplate.convertAndSend("send-couplet-code",msgData,message -> { +// message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); +// return message; +// }); for (String string : strings) { IncidentService incidentService = SpringUtils.getBean(string); incidentService.incident(msgData); diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml index bed4d26..1476cf8 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml @@ -15,6 +15,7 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 config: # 配置中心地址 server-addr: 121.89.211.230:8848 @@ -23,6 +24,7 @@ spring: # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 main: allow-bean-definition-overriding: true rabbitmq: @@ -49,8 +51,8 @@ mybatis-plus: configuration: map-underscore-to-camel-case: true -# RabbitMQ配置 -mq: - queueName: queue - exchangeName: exchange - routingKey: routingKey +## RabbitMQ配置 +#mq: +# queueName: queueName +# exchangeName: exchangeName +# routingKey: routingKey diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java index 9603263..cdebce4 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java @@ -1,97 +1,97 @@ -package com.couplet.business.server.consumer; - -import com.alibaba.fastjson.JSONObject; -import com.couplet.analyze.msg.domain.CoupletMsgData; -import com.couplet.common.domain.CoupletTroubleLog; -import com.couplet.common.system.remote.RemoteCodeService; -import com.rabbitmq.client.Channel; -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.core.Message; -import org.springframework.amqp.rabbit.annotation.Queue; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.Date; -import java.util.Random; -import java.util.concurrent.CompletableFuture; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/3/14 22:09 - * @description - */ -@Component -@Slf4j -public class SendCodeQueueConsumer { - @Autowired - private RedisTemplate redisTemplate; - - @Autowired - private RemoteCodeService remoteCodeService; - - @RabbitListener(queuesToDeclare = {@Queue("send-couplet-code")}) - public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) { - log.info("日志队列:{},接收到的消息:{},开始消费...","send-couplet-code", JSONObject.toJSONString(msgData)); - long start = System.currentTimeMillis(); - - String messageId = message.getMessageProperties().getMessageId(); - - try { - Long aLong = redisTemplate.opsForSet().add("send-log-queue", messageId); - if (aLong==1) { - //异步保存日志 - CompletableFuture.runAsync(() -> { - CoupletTroubleLog coupletTroubleLog = new CoupletTroubleLog(); - //判断状态是否为异常 - if (msgData.getVehicleStatus() !=1){ - String code = generateGTA(); - coupletTroubleLog.setTroubleLogCode(code); - coupletTroubleLog.setTroubleLogStart(new Date()); - String vin = msgData.getVin(); - coupletTroubleLog.setTroubleLogVin(vin); - // 如果状态为正常1时添加结束时间 - if (msgData.getVehicleStatus() == 1){ - coupletTroubleLog.setTroubleLogEnd(new Date()); - } - } - remoteCodeService.insertCode(coupletTroubleLog); - }); - log.info(""); - } - long end = System.currentTimeMillis(); - log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","send-log-queue", JSONObject.toJSONString(msgData), (end-start)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - /** - * - * 拼接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(); - } -} +//package com.couplet.business.server.consumer; +// +//import com.alibaba.fastjson.JSONObject; +//import com.couplet.analyze.msg.domain.CoupletMsgData; +//import com.couplet.common.domain.CoupletTroubleLog; +//import com.couplet.common.system.remote.RemoteCodeService; +//import com.rabbitmq.client.Channel; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.amqp.core.Message; +//import org.springframework.amqp.rabbit.annotation.Queue; +//import org.springframework.amqp.rabbit.annotation.RabbitListener; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.data.redis.core.RedisTemplate; +//import org.springframework.stereotype.Component; +// +//import java.util.Date; +//import java.util.Random; +//import java.util.concurrent.CompletableFuture; +// +///** +// * @author DongXiaoDong +// * @version 1.0 +// * @date 2024/3/14 22:09 +// * @description +// */ +//@Component +//@Slf4j +//public class SendCodeQueueConsumer { +// @Autowired +// private RedisTemplate redisTemplate; +// +// @Autowired +// private RemoteCodeService remoteCodeService; +// +// @RabbitListener(queuesToDeclare = {@Queue("send-couplet-code")}) +// public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) { +// log.info("日志队列:{},接收到的消息:{},开始消费...","send-couplet-code", JSONObject.toJSONString(msgData)); +// long start = System.currentTimeMillis(); +// +// String messageId = message.getMessageProperties().getMessageId(); +// +// try { +// Long aLong = redisTemplate.opsForSet().add("send-log-queue", messageId); +// if (aLong==1) { +// //异步保存日志 +// CompletableFuture.runAsync(() -> { +// CoupletTroubleLog coupletTroubleLog = new CoupletTroubleLog(); +// //判断状态是否为异常 +// if (msgData.getVehicleStatus() !=1){ +// String code = generateGTA(); +// coupletTroubleLog.setTroubleLogCode(code); +// coupletTroubleLog.setTroubleLogStart(new Date()); +// String vin = msgData.getVin(); +// coupletTroubleLog.setTroubleLogVin(vin); +// // 如果状态为正常1时添加结束时间 +// if (msgData.getVehicleStatus() == 1){ +// coupletTroubleLog.setTroubleLogEnd(new Date()); +// } +// } +// remoteCodeService.insertCode(coupletTroubleLog); +// }); +// log.info("记录异常成功"); +// } +// long end = System.currentTimeMillis(); +// log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","send-log-queue", JSONObject.toJSONString(msgData), (end-start)); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// /** +// * +// * 拼接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(); +// } +//} diff --git a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml index cf4e9b6..2a9497d 100644 --- a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml @@ -7,7 +7,6 @@ spring: application: # 应用名称 name: couplet-business - profiles: # 环境配置 active: dev @@ -16,6 +15,7 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 config: # 配置中心地址 server-addr: 121.89.211.230:8848 @@ -24,6 +24,7 @@ spring: # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 main: allow-bean-definition-overriding: true logging: 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 4701557..7048dcf 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 @@ -20,7 +20,7 @@ LEFT JOIN couplet_trouble_type y on t.type_id= y.type_id - insert into couplet_trouble_log(trouble_log_code,toruble_log_vin,trouble_log_start,trouble_log_end) + insert into couplet_trouble_log(trouble_log_code,trouble_log_vin,trouble_log_start,trouble_log_end) values(#{troubleLogCode},#{troubleLogVin},#{troubleLogStart},#{troubleLogEnd}) diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java index 341d052..853a559 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java @@ -25,16 +25,16 @@ import org.springframework.context.annotation.Primary; public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback { // 通过注入的方式获取队列名、交换机名和路由键 //队列名 - @Value("${mq.queueName}") - public String queueName; +// @Value("${mq.queueName}") + public static final String queueName = "queueName"; //交换机 - @Value("${mq.exchangeName}") - public String exchangeName; +// @Value("${mq.exchangeName}") + public static final String exchangeName = "exchangeName"; //路由键 - @Value("${mq.routingKey}") - public String routingKey; +// @Value("${mq.routingKey}") + public static final String routingKey = "routingKey"; private RabbitTemplate rabbitTemplate; diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java index 057ac32..87b5529 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java @@ -1,55 +1,55 @@ -package com.couplet.mq.controller; - -import com.couplet.common.core.utils.uuid.IdUtils; -import com.couplet.mq.domain.User; -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.rabbit.connection.CorrelationData; -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.*; - -/** - * @ProjectName: five-groups-couplet - * @Author: LiuYunHu - * @CreateTime: 2024/3/29 - * @Description: MQController类 - */ -@RestController -@RequestMapping("/mq") -@Slf4j -public class MqController { - // 通过注入的方式获取队列名、交换机名和路由键 - //队列名 - @Value("${mq.queueName}") - public String queueName; - - //交换机 - @Value("${mq.exchangeName}") - public String exchangeName; - - //路由键 - @Value("${mq.routingKey}") - public String routingKey; - - @Autowired - private RabbitTemplate rabbitTemplate; - - /* - * @Author: LiuYunHu - * @Date: 2024/4/1 19:58 - * @Description: 消息发送者 - * @Param: [data] - * @Return: void - **/ - @PostMapping("/sout") - //接收json字符串 - public void sout(@RequestBody User param) { - rabbitTemplate.convertAndSend(exchangeName, routingKey, param, message -> { - message.getMessageProperties().setMessageId(IdUtils.randomUUID()); - return message; - }, new CorrelationData(IdUtils.randomUUID()) - ); - - } -} +//package com.couplet.mq.controller; +// +//import com.couplet.common.core.utils.uuid.IdUtils; +//import com.couplet.mq.domain.User; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.amqp.rabbit.connection.CorrelationData; +//import org.springframework.amqp.rabbit.core.RabbitTemplate; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.web.bind.annotation.*; +// +///** +// * @ProjectName: five-groups-couplet +// * @Author: LiuYunHu +// * @CreateTime: 2024/3/29 +// * @Description: MQController类 +// */ +//@RestController +//@RequestMapping("/mq") +//@Slf4j +//public class MqController { +// // 通过注入的方式获取队列名、交换机名和路由键 +// //队列名 +//// @Value("${mq.queueName}") +// public String queueName; +// +// //交换机 +//// @Value("${mq.exchangeName}") +// public String exchangeName; +// +// //路由键 +//// @Value("${mq.routingKey}") +// public String routingKey; +// +// @Autowired +// private RabbitTemplate rabbitTemplate; +// +// /* +// * @Author: LiuYunHu +// * @Date: 2024/4/1 19:58 +// * @Description: 消息发送者 +// * @Param: [data] +// * @Return: void +// **/ +// @PostMapping("/sout") +// //接收json字符串 +// public void sout(@RequestBody User param) { +// rabbitTemplate.convertAndSend(exchangeName, routingKey, param, message -> { +// message.getMessageProperties().setMessageId(IdUtils.randomUUID()); +// return message; +// }, new CorrelationData(IdUtils.randomUUID()) +// ); +// +// } +//} diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java index a01fcac..5c0def9 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java @@ -1,164 +1,164 @@ -package com.couplet.mq.service; - -import com.couplet.mq.domain.User; -import com.rabbitmq.client.Channel; -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.core.Message; -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Component; - -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -/** - * @ProjectName: five-groups-couplet - * @Author: LiuYunHu - * @CreateTime: 2024/3/28 - * @Description: MQ消费者类 - */ - -@Component -@Slf4j -@SuppressWarnings("all") -@RabbitListener(queues = "${mq.queueName}") -public class Consumer { - @Autowired - private StringRedisTemplate redis; - - /* 线程池执行 - - //创建一个定长线程池 - private final Executor executor = Executors.newFixedThreadPool(5); - - @Async - @RabbitHandler - public void process(User param, Channel channel, Message message) { - executor.execute(() -> { - try { - handleMessage(param, channel, message); - } catch (IOException e) { - log.error("处理消息失败:{}", e); - } - }); - } - - //处理信息的方法 - private void handleMessage(User param, Channel channel, Message message) throws IOException { - log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag()); - - long deliveryTag = message.getMessageProperties().getDeliveryTag(); - String messageId = message.getMessageProperties().getMessageId(); - - if (!redis.hasKey("value:" + messageId)) { - redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES); - } - - // 1 添加成功新数据 0已有重复值,不允许再添加 - Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId); - //过期时间 - redis.expire("set:" + messageId, 5, TimeUnit.MINUTES); - - - try { - if (add == 1) { - //第一次 消费 - System.out.println("*****************************"); - System.out.println("消费者收到消息:" + param); - System.out.println("*****************************"); - log.info("消费结束"); - - channel.basicAck(deliveryTag, false); - - } else { - //重复消费 - log.error("重复消费"); - channel.basicReject(deliveryTag, false); - - //删除缓存 - redis.opsForSet().remove("set:" + messageId, "set:" + messageId); - } - - - } catch (Exception e) { - log.error("消息没有成功消费!"); - - String s = redis.opsForValue().get("value:" + messageId); - - long oldTag = Long.parseLong(s); - - if (deliveryTag == (oldTag + 2)) { - log.error("确实消费不了,不入队了!"); - channel.basicNack(deliveryTag, false, false); - } else { - log.info("消息消费失败,重新入队"); - channel.basicNack(deliveryTag, false, true); - } - } - - } - -**/ - - @RabbitHandler - public void process(User param, Channel channel, Message message) throws IOException { - log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag()); - - long deliveryTag = message.getMessageProperties().getDeliveryTag(); - String messageId = message.getMessageProperties().getMessageId(); - - if (!redis.hasKey("value:" + messageId)) { - redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES); - } - - // 1 添加成功新数据 0已有重复值,不允许再添加 - Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId); - //过期时间 - redis.expire("set:" + messageId, 5, TimeUnit.MINUTES); - - - try { - if (add == 1) { - //第一次 消费 - System.out.println("*****************************"); - System.out.println("消费者收到消息:" + param); - System.out.println("*****************************"); - log.info("消费结束"); - - //确认消费 - channel.basicAck(deliveryTag, false); - - } else { - //重复消费 - log.error("重复消费"); - //拒绝消费 - channel.basicReject(deliveryTag, false); - - //删除缓存 - redis.opsForSet().remove("set:" + messageId, "set:" + messageId); - } - - - } catch (Exception e) { - log.error("消息没有成功消费!"); - - String s = redis.opsForValue().get("value:" + messageId); - - long oldTag = Long.parseLong(s); - - if (deliveryTag == (oldTag + 2)) { - log.error("确实消费不了,不入队了!"); - - - //拒绝消费 - channel.basicNack(deliveryTag, false, false); - } else { - log.info("消息消费失败,重新入队"); - //重新入队 - channel.basicNack(deliveryTag, false, true); - } - } - } -} +//package com.couplet.mq.service; +// +//import com.couplet.mq.domain.User; +//import com.rabbitmq.client.Channel; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.amqp.core.Message; +//import org.springframework.amqp.rabbit.annotation.RabbitHandler; +//import org.springframework.amqp.rabbit.annotation.RabbitListener; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.data.redis.core.StringRedisTemplate; +//import org.springframework.stereotype.Component; +// +//import java.io.IOException; +//import java.util.concurrent.TimeUnit; +// +///** +// * @ProjectName: five-groups-couplet +// * @Author: LiuYunHu +// * @CreateTime: 2024/3/28 +// * @Description: MQ消费者类 +// */ +// +//@Component +//@Slf4j +//@SuppressWarnings("all") +//@RabbitListener(queues = "${mq.queueName}") +//public class Consumer { +// @Autowired +// private StringRedisTemplate redis; +// +// /* 线程池执行 +// +// //创建一个定长线程池 +// private final Executor executor = Executors.newFixedThreadPool(5); +// +// @Async +// @RabbitHandler +// public void process(User param, Channel channel, Message message) { +// executor.execute(() -> { +// try { +// handleMessage(param, channel, message); +// } catch (IOException e) { +// log.error("处理消息失败:{}", e); +// } +// }); +// } +// +// //处理信息的方法 +// private void handleMessage(User param, Channel channel, Message message) throws IOException { +// log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag()); +// +// long deliveryTag = message.getMessageProperties().getDeliveryTag(); +// String messageId = message.getMessageProperties().getMessageId(); +// +// if (!redis.hasKey("value:" + messageId)) { +// redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES); +// } +// +// // 1 添加成功新数据 0已有重复值,不允许再添加 +// Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId); +// //过期时间 +// redis.expire("set:" + messageId, 5, TimeUnit.MINUTES); +// +// +// try { +// if (add == 1) { +// //第一次 消费 +// System.out.println("*****************************"); +// System.out.println("消费者收到消息:" + param); +// System.out.println("*****************************"); +// log.info("消费结束"); +// +// channel.basicAck(deliveryTag, false); +// +// } else { +// //重复消费 +// log.error("重复消费"); +// channel.basicReject(deliveryTag, false); +// +// //删除缓存 +// redis.opsForSet().remove("set:" + messageId, "set:" + messageId); +// } +// +// +// } catch (Exception e) { +// log.error("消息没有成功消费!"); +// +// String s = redis.opsForValue().get("value:" + messageId); +// +// long oldTag = Long.parseLong(s); +// +// if (deliveryTag == (oldTag + 2)) { +// log.error("确实消费不了,不入队了!"); +// channel.basicNack(deliveryTag, false, false); +// } else { +// log.info("消息消费失败,重新入队"); +// channel.basicNack(deliveryTag, false, true); +// } +// } +// +// } +// +//**/ +// +// @RabbitHandler +// public void process(User param, Channel channel, Message message) throws IOException { +// log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag()); +// +// long deliveryTag = message.getMessageProperties().getDeliveryTag(); +// String messageId = message.getMessageProperties().getMessageId(); +// +// if (!redis.hasKey("value:" + messageId)) { +// redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES); +// } +// +// // 1 添加成功新数据 0已有重复值,不允许再添加 +// Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId); +// //过期时间 +// redis.expire("set:" + messageId, 5, TimeUnit.MINUTES); +// +// +// try { +// if (add == 1) { +// //第一次 消费 +// System.out.println("*****************************"); +// System.out.println("消费者收到消息:" + param); +// System.out.println("*****************************"); +// log.info("消费结束"); +// +// //确认消费 +// channel.basicAck(deliveryTag, false); +// +// } else { +// //重复消费 +// log.error("重复消费"); +// //拒绝消费 +// channel.basicReject(deliveryTag, false); +// +// //删除缓存 +// redis.opsForSet().remove("set:" + messageId, "set:" + messageId); +// } +// +// +// } catch (Exception e) { +// log.error("消息没有成功消费!"); +// +// String s = redis.opsForValue().get("value:" + messageId); +// +// long oldTag = Long.parseLong(s); +// +// if (deliveryTag == (oldTag + 2)) { +// log.error("确实消费不了,不入队了!"); +// +// +// //拒绝消费 +// channel.basicNack(deliveryTag, false, false); +// } else { +// log.info("消息消费失败,重新入队"); +// //重新入队 +// channel.basicNack(deliveryTag, false, true); +// } +// } +// } +//} From 71f1bc84e211c93bdc744bd23d83757d0fbfe0f4 Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 18:01:10 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/domain/CoupletTroubleCode.java | 26 +++- .../common/domain/CoupletTroubleType.java | 15 --- .../system/remote/RemoteCodeService.java | 3 +- .../factory/RemoteCodeFallbackFactory.java | 3 +- .../analyze/msg/consumer/MsgConsumer.java | 2 +- .../analyze/msg/model/ModelMessage.java | 116 ++++++++++++++++-- .../src/test/java/com/couplet/msg/Main.java | 20 +-- .../consumer/SendCodeQueueConsumer.java | 97 --------------- .../controller/SysTroubleController.java | 18 ++- .../controller/TroubleLogController.java | 10 -- .../server/mapper/SysTroubleMapper.java | 7 +- .../server/mapper/TroubleLogMapper.java | 16 --- .../server/service/SysTroubleService.java | 7 +- .../server/service/TroubleLogService.java | 13 -- .../service/impl/SysTroubleServiceImpl.java | 20 +-- .../service/impl/TroubleLogServiceImpl.java | 23 ---- .../mapper/business/SysTroubleMapper.xml | 29 ++--- .../mapper/business/TroubleLogMapper.xml | 8 -- mqttx_32dcaf76-tcp8130181161883/.lck | 0 19 files changed, 167 insertions(+), 266 deletions(-) delete mode 100644 couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleType.java delete mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java delete mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java delete mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java delete mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java delete mode 100644 couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/TroubleLogServiceImpl.java delete mode 100644 couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml create mode 100644 mqttx_32dcaf76-tcp8130181161883/.lck 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 3134a5e..dc36948 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 @@ -3,12 +3,15 @@ package com.couplet.common.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.couplet.common.core.annotation.Excel; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.NotEmpty; +import java.util.Date; /** * @author DongXiaoDong @@ -37,6 +40,12 @@ public class CoupletTroubleCode { @NotEmpty(message = "故障码不能为空") private String troubleCode; + /** + * vin + */ + @Excel(name = "vin") + private String troubleVin; + /** * 故障位 */ @@ -60,12 +69,19 @@ public class CoupletTroubleCode { */ @Excel(name = "故障类型Id") @NotEmpty(message = "故障类型Id不能为空") - private Integer typeId; + private String troubleType; /** - * 故障等级Id + * 故障开始时间 */ - @Excel(name = "故障等级Id") - @NotEmpty(message = "故障等级Id不能为空") - private Integer gradeId; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date troubleStartTime; + + /** + * 故障结束时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date troubleEndTime; } diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleType.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleType.java deleted file mode 100644 index 497e180..0000000 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/CoupletTroubleType.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.couplet.common.domain; - -import lombok.Data; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/3/26 21:50 - * @description - */ -@Data -public class CoupletTroubleType { - private Integer typeId; - private String typeName; -} diff --git a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java index 1475af8..d897d69 100644 --- a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java +++ b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/RemoteCodeService.java @@ -2,6 +2,7 @@ package com.couplet.common.system.remote; import com.couplet.common.core.constant.ServiceNameConstants; import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleLog; import com.couplet.common.system.remote.factory.RemoteCodeFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; @@ -18,5 +19,5 @@ import org.springframework.web.bind.annotation.RequestBody; public interface RemoteCodeService { @PostMapping("trouble/insertCode") - public Result insertCode(@RequestBody CoupletTroubleLog coupletTroubleLog); + public Result insertCode(@RequestBody CoupletTroubleCode coupletTroubleCode); } diff --git a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java index d71a4d9..d6fd2b9 100644 --- a/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java +++ b/couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/remote/factory/RemoteCodeFallbackFactory.java @@ -1,6 +1,7 @@ package com.couplet.common.system.remote.factory; import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleLog; import com.couplet.common.system.remote.RemoteCodeService; import lombok.extern.slf4j.Slf4j; @@ -24,7 +25,7 @@ public class RemoteCodeFallbackFactory implements FallbackFactory insertCode(CoupletTroubleLog coupletTroubleLog) { + public Result insertCode(CoupletTroubleCode coupletTroubleCode) { return null; } }; diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java index 53db614..fb4f986 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/MsgConsumer.java @@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit; */ @Log4j2 @Component -@RabbitListener(queues = "vinQueue") +//@RabbitListener(queues = "vinQueue") public class MsgConsumer { @Autowired 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 50ed034..f37130c 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 @@ -5,6 +5,9 @@ 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.core.utils.uuid.IdUtils; +import com.couplet.common.domain.CoupletTroubleCode; +import com.couplet.common.domain.CoupletTroubleLog; +import com.couplet.common.system.remote.RemoteCodeService; import lombok.extern.slf4j.Slf4j; import org.eclipse.paho.client.mqttv3.*; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -15,10 +18,8 @@ import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -48,6 +49,9 @@ public class ModelMessage { } }; + @Autowired + private RemoteCodeService remoteCodeService; + // @Value("${mq.queueName}") // public String queueName; // @@ -84,11 +88,33 @@ public class ModelMessage { for (CoupletMsgData msgData : coupletMsgDataList) { log.info("解析到车辆数据:{}", msgData); - //发送消息到MQ -// rabbitTemplate.convertAndSend("send-couplet-code",msgData,message -> { -// message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); -// return message; -// }); + // 使用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); @@ -115,6 +141,78 @@ 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-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Main.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Main.java index 77a6a21..143796c 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Main.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/test/java/com/couplet/msg/Main.java @@ -1,5 +1,6 @@ package com.couplet.msg; +import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -11,18 +12,17 @@ import java.util.regex.Pattern; */ public class Main { public static void main(String[] args) { - String msgString = "VIN123456789DIJE41711764104506116.664380039.531990072.00031.3760000022000022000852000000D00809.600940000589066790930000203002030000044282.55000014000080700007440003000400095000058000054000011111111111111111"; + // 创建一个字符串数组存储三个状态 + String[] statuses = {"电池故障", "车体故障", "车尾故障","抽轮故障"}; - //使用正则表达式匹配需要的部分 - String pattern = "(.{17})(.{10})(.{4})(.{2})(.{2})"; - Pattern compile = Pattern.compile(pattern); - Matcher matcher = compile.matcher(msgString); + // 生成随机数对象 + Random rand = new Random(); - if (matcher.find()) { - for (int i = 1; i <= matcher.groupCount(); i++) { - System.out.println("Group "+ i + ":" + matcher.group(i)); - } - } + // 生成一个范围在 0 到 2 之间的随机整数 + int randomIndex = rand.nextInt(4); + // 随机选择一个字符串并输出 + String randomStatus = statuses[randomIndex]; + System.out.println("随机输出的字符串:" + randomStatus); } } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java deleted file mode 100644 index cdebce4..0000000 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/consumer/SendCodeQueueConsumer.java +++ /dev/null @@ -1,97 +0,0 @@ -//package com.couplet.business.server.consumer; -// -//import com.alibaba.fastjson.JSONObject; -//import com.couplet.analyze.msg.domain.CoupletMsgData; -//import com.couplet.common.domain.CoupletTroubleLog; -//import com.couplet.common.system.remote.RemoteCodeService; -//import com.rabbitmq.client.Channel; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.amqp.core.Message; -//import org.springframework.amqp.rabbit.annotation.Queue; -//import org.springframework.amqp.rabbit.annotation.RabbitListener; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.data.redis.core.RedisTemplate; -//import org.springframework.stereotype.Component; -// -//import java.util.Date; -//import java.util.Random; -//import java.util.concurrent.CompletableFuture; -// -///** -// * @author DongXiaoDong -// * @version 1.0 -// * @date 2024/3/14 22:09 -// * @description -// */ -//@Component -//@Slf4j -//public class SendCodeQueueConsumer { -// @Autowired -// private RedisTemplate redisTemplate; -// -// @Autowired -// private RemoteCodeService remoteCodeService; -// -// @RabbitListener(queuesToDeclare = {@Queue("send-couplet-code")}) -// public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) { -// log.info("日志队列:{},接收到的消息:{},开始消费...","send-couplet-code", JSONObject.toJSONString(msgData)); -// long start = System.currentTimeMillis(); -// -// String messageId = message.getMessageProperties().getMessageId(); -// -// try { -// Long aLong = redisTemplate.opsForSet().add("send-log-queue", messageId); -// if (aLong==1) { -// //异步保存日志 -// CompletableFuture.runAsync(() -> { -// CoupletTroubleLog coupletTroubleLog = new CoupletTroubleLog(); -// //判断状态是否为异常 -// if (msgData.getVehicleStatus() !=1){ -// String code = generateGTA(); -// coupletTroubleLog.setTroubleLogCode(code); -// coupletTroubleLog.setTroubleLogStart(new Date()); -// String vin = msgData.getVin(); -// coupletTroubleLog.setTroubleLogVin(vin); -// // 如果状态为正常1时添加结束时间 -// if (msgData.getVehicleStatus() == 1){ -// coupletTroubleLog.setTroubleLogEnd(new Date()); -// } -// } -// remoteCodeService.insertCode(coupletTroubleLog); -// }); -// log.info("记录异常成功"); -// } -// long end = System.currentTimeMillis(); -// log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","send-log-queue", JSONObject.toJSONString(msgData), (end-start)); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// } -// /** -// * -// * 拼接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(); -// } -//} 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 5777d97..0377c48 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 @@ -7,7 +7,6 @@ import com.couplet.common.core.web.controller.BaseController; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; import com.couplet.common.domain.CoupletTroubleLog; -import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import com.couplet.common.log.annotation.Log; import com.couplet.common.log.enums.BusinessType; @@ -40,14 +39,6 @@ public class SysTroubleController extends BaseController { return Result.success(result); } - /** - * 故障类型信息 - */ - @GetMapping("/troubleTypeList") - public List listType() { - return troubleService.selectTroubleListByType(); - } - /** * 故障等级信息 */ @@ -84,10 +75,15 @@ public class SysTroubleController extends BaseController { return success(); } + /** + * 故障数据入库 + * @param coupletTroubleLog + * @return + */ @PostMapping("insertCode") - public Result insertCode(@RequestBody CoupletTroubleLog coupletTroubleLog){ + public Result insertCode(@RequestBody CoupletTroubleCode coupletTroubleCode){ long start = System.currentTimeMillis(); - int i = troubleService.insertMsgResq(coupletTroubleLog); + int i = troubleService.insertMsgResq(coupletTroubleCode); long end = System.currentTimeMillis(); log.info("记录异常信息成功,耗时:{}",(end-start)); diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java deleted file mode 100644 index 7ff88b5..0000000 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/TroubleLogController.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.couplet.business.server.controller; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/4/4 10:37 - * @description - */ -public class TroubleLogController { -} 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 6ca3d4b..af3460a 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 @@ -5,7 +5,6 @@ import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; import com.couplet.common.domain.CoupletTroubleLog; -import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import org.apache.ibatis.annotations.Mapper; @@ -21,11 +20,7 @@ import java.util.List; public interface SysTroubleMapper extends BaseMapper { List selectTroubleList(TroubleResp troubleReq); - List selectTroubleListByType(); - List selectTroubleListByGrade(); - List selectTroubleListByMsg(); - - int insertMsgResq(CoupletTroubleLog coupletTroubleLog); + int insertMsgResq(CoupletTroubleCode coupletTroubleCode); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java deleted file mode 100644 index b686e7d..0000000 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/TroubleLogMapper.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.couplet.business.server.mapper; - - -import com.couplet.analyze.msg.domain.CoupletMsgData; -import org.apache.ibatis.annotations.Mapper; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/4/4 10:38 - * @description - */ -@Mapper -public interface TroubleLogMapper { - -} 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 0122c14..6abe6f4 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 @@ -6,7 +6,6 @@ import com.couplet.common.core.domain.PageResult; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; import com.couplet.common.domain.CoupletTroubleLog; -import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import io.swagger.models.auth.In; @@ -22,11 +21,7 @@ import java.util.List; public interface SysTroubleService extends IService { PageResult selectTroubleList(TroubleResp troubleReq); - List selectTroubleListByType(); - List selectTroubleListByGrade(); - List selectTroubleListByMsg(); - - int insertMsgResq(CoupletTroubleLog coupletTroubleLog); + int insertMsgResq(CoupletTroubleCode coupletTroubleCode); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java deleted file mode 100644 index d230dc6..0000000 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/TroubleLogService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.couplet.business.server.service; - -import com.couplet.analyze.msg.domain.CoupletMsgData; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/4/4 10:38 - * @description - */ -public interface TroubleLogService { - -} 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 9c0321d..1280760 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 @@ -8,7 +8,6 @@ import com.couplet.common.core.domain.PageResult; import com.couplet.common.domain.CoupletTroubleCode; import com.couplet.common.domain.CoupletTroubleGrade; import com.couplet.common.domain.CoupletTroubleLog; -import com.couplet.common.domain.CoupletTroubleType; import com.couplet.common.domain.request.TroubleResp; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -44,33 +43,18 @@ public class SysTroubleServiceImpl extends ServiceImpl selectTroubleListByType() { - return sysTroubleMapper.selectTroubleListByType(); - } - @Override public List selectTroubleListByGrade() { return sysTroubleMapper.selectTroubleListByGrade(); } - /** - * 查询报文信息 - * @return - */ - @Override - public List selectTroubleListByMsg() { - return sysTroubleMapper.selectTroubleListByMsg(); - } - - /** * 添加异常信息 * @param coupletTroubleLog * @return */ @Override - public int insertMsgResq(CoupletTroubleLog coupletTroubleLog) { - return sysTroubleMapper.insertMsgResq(coupletTroubleLog); + public int insertMsgResq(CoupletTroubleCode coupletTroubleCode) { + return sysTroubleMapper.insertMsgResq(coupletTroubleCode); } } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/TroubleLogServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/TroubleLogServiceImpl.java deleted file mode 100644 index 3555be6..0000000 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/TroubleLogServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.couplet.business.server.service.impl; - -import com.couplet.analyze.msg.domain.CoupletMsgData; -import com.couplet.business.server.mapper.TroubleLogMapper; -import com.couplet.business.server.service.TroubleLogService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Random; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/4/4 10:38 - * @description - */ -@Service -public class TroubleLogServiceImpl implements TroubleLogService { - @Autowired - private TroubleLogMapper troubleLogMapper; - - -} 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 7048dcf..2015bf8 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 @@ -7,23 +7,18 @@ + - - + + + - select t.*,g.grade_name,y.type_name from couplet_trouble_code t - LEFT JOIN couplet_trouble_grade g on t.grade_id = g.grade_id - LEFT JOIN couplet_trouble_type y on t.type_id= y.type_id + select * from couplet_trouble_code - - insert into couplet_trouble_log(trouble_log_code,trouble_log_vin,trouble_log_start,trouble_log_end) - values(#{troubleLogCode},#{troubleLogVin},#{troubleLogStart},#{troubleLogEnd}) - - - - + + insert into couplet_trouble_code( + trouble_code, + trouble_vin, + trouble_position,trouble_value,trouble_tag,trouble_type,trouble_start_time,trouble_end_time) + values(#{troubleCode},#{troubleVin},#{troublePosition},#{troubleValue},#{troubleTag},#{troubleType},#{troubleStartTime},#{troubleEndTime}) + + diff --git a/couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml b/couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml deleted file mode 100644 index b2e17c4..0000000 --- a/couplet-modules/couplet-business/src/main/resources/mapper/business/TroubleLogMapper.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/mqttx_32dcaf76-tcp8130181161883/.lck b/mqttx_32dcaf76-tcp8130181161883/.lck new file mode 100644 index 0000000..e69de29 From 9a78e4a2e280a9beaeb0ba0501b016260a55e49b Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Fri, 5 Apr 2024 18:39:02 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/server/controller/SysTroubleController.java | 9 +++++++++ .../couplet/business/server/mapper/SysTroubleMapper.java | 2 ++ .../business/server/service/SysTroubleService.java | 2 ++ .../server/service/impl/SysTroubleServiceImpl.java | 8 ++++++++ .../main/resources/mapper/business/SysTroubleMapper.xml | 4 ++++ 5 files changed, 25 insertions(+) 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 0377c48..8220bed 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 @@ -90,4 +90,13 @@ public class SysTroubleController extends BaseController { return Result.success(i); } + + /** + * 清空故障码信息 + */ + @PostMapping("cleanTroubleCode") + public Result cleanTroubleCode(){ + troubleService.cleanTroubleCode(); + return Result.success(); + } } 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 af3460a..6986b8d 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 @@ -23,4 +23,6 @@ public interface SysTroubleMapper extends BaseMapper { List selectTroubleListByGrade(); int insertMsgResq(CoupletTroubleCode coupletTroubleCode); + + 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 6abe6f4..744ab5f 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 @@ -24,4 +24,6 @@ public interface SysTroubleService extends IService { List selectTroubleListByGrade(); int insertMsgResq(CoupletTroubleCode coupletTroubleCode); + + 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 1280760..efcfe7f 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 @@ -57,4 +57,12 @@ public class SysTroubleServiceImpl extends ServiceImpl select * from couplet_trouble_code + + truncate table couplet_trouble_code + +