feat(): 新增车辆上线消费者和识别故障监听器

dev.entOperation
xinzirun 2024-10-07 09:02:38 +08:00
parent ca8bd65148
commit a1894bb013
4 changed files with 147 additions and 0 deletions

View File

@ -1,2 +1,9 @@
com.muyu.enterprise.cache.CarCompanyCacheService
com.muyu.enterprise.cache.CarFaultCacheService
com.muyu.enterprise.cache.CarManageCacheService 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

View File

@ -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";
}

View File

@ -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));
}});
}
}

View File

@ -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);
}
}