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("实时数据事件结束.....");