feat 故障报警

master
rouchen 2024-06-20 22:42:26 +08:00
parent d0da430ffc
commit c44046d4ac
23 changed files with 253 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,20 @@
package com.muyu.errorAlarm.controller;
import com.muyu.errorAlarm.service.ErrorAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* ErrorAlarmController
*
* @author Yangle
* Date 2024/6/20 11:25
*/
@RestController
public class ErrorAlarmController {
@Autowired
private ErrorAlarmService errorAlarmService;
}

View File

@ -0,0 +1,10 @@
package com.muyu.errorAlarm.service;
/**
* errorAlarmService
*
* @author Yangle
* Date 2024/6/20 11:26
*/
public interface ErrorAlarmService {
}

View File

@ -0,0 +1,15 @@
package com.muyu.errorAlarm.service.impl;
import com.muyu.errorAlarm.service.ErrorAlarmService;
import org.springframework.stereotype.Service;
/**
* ErrorAlarmServiceImpl
*
* @author Yangle
* Date 2024/6/20 11:26
*/
@Service
public class ErrorAlarmServiceImpl implements ErrorAlarmService {
}

View File

@ -0,0 +1,32 @@
package com.muyu.event;
import com.muyu.event.common.VehicleEvent;
import com.muyu.event.service.EventService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.List;
/**
* EventRunner
*
* @author Yangle
* Date 2024/6/20 16:47
*/
@Component
public class EventRunner implements Runnable {
@Autowired
private EventService eventService;
@PostConstruct
public void run() {
List<VehicleEvent> vehicleEvents = eventService.selectVehicleEvent();
vehicleEvents.forEach(
vehicleEvent -> {
eventService.selectEvent(vehicleEvent);
}
);
}
}

View File

@ -0,0 +1,31 @@
//package com.muyu.event;
//
//import com.muyu.kafka.SimpleKafkaConsumer;
//import lombok.extern.log4j.Log4j2;
//import org.checkerframework.checker.units.qual.C;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.stereotype.Component;
//
///**
// * kafka消费者启动类 KafkaRunner
// *
// * @author Yangle
// * Date 2024/6/20 21:42
// */
//@Component
//@Log4j2
//public class KafkaRunner implements ApplicationRunner {
//
// @Override
// public void run(ApplicationArguments args) throws Exception {
// try {
// log.info("项目启动开始动态启动kafka消费者");
//
// }catch (Exception e){
// log.error("启动kafka消费者失败异常信息:{}",e);
// }
//
// }
//
//}

View File

