feat(): 新增车辆上线消费者和识别故障监听器
parent
ca8bd65148
commit
a1894bb013
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
|
@ -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<Object> 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<String, Object>() {{
|
||||
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));
|
||||
}});
|
||||
}
|
||||
}
|
|
@ -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<String> {
|
||||
|
||||
/**
|
||||
* 本地缓存工具
|
||||
*/
|
||||
private final CacheUtil<Object> cacheUtil;
|
||||
|
||||
@Override
|
||||
public void onEvent(BasicEvent<String> event) {
|
||||
log.info("触发识别故障时间监听器……");
|
||||
JSONObject data = JSONObject.parseObject(event.getData());
|
||||
Map<String, Object> dataMap = (Map<String, Object>) cacheUtil.get((String) data.get("vin"));
|
||||
FaultRule faultRule = (FaultRule) dataMap.get(CacheHandlerConstants.FAULT_RULE_KEY);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue