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})
+
+