@ -0,0 +1,145 @@
//package com.muyu.event.util;
//
//import com.muyu.iotDB.config.IotDBSessionConfig;
//import com.muyu.iotDB.service.IotDbServer;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cache.CacheManager;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.Resource;
//import java.util.LinkedHashMap;
//
//@Slf4j
//@Service
//public class KafkaConsumer {
// LinkedHashMap<String, EventStrategy> eventStrategyLinkedHashMap = new LinkedHashMap<>();
// @Autowired
// private CacheManager cacheManager;
//
// @Autowired
// private CarEventService carEventService;
//
// @Autowired
// private RedisTemplate<String,String> redisTemplate;
// @Resource
// private IotDbServer iotDbServer;
// @Resource
// private IotDBSessionConfig iotDBSessionConfig;
//
// @PostConstruct
// public void initStrategyMap(){
// eventStrategyLinkedHashMap.put("ELECTRONIC_FENCE",EventStrategy.ELECTRONIC_FENCE);
// eventStrategyLinkedHashMap.put("FAULT_ALARM",EventStrategy.FAULT_ALARM);
// eventStrategyLinkedHashMap.put("INDEX_WARNING",EventStrategy.INDEX_WARNING);
// eventStrategyLinkedHashMap.put("REAL_TIME_DATA",EventStrategy.REAL_TIME_DATA);
// }
// @KafkaListener(topics = "topichyc", groupId = "firstGroup", containerFactory = "kafkaListenerContainerFactory",
// errorHandler = "myKafkaListenerErrorHandler")
// public void consume(List<ConsumerRecord<Object,Object>> consumerRecords, Acknowledgment acknowledgment) {
// try {
// //策略map集合
//// LinkedHashMap<String, Strategy> stringStrategyLinkedHashMap = new LinkedHashMap<>();
//// stringStrategyLinkedHashMap.put("存储数据", Strategy.STORE_DATA);
//// stringStrategyLinkedHashMap.put("实时数据",Strategy.REAL_TIME_DATA);
//
// log.info("拉取到的记录数是:{}",consumerRecords.size());
// for (ConsumerRecord<Object, Object> consumerRecord : consumerRecords) {
// String value = (String) consumerRecord.value();
//
// VehicleData vehicleData = JSONObject.parseObject(value, VehicleData.class);
// log.error("消费者0得到的数据:{},所在分区:{}",vehicleData.toString(),consumerRecord.partition());
//
// iotDbServer.insertData(vehicleData);
// //得到小车绑定信息
// String carEventByVin = this.getCarEventByVin(vehicleData.getVin());
// //解析绑定的信息
// String[] eventArr = carEventByVin.split(",");
// for (String eventString : eventArr) {
// //处理事件
// eventStrategyLinkedHashMap.get(eventString).exe(cacheManager,redisTemplate,vehicleData);
// }
// }
// //解析得到VIN
//
//
//
//// String dataMessage = value.toString();
//// JSONObject jsonObject = JSON.parseObject(dataMessage);
//// //根据VIN得到该小车拥有的事件
//// String vin = jsonObject.get("vin").toString();
//// List<String> eventList = getEvent(vin);
//// //循环事件集合,并执行响应的事件
//// for (String event : eventList) {
//// stringStrategyLinkedHashMap.get(event).exe(redisTemplate,dataMessage);
//// }
//
// } catch (ServerException e) {
// log.error("添加iotDb异常");
// throw new RuntimeException(e);
// } catch (IoTDBConnectionException e) {
// throw new RuntimeException(e);
// } catch (StatementExecutionException e) {
// throw new RuntimeException(e);
// } finally {
// acknowledgment.acknowledge();
// }
// }
//
// public List<String> getEvent(String vin){
// ArrayList<String> strings = new ArrayList<>();
//
// strings.add("存储数据");
// int nextInt = new Random().nextInt(100);
// if (nextInt % 2 ==0){
// strings.add("实时数据");
// }
// return strings;
// }
//
// public String getCarEventByVin(String vin){
//
//
// // 先从本地缓存获取
// Cache cache = cacheManager.getCache("carEvent");
// Cache.ValueWrapper valueWrapper = cache.get(vin);
// if (valueWrapper != null) {
// return valueWrapper.get().toString();
// }
//
// // 从 Redis 获取
//
// String carEventString = redisTemplate.opsForValue().get(vin);
// if (carEventString != null) {
// // 将数据同步到本地缓存
// cache.put(vin, carEventString);
// return carEventString;
// }
//
// // 从 MySQL 获取
// CacheCarEvent cacheCarEvent = carEventService.getCarEvent(vin);
// if (cacheCarEvent != null) {
// // 将数据存入 Redis 和本地缓存
// redisTemplate.opsForValue().set(vin, cacheCarEvent.getEventValue());
// cache.put(vin, cacheCarEvent.getEventValue());
// }
//
// return cacheCarEvent.getEventValue();
//
// }
//
// public void updateValueWithoutChangingTTL(String key, String newValue) {
// // 获取当前的过期时间
// Long currentTTL = redisTemplate.getExpire(key, TimeUnit.SECONDS);
//
// // 更新键的值
// redisTemplate.opsForList().rightPush( key,newValue);
//
// // 重新设置过期时间
// if (currentTTL != null && currentTTL > 0) {
// redisTemplate.expire(key, currentTTL, TimeUnit.SECONDS);
// }
// }
//}