From a1894bb013389e9b4bf2fec8c559f51bd01b86d0 Mon Sep 17 00:00:00 2001 From: xinzirun Date: Mon, 7 Oct 2024 09:02:38 +0800 Subject: [PATCH] =?UTF-8?q?feat():=20=E6=96=B0=E5=A2=9E=E8=BD=A6=E8=BE=86?= =?UTF-8?q?=E4=B8=8A=E7=BA=BF=E6=B6=88=E8=B4=B9=E8=80=85=E5=92=8C=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E6=95=85=E9=9A=9C=E7=9B=91=E5=90=AC=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ot.autoconfigure.AutoConfiguration.imports | 7 ++ .../constant/CacheHandlerConstants.java | 29 ++++++++ .../process/consumer/GoOnlineConsumer.java | 73 +++++++++++++++++++ .../IdentifyingFailuresEventListener.java | 38 ++++++++++ 4 files changed, 147 insertions(+) create mode 100644 cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/constant/CacheHandlerConstants.java create mode 100644 cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/consumer/GoOnlineConsumer.java create mode 100644 cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/listener/IdentifyingFailuresEventListener.java diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 74d44ab..d0243d7 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,2 +1,9 @@ +com.muyu.enterprise.cache.CarCompanyCacheService +com.muyu.enterprise.cache.CarFaultCacheService com.muyu.enterprise.cache.CarManageCacheService +com.muyu.enterprise.cache.CarMessageCacheService +com.muyu.enterprise.cache.CarTemplateCacheService +com.muyu.enterprise.cache.CarWarnCacheService +com.muyu.enterprise.cache.ElectronicFenceCacheService + diff --git a/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/constant/CacheHandlerConstants.java b/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/constant/CacheHandlerConstants.java new file mode 100644 index 0000000..4ded5df --- /dev/null +++ b/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/constant/CacheHandlerConstants.java @@ -0,0 +1,29 @@ +package com.muyu.event.process.constant; + +/** + * @Author: zi run + * @Date 2024/10/6 14:39 + * @Description 缓存处理常量存放 + */ +public class CacheHandlerConstants { + + /** + * 车辆管理缓存标识 + */ + public static final String CAR_MANAGE_KEY = "carManage"; + + /** + * 故障规则缓存标识 + */ + public static final String FAULT_RULE_KEY = "faultRule"; + + /** + * 电子围栏缓存标识 + */ + public static final String ELECTRONIC_FENCE_KEY = "electronicFence"; + + /** + * 预警规则缓存标识 + */ + public static final String WARN_RULE_KEY = "warnRule"; +} diff --git a/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/consumer/GoOnlineConsumer.java b/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/consumer/GoOnlineConsumer.java new file mode 100644 index 0000000..f5fc581 --- /dev/null +++ b/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/consumer/GoOnlineConsumer.java @@ -0,0 +1,73 @@ +package com.muyu.event.process.consumer; + +import com.muyu.enterprise.cache.CarFaultCacheService; +import com.muyu.enterprise.cache.CarManageCacheService; +import com.muyu.enterprise.cache.CarWarnCacheService; +import com.muyu.enterprise.cache.ElectronicFenceCacheService; +import com.muyu.event.process.constant.CacheHandlerConstants; +import com.muyu.event.process.util.CacheUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.annotation.Exchange; +import org.springframework.amqp.rabbit.annotation.Queue; +import org.springframework.amqp.rabbit.annotation.QueueBinding; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.HashMap; + +/** + * @Author: zi run + * @Date 2024/10/6 10:01 + * @Description 商量上线消费者 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class GoOnlineConsumer { + + /** + * 存储通用类型数据缓存工具 + */ + private final CacheUtil cacheUtil; + + /** + * 车辆管理缓存服务 + */ + private final CarManageCacheService carManageCacheService; + + /** + * 车辆故障缓存服务 + */ + private final CarFaultCacheService carFaultCacheService; + + /** + * 车辆电子围栏缓存服务 + */ + private final ElectronicFenceCacheService electronicFenceCacheService; + + /** + * 车辆预警缓存服务 + */ + private final CarWarnCacheService carWarnCacheService; + + /** + * 处理车辆上线事件 + * @param vin 车辆的识别码,根据识别码从缓存中存入对应的数据 + */ + @RabbitListener( + bindings = @QueueBinding( + value = @Queue(value = "GO_ONLINE", durable = "true"), + exchange = @Exchange(value = "ONLINE_EXCHANGE", type = "fanout") + ) + ) + public void online(String vin) { + log.info("车辆vin码:{},该车辆已上线", vin); + cacheUtil.put(vin, new HashMap() {{ + put(CacheHandlerConstants.CAR_MANAGE_KEY, carManageCacheService.get(vin)); + put(CacheHandlerConstants.FAULT_RULE_KEY, carFaultCacheService.get(vin)); + put(CacheHandlerConstants.ELECTRONIC_FENCE_KEY, electronicFenceCacheService.get(vin)); + put(CacheHandlerConstants.WARN_RULE_KEY, carWarnCacheService.get(vin)); + }}); + } +} diff --git a/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/listener/IdentifyingFailuresEventListener.java b/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/listener/IdentifyingFailuresEventListener.java new file mode 100644 index 0000000..cadaa16 --- /dev/null +++ b/cloud-modules/cloud-modules-event-process/src/main/java/com/muyu/event/process/listener/IdentifyingFailuresEventListener.java @@ -0,0 +1,38 @@ +package com.muyu.event.process.listener; + +import com.alibaba.fastjson2.JSONObject; +import com.muyu.enterprise.domain.FaultRule; +import com.muyu.event.process.basic.BasicEvent; +import com.muyu.event.process.basic.BasicEventListener; +import com.muyu.event.process.constant.CacheHandlerConstants; +import com.muyu.event.process.util.CacheUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @Author: zi run + * @Date 2024/10/6 14:28 + * @Description 识别故障事件监听器 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class IdentifyingFailuresEventListener implements BasicEventListener { + + /** + * 本地缓存工具 + */ + private final CacheUtil cacheUtil; + + @Override + public void onEvent(BasicEvent event) { + log.info("触发识别故障时间监听器……"); + JSONObject data = JSONObject.parseObject(event.getData()); + Map dataMap = (Map) cacheUtil.get((String) data.get("vin")); + FaultRule faultRule = (FaultRule) dataMap.get(CacheHandlerConstants.FAULT_RULE_KEY); + + } +}