feat: 新增事件处理系统故障报警功能
parent
08e3207110
commit
2dd3a41d62
17
pom.xml
17
pom.xml
|
@ -16,6 +16,23 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- rabbit -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.amqp</groupId>
|
||||
<artifactId>spring-rabbit-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<!-- caffeine -->
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>2.9.3</version>
|
||||
</dependency>
|
||||
<!-- SpringBoot Boot Redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.muyu.eventdriven;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
public class EventDrivenApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.context.annotation.Import;
|
|||
* @Author Xin.Yao
|
||||
* @Date 2024/5/9 19:52
|
||||
*/
|
||||
@ComponentScan
|
||||
@Import({EventDrivenRunner.class})
|
||||
public class EventDrivenConfig {
|
||||
}
|
||||
//@ComponentScan
|
||||
//@Import({EventDrivenRunner.class})
|
||||
//public class EventDrivenConfig {
|
||||
//}
|
||||
|
|
|
@ -1,35 +1,20 @@
|
|||
package com.muyu.eventdriven.config;
|
||||
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.muyu.eventdriven.domain.EventTacticsManage;
|
||||
import com.muyu.eventdriven.domain.VehicleData;
|
||||
import com.muyu.eventdriven.tactics.EventContext;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName DataAccessClientRunner
|
||||
* @Description 描述
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/5/9 19:53
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class EventDrivenRunner implements ApplicationRunner {
|
||||
@Autowired
|
||||
private EventTacticsManage eventTacticsManage;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args){
|
||||
eventTacticsManage.initEventTacticsManage();
|
||||
}
|
||||
}
|
||||
//@Log4j2
|
||||
//@Component
|
||||
//public class EventDrivenRunner implements ApplicationRunner {
|
||||
// @Autowired
|
||||
// private EventTacticsManage eventTacticsManage;
|
||||
//
|
||||
// @Override
|
||||
// public void run(ApplicationArguments args){
|
||||
// eventTacticsManage.initEventTacticsManage();
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.eventdriven.config.caffeine;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName CaffeineCacheConfig
|
||||
* @Description 本地缓存配置类
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/21 上午9:39
|
||||
*/
|
||||
@Configuration
|
||||
public class CaffeineCacheConfig {
|
||||
@Bean
|
||||
public Cache<String, Object> caffeineCache() {
|
||||
return Caffeine.newBuilder()
|
||||
// 设置最后一次写入或访问后经过固定时间过期
|
||||
.expireAfterWrite(5, TimeUnit.SECONDS)
|
||||
// 初始的缓存空间大小
|
||||
.initialCapacity(100)
|
||||
// 缓存的最大条数
|
||||
.maximumSize(1000)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.eventdriven.config;
|
||||
package com.muyu.eventdriven.config.iotdb;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
|
@ -186,4 +186,4 @@ public class IotDBSessionConfig {
|
|||
session.deleteData(pathList, startTime, endTime);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.muyu.eventdriven.config.rabbit;
|
||||
|
||||
import com.muyu.eventdriven.constants.RabbitConstants;
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @ClassName RabbitRoutingConfig
|
||||
* @Description rabbit配置类
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/21 上午11:35
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitRoutingConfig {
|
||||
/**
|
||||
* Queue 可以有4个参数
|
||||
* 1.name 队列名
|
||||
* 2.durable 持久化消息队列 ,rabbitmq重启的时候不需要创建新的队列 默认true
|
||||
* 3.auto-delete 表示消息队列没有在使用时将被自动删除 默认是false
|
||||
* 4.exclusive 表示该消息队列是否只在当前connection生效,默认是false
|
||||
*/
|
||||
@Bean
|
||||
public Queue createRoutingQueueA() {
|
||||
return new Queue(RabbitConstants.QUEUE_STATUS_ABNORMAL, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue createRoutingQueueB() {
|
||||
return new Queue(RabbitConstants.QUEUE_STATUS_NORMAL, true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectExchange routingExchange() {
|
||||
//配置广播路由器
|
||||
return new DirectExchange(RabbitConstants.EXCHANGE_STATUS);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding bingQueueAToRoutingExchange() {
|
||||
return BindingBuilder.bind(createRoutingQueueA()).to(routingExchange()).with(RabbitConstants.STATUS_ABNORMAL);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding bingQueueBToRoutingExchange() {
|
||||
return BindingBuilder.bind(createRoutingQueueB()).to(routingExchange()).with(RabbitConstants.STATUS_NORMAL);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.eventdriven.config.redis;
|
||||
|
||||
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.RedisMessageListenerContainer;
|
||||
|
||||
/**
|
||||
* @ClassName RedisListenerConfig
|
||||
* @Description redis键过期监听配置类
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/21 上午11:23
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisListenerConfig {
|
||||
@Bean
|
||||
public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
|
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||
container.setConnectionFactory(connectionFactory);
|
||||
return container;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.eventdriven.constants;
|
||||
|
||||
/**
|
||||
* @ClassName FaultCodeConstants
|
||||
* @Description 故障码常量
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/21 上午11:49
|
||||
*/
|
||||
public class FaultCodeConstants {
|
||||
public static final String VEHICLESTATUS = "GZ001";
|
||||
public static final String CHARGINGSTATUS = "GZ002";
|
||||
public static final String OPERATINGSTATUS = "GZ003";
|
||||
public static final String SOCSTATUS = "GZ004";
|
||||
public static final String CHARGINGENERGYSTORAGESTATUS = "GZ005";
|
||||
public static final String DRIVEMOTORSTATUS = "GZ006";
|
||||
public static final String POSITIONSTATUS = "GZ007";
|
||||
public static final String EASSTATUS = "GZ008";
|
||||
public static final String PTCSTATUS = "GZ009";
|
||||
public static final String EPSSTATUS = "GZ010";
|
||||
public static final String ABSSTATUS = "GZ011";
|
||||
public static final String MCUSTATUS = "GZ012";
|
||||
public static final String HEATINGSTATUS = "GZ013";
|
||||
public static final String BATTERYSTATUS = "GZ014";
|
||||
public static final String BATTERYINSULATIONSTATUS = "GZ015";
|
||||
public static final String DCDCSTATUS = "GZ016";
|
||||
public static final String CHGSTATUS = "GZ017";
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.eventdriven.constants;
|
||||
|
||||
/**
|
||||
* @ClassName RabbitConstants
|
||||
* @Description Rabbit常量类
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/21 上午11:39
|
||||
*/
|
||||
public class RabbitConstants {
|
||||
public static final String QUEUE_STATUS_ABNORMAL = "queue_status_abnormal";
|
||||
public static final String QUEUE_STATUS_NORMAL = "queue_status_normal";
|
||||
public static final String EXCHANGE_STATUS = "exchange_status";
|
||||
public static final String STATUS_ABNORMAL = "abnormal";
|
||||
public static final String STATUS_NORMAL = "normal";
|
||||
}
|
|
@ -10,4 +10,5 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
public class RedisConstants {
|
||||
public static final String VEHICLE_EVENT = "vehicle_event";
|
||||
public static final String VEHICLE_FAULT_KEY = "vehicle_fault_key:";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package com.muyu.eventdriven.consumer.redis;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.muyu.eventdriven.constants.RabbitConstants;
|
||||
import com.muyu.eventdriven.constants.RedisConstants;
|
||||
import com.muyu.eventdriven.domain.VehicleFaultStatus;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName RedisKeyExpirationListener
|
||||
* @Description redsi键过期监听类
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/21 上午11:27
|
||||
*/
|
||||
@Component
|
||||
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
super(listenerContainer);
|
||||
}
|
||||
|
||||
//拿到过期key的信息并做处理
|
||||
@Override
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
String key = message.toString();
|
||||
if (key.contains(RedisConstants.VEHICLE_FAULT_KEY)){
|
||||
String[] split = key.split(":");
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STATUS,RabbitConstants.STATUS_NORMAL, JSON.toJSONString(new VehicleFaultStatus(split[1],new Date().getTime(),split[2],"1")));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.muyu.eventdriven.controller;
|
||||
|
||||
import com.muyu.eventdriven.config.IotDBSessionConfig;
|
||||
import com.muyu.eventdriven.config.iotdb.IotDBSessionConfig;
|
||||
import com.muyu.eventdriven.model.param.IotDbParam;
|
||||
import com.muyu.eventdriven.response.ResponseData;
|
||||
import com.muyu.eventdriven.server.IotDbServer;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.muyu.eventdriven.domain;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.muyu.eventdriven.tactics.EventContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,25 +14,24 @@ import java.util.Map;
|
|||
*/
|
||||
@Component
|
||||
public class EventTacticsManage {
|
||||
private static Map<String, EventContext> eventContextMap = new HashMap<>();
|
||||
|
||||
public void initEventTacticsManage(){
|
||||
ArrayList<String> strings = new ArrayList<>();
|
||||
strings.add("com.muyu.eventdriven.tactics.basics.StorageEvent");
|
||||
strings.add("com.muyu.eventdriven.tactics.system.ElectronicFenceEvent");
|
||||
strings.add("com.muyu.eventdriven.tactics.system.FaultAlarmEvent");
|
||||
strings.add("com.muyu.eventdriven.tactics.system.RealTimeDataEvent");
|
||||
strings.add("com.muyu.eventdriven.tactics.system.IndexWarningEvent");
|
||||
for (int i = 1; i <= strings.size(); i++) {
|
||||
eventContextMap.put(String.valueOf(i),new EventContext(strings.get(i-1)));
|
||||
}
|
||||
}
|
||||
|
||||
public EventContext getEventContext(String key){
|
||||
return eventContextMap.get(key);
|
||||
}
|
||||
|
||||
public void setEventContext(String key,EventContext eventContext){
|
||||
eventContextMap.put(key,eventContext);
|
||||
}
|
||||
// public void initEventTacticsManage(){
|
||||
// ArrayList<String> strings = new ArrayList<>();
|
||||
// strings.add("com.muyu.eventdriven.tactics.basics.StorageEvent");
|
||||
// strings.add("com.muyu.eventdriven.tactics.system.ElectronicFenceEvent");
|
||||
// strings.add("com.muyu.eventdriven.tactics.system.FaultAlarmEvent");
|
||||
// strings.add("com.muyu.eventdriven.tactics.system.RealTimeDataEvent");
|
||||
// strings.add("com.muyu.eventdriven.tactics.system.IndexWarningEvent");
|
||||
// for (int i = 1; i <= strings.size(); i++) {
|
||||
// eventContextMap.put(String.valueOf(i),new EventContext(strings.get(i-1)));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public EventContext getEventContext(String key){
|
||||
// return eventContextMap.get(key);
|
||||
// }
|
||||
//
|
||||
// public void setEventContext(String key,EventContext eventContext){
|
||||
// eventContextMap.put(key,eventContext);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.eventdriven.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @ClassName VehicleFaultStatus
|
||||
* @Description 车辆状态报警类
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/21 上午11:46
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class VehicleFaultStatus {
|
||||
public String vin;
|
||||
public Long timestamp;
|
||||
public String faultCode;
|
||||
public String faultType;
|
||||
}
|
|
@ -1,28 +1,24 @@
|
|||
package com.muyu.eventdriven.server.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.muyu.eventdriven.constants.RedisConstants;
|
||||
import com.muyu.eventdriven.consumer.KafkaConsumers;
|
||||
import com.muyu.eventdriven.domain.EventTacticsManage;
|
||||
import com.muyu.eventdriven.domain.VehicleData;
|
||||
import com.muyu.eventdriven.domain.VehicleKafka;
|
||||
import com.muyu.eventdriven.domain.rest.Result;
|
||||
import com.muyu.eventdriven.mapper.EventDrivenMapper;
|
||||
import com.muyu.eventdriven.server.EventInfoService;
|
||||
import com.muyu.eventdriven.tactics.EventContext;
|
||||
import com.muyu.eventdriven.tactics.EventTactics;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -38,12 +34,21 @@ import java.util.concurrent.TimeUnit;
|
|||
public class EventInfoServiceImpl implements EventInfoService {
|
||||
private static Map<String,KafkaConsumer> kafkaConsumerMap = new HashMap<>();
|
||||
|
||||
private static List<String> classNameList = new ArrayList<>((Arrays.asList(
|
||||
"StorageEvent",
|
||||
"ElectronicFenceEvent",
|
||||
"FaultAlarmEvent",
|
||||
"RealTimeDataEvent",
|
||||
"IndexWarningEvent")));
|
||||
|
||||
@Autowired
|
||||
private KafkaConsumers kafkaConsumers;
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
@Autowired
|
||||
private EventTacticsManage eventTacticsManage;
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void creatKafkaConsumer(String vehicleVin) {
|
||||
|
@ -65,7 +70,7 @@ public class EventInfoServiceImpl implements EventInfoService {
|
|||
String vehicleEventString = "1,2,3,4,5";
|
||||
for (String str : vehicleEventString.split(",")) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
eventTacticsManage.getEventContext(str).eventManage(key,value);
|
||||
applicationContext.getBean(classNameList.get(Integer.parseInt(str)), EventTactics.class).eventManage(key,value);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package com.muyu.eventdriven.server.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.muyu.eventdriven.config.IotDBSessionConfig;
|
||||
import com.muyu.eventdriven.config.iotdb.IotDBSessionConfig;
|
||||
import com.muyu.eventdriven.domain.VehicleData;
|
||||
import com.muyu.eventdriven.model.param.IotDbParam;
|
||||
import com.muyu.eventdriven.model.result.IotDbResult;
|
||||
import com.muyu.eventdriven.server.IotDbServer;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||
|
@ -16,7 +15,6 @@ import org.apache.iotdb.tsfile.read.common.RowRecord;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.rmi.ServerException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.muyu.eventdriven.tactics;
|
||||
|
||||
import com.muyu.eventdriven.domain.VehicleData;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
/**
|
||||
* @ClassName EventContext
|
||||
* @Description 事件处理上下文
|
||||
* @Author Xin.Yao
|
||||
* @Date 2024/6/20 上午11:04
|
||||
*/
|
||||
public class EventContext {
|
||||
private EventTactics eventTactics;
|
||||
|
||||
|
||||
public EventContext(String className) {
|
||||
try {
|
||||
Class<?> aClass = Class.forName(className);
|
||||
this.eventTactics = (EventTactics) aClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void eventManage(String vin, List<VehicleData> vehicleDataList){
|
||||
eventTactics.eventManage(vin,vehicleDataList);
|
||||
}
|
||||
|
||||
public void eventManage(VehicleData vehicleData){
|
||||
eventTactics.eventManage(vehicleData);
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
|||
* @Author Xin.Yao
|
||||
* @Date 2024/6/20 上午10:38
|
||||
*/
|
||||
@Service
|
||||
@Service("StorageEvent")
|
||||
@Log4j2
|
||||
public class StorageEvent implements EventTactics {
|
||||
@Autowired
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.muyu.eventdriven.tactics.system;
|
||||
|
||||
import com.muyu.eventdriven.domain.VehicleData;
|
||||
import com.muyu.eventdriven.tactics.EventContext;
|
||||
import com.muyu.eventdriven.tactics.EventTactics;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -14,7 +13,7 @@ import java.util.List;
|
|||
* @Author Xin.Yao
|
||||
* @Date 2024/6/20 上午10:42
|
||||
*/
|
||||
@Service
|
||||
@Service("ElectronicFenceEvent")
|
||||
@Log4j2
|
||||
public class ElectronicFenceEvent implements EventTactics {
|
||||
/**
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
package com.muyu.eventdriven.tactics.system;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.muyu.eventdriven.constants.FaultCodeConstants;
|
||||
import com.muyu.eventdriven.constants.RabbitConstants;
|
||||
import com.muyu.eventdriven.constants.RedisConstants;
|
||||
import com.muyu.eventdriven.domain.VehicleData;
|
||||
import com.muyu.eventdriven.domain.VehicleFaultStatus;
|
||||
import com.muyu.eventdriven.tactics.EventTactics;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ClassName FaultAlarmEvent
|
||||
|
@ -13,9 +25,20 @@ import java.util.List;
|
|||
* @Author Xin.Yao
|
||||
* @Date 2024/6/20 上午10:58
|
||||
*/
|
||||
@Service
|
||||
@Service("FaultAlarmEvent")
|
||||
@Log4j2
|
||||
//@RequiredArgsConstructor
|
||||
public class FaultAlarmEvent implements EventTactics {
|
||||
@Autowired
|
||||
private Cache<String, Object> caffeineCache;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public void eventManage(VehicleData vehicleData) {
|
||||
log.info("车辆{}执行故障报警事件",vehicleData.getVin());
|
||||
|
@ -23,6 +46,85 @@ public class FaultAlarmEvent implements EventTactics {
|
|||
|
||||
@Override
|
||||
public void eventManage(String vin, List<VehicleData> vehicleDataList) {
|
||||
vehicleDataList.stream().forEach(vehicleData -> {
|
||||
//车辆状态
|
||||
if (vehicleData.getVehicleStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.VEHICLESTATUS);
|
||||
}
|
||||
//充电状态
|
||||
if (vehicleData.getChargingStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.CHARGINGSTATUS);
|
||||
}
|
||||
//运行状态
|
||||
if (vehicleData.getOperatingStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.OPERATINGSTATUS);
|
||||
}
|
||||
//SOC
|
||||
if (vehicleData.getSocStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.SOCSTATUS);
|
||||
}
|
||||
//可充电储能装置工作状态
|
||||
if (vehicleData.getChargingEnergyStorageStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.CHARGINGENERGYSTORAGESTATUS);
|
||||
}
|
||||
//驱动电机状态
|
||||
if (vehicleData.getDriveMotorStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.DRIVEMOTORSTATUS);
|
||||
}
|
||||
//定位是否有效
|
||||
if (vehicleData.getPositionStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.POSITIONSTATUS);
|
||||
}
|
||||
//EAS(汽车防盗系统)状态
|
||||
if (vehicleData.getEasStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.EASSTATUS);
|
||||
}
|
||||
//PTC(电动加热器)状态
|
||||
if (vehicleData.getPtcStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.PTCSTATUS);
|
||||
}
|
||||
//EPS(电动助力系统)状态
|
||||
if (vehicleData.getEpsStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.EPSSTATUS);
|
||||
}
|
||||
//ABS(防抱死)状态
|
||||
if (vehicleData.getAbsStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.ABSSTATUS);
|
||||
}
|
||||
//MCU(电机/逆变器)状态
|
||||
if (vehicleData.getMcuStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.MCUSTATUS);
|
||||
}
|
||||
//动力电池加热状态
|
||||
if (vehicleData.getHeatingStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.HEATINGSTATUS);
|
||||
}
|
||||
//动力电池当前状态
|
||||
if (vehicleData.getBatteryStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.BATTERYSTATUS);
|
||||
}
|
||||
//动力电池保温状态
|
||||
if (vehicleData.getBatteryInsulationStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.BATTERYINSULATIONSTATUS);
|
||||
}
|
||||
//DCDC(电力交换系统)状态
|
||||
if (vehicleData.getDcdcStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.DCDCSTATUS);
|
||||
}
|
||||
//CHG(充电机)状态
|
||||
if (vehicleData.getChgStatus() == 0){
|
||||
hasLocalCache(vehicleData, FaultCodeConstants.CHGSTATUS);
|
||||
}
|
||||
|
||||
});
|
||||
log.info("车辆{}执行故障报警事件",vin);
|
||||
}
|
||||
|
||||
public void hasLocalCache(VehicleData vehicleData,String faultCode){
|
||||
Object o = caffeineCache.get(RedisConstants.VEHICLE_FAULT_KEY+vehicleData.getVin()+":" + faultCode, key -> vehicleData.getDrivingRoute());
|
||||
if (o.toString().equals(vehicleData.getDrivingRoute())){
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.EXCHANGE_STATUS,RabbitConstants.STATUS_ABNORMAL, JSON.toJSONString(new VehicleFaultStatus(vehicleData.getVin(),new Date().getTime(),faultCode,"0")));
|
||||
}
|
||||
redisTemplate.opsForValue().set(RedisConstants.VEHICLE_FAULT_KEY+vehicleData.getVin()+":" + faultCode,vehicleData.getDrivingRoute(),10, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
* @Author Xin.Yao
|
||||
* @Date 2024/6/20 上午11:00
|
||||
*/
|
||||
@Service
|
||||
@Service("IndexWarningEvent")
|
||||
@Log4j2
|
||||
public class IndexWarningEvent implements EventTactics {
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
* @Author Xin.Yao
|
||||
* @Date 2024/6/20 上午10:47
|
||||
*/
|
||||
@Service
|
||||
@Service("RealTimeDataEvent")
|
||||
@Log4j2
|
||||
public class RealTimeDataEvent implements EventTactics {
|
||||
@Autowired
|
||||
|
|
|
@ -1 +1 @@
|
|||
com.muyu.eventdriven.config.EventDrivenConfig
|
||||
|
||||
|
|
|
@ -2,6 +2,12 @@ server:
|
|||
port: 9006
|
||||
|
||||
spring:
|
||||
rabbitmq:
|
||||
username: guest
|
||||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 47.99.219.99
|
||||
kafka:
|
||||
#config/consumer.properties配置的bootstrap.servers
|
||||
bootstrap-servers: 47.98.170.220:9092
|
||||
|
@ -14,9 +20,9 @@ spring:
|
|||
#这个可以和config/consumer.properties里的group.id不同
|
||||
group-id: test-consumer-group
|
||||
redis:
|
||||
host: gu
|
||||
host: 47.99.219.99
|
||||
port: 6379
|
||||
password:
|
||||
password: yx@123
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/event-driven?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
|
|
Loading…
Reference in New Issue