Compare commits
4 Commits
3378b4c216
...
a1894bb013
Author | SHA1 | Date |
---|---|---|
|
a1894bb013 | |
|
ca8bd65148 | |
|
a0c2d916f2 | |
|
8888b7430c |
|
@ -1,8 +1,8 @@
|
|||
package com.muyu.enterprise.cache;
|
||||
|
||||
import com.muyu.common.cache.config.CacheAbsBasic;
|
||||
import com.muyu.enterprise.domain.CarCompany;
|
||||
import com.muyu.enterprise.domain.FaultType;
|
||||
import com.muyu.enterprise.domain.FaultRule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* redis故障业务层
|
||||
|
@ -11,17 +11,16 @@ import com.muyu.enterprise.domain.FaultType;
|
|||
* @Date 2024/10/3 15:22
|
||||
* @author MingWei.Zong
|
||||
*/
|
||||
|
||||
public class CarFaultCacheService extends CacheAbsBasic<String, FaultType> {
|
||||
public class CarFaultCacheService extends CacheAbsBasic<String, FaultRule> {
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "faultType:info:";
|
||||
return "faultRule:info:";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace("faultType:info:","");
|
||||
return key.replace("faultRule:info:","");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import lombok.experimental.SuperBuilder;
|
|||
@TableName(value = "fault_rule",autoResultMap = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Tag(name = "故障规则")
|
||||
public class FaultrRule extends BaseEntity {
|
||||
public class FaultRule extends BaseEntity {
|
||||
/**
|
||||
* 故障规则ID
|
||||
*/
|
|
@ -2,7 +2,7 @@ package com.muyu.enterprise.controller;
|
|||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.enterprise.domain.FaultrRule;
|
||||
import com.muyu.enterprise.domain.FaultRule;
|
||||
import com.muyu.enterprise.service.FaultrRuleService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -26,9 +26,9 @@ public class FaultrRuleController {
|
|||
* 查询车辆故障列表
|
||||
*/
|
||||
@RequestMapping(value = "/faultRuleList", method = RequestMethod.GET)
|
||||
public Result<List<FaultrRule>> faultRuleList(FaultrRule faultrRule)
|
||||
public Result<List<FaultRule>> faultRuleList(FaultRule faultrRule)
|
||||
{
|
||||
List<FaultrRule> list = faultrRuleService.faultRuleList(faultrRule);
|
||||
List<FaultRule> list = faultrRuleService.faultRuleList(faultrRule);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class FaultrRuleController {
|
|||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/insertRule",method = RequestMethod.POST)
|
||||
public Result insertRule(@RequestBody FaultrRule faultrRule){
|
||||
public Result insertRule(@RequestBody FaultRule faultrRule){
|
||||
return Result.success(faultrRuleService.save(faultrRule));
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class FaultrRuleController {
|
|||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/updateRule",method = RequestMethod.POST)
|
||||
public Result updateRule(@RequestBody FaultrRule faultrRule){
|
||||
public Result updateRule(@RequestBody FaultRule faultrRule){
|
||||
return Result.success(faultrRuleService.updateById(faultrRule));
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class FaultrRuleController {
|
|||
*/
|
||||
@RequestMapping(value = "/byidRuleId/{faultRuleId}",method = RequestMethod.GET)
|
||||
public Result byidRuleId(@PathVariable Long faultRuleId){
|
||||
FaultrRule byid = faultrRuleService.byidRuleId(faultRuleId);
|
||||
FaultRule byid = faultrRuleService.byidRuleId(faultRuleId);
|
||||
return Result.success(byid);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.muyu.enterprise.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.enterprise.domain.FaultrRule;
|
||||
import com.muyu.enterprise.domain.FaultRule;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
|
@ -11,5 +11,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* @Description FaultrRuleMapper:故障规则持久层
|
||||
*/
|
||||
@Mapper
|
||||
public interface FaultrRuleMapper extends BaseMapper<FaultrRule> {
|
||||
public interface FaultrRuleMapper extends BaseMapper<FaultRule> {
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.muyu.enterprise.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.enterprise.domain.FaultrRule;
|
||||
import com.muyu.enterprise.domain.FaultRule;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
|
@ -10,8 +10,8 @@ import java.util.List;
|
|||
* @Date 2024/9/28 12.19
|
||||
* @Description FaultrRuleService:故障规则业务层
|
||||
*/
|
||||
public interface FaultrRuleService extends IService<FaultrRule> {
|
||||
List<FaultrRule> faultRuleList(FaultrRule faultrRule);
|
||||
public interface FaultrRuleService extends IService<FaultRule> {
|
||||
List<FaultRule> faultRuleList(FaultRule faultrRule);
|
||||
|
||||
FaultrRule byidRuleId(Long faultRuleId);
|
||||
FaultRule byidRuleId(Long faultRuleId);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.muyu.enterprise.service.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.enterprise.domain.FaultrRule;
|
||||
import com.muyu.enterprise.domain.FaultRule;
|
||||
import com.muyu.enterprise.mapper.FaultrRuleMapper;
|
||||
import com.muyu.enterprise.service.FaultrRuleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -17,25 +17,25 @@ import java.util.List;
|
|||
* @Description FaultrRuleServiceImpl:故障规则业务实现层
|
||||
*/
|
||||
@Service
|
||||
public class FaultrRuleServiceImpl extends ServiceImpl<FaultrRuleMapper, FaultrRule> implements FaultrRuleService {
|
||||
public class FaultrRuleServiceImpl extends ServiceImpl<FaultrRuleMapper, FaultRule> implements FaultrRuleService {
|
||||
|
||||
@Override
|
||||
public List<FaultrRule> faultRuleList(FaultrRule faultrRule) {
|
||||
LambdaQueryWrapper<FaultrRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
public List<FaultRule> faultRuleList(FaultRule faultrRule) {
|
||||
LambdaQueryWrapper<FaultRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(faultrRule.getFaultRuleName())) {
|
||||
queryWrapper.eq(FaultrRule::getFaultRuleName,faultrRule.getFaultRuleName());
|
||||
queryWrapper.eq(FaultRule::getFaultRuleName,faultrRule.getFaultRuleName());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(faultrRule.getFaultRuleParameter())) {
|
||||
queryWrapper.eq(FaultrRule::getFaultRuleParameter,faultrRule.getFaultRuleParameter());
|
||||
queryWrapper.eq(FaultRule::getFaultRuleParameter,faultrRule.getFaultRuleParameter());
|
||||
}
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FaultrRule byidRuleId(Long faultRuleId) {
|
||||
LambdaQueryWrapper<FaultrRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
public FaultRule byidRuleId(Long faultRuleId) {
|
||||
LambdaQueryWrapper<FaultRule> queryWrapper = new LambdaQueryWrapper<>();
|
||||
Assert.notNull(faultRuleId, "规则ID不可为空");
|
||||
queryWrapper.eq(FaultrRule::getFaultRuleId, faultRuleId);
|
||||
queryWrapper.eq(FaultRule::getFaultRuleId, faultRuleId);
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,5 +93,11 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 企业缓存模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -3,6 +3,8 @@ package com.muyu.event.process.basic;
|
|||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: zi run
|
||||
* @Date 2024/9/30 15:37
|
||||
|
@ -12,17 +14,17 @@ import org.springframework.stereotype.Component;
|
|||
public class BasicEventHandler<T> implements ApplicationListener<BasicEvent<T>> {
|
||||
|
||||
/**
|
||||
* 具体事件监听器
|
||||
* 具体事件监听器列表
|
||||
*/
|
||||
private final BasicEventListener<T> listener;
|
||||
private final List<BasicEventListener<T>> listeners;
|
||||
|
||||
/**
|
||||
* 构造函数,用于注入具体事件监听器
|
||||
*
|
||||
* @param listener 具体事件监听器
|
||||
* @param listeners 具体事件监听器列表
|
||||
*/
|
||||
public BasicEventHandler(BasicEventListener<T> listener) {
|
||||
this.listener = listener;
|
||||
public BasicEventHandler(List<BasicEventListener<T>> listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,6 +34,6 @@ public class BasicEventHandler<T> implements ApplicationListener<BasicEvent<T>>
|
|||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(BasicEvent<T> event) {
|
||||
listener.onEvent(event);
|
||||
listeners.forEach(l -> l.onEvent(event));
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
|
@ -7,6 +7,7 @@ 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.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: zi run
|
||||
|
@ -14,11 +15,12 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|||
* @Description 车辆下线消费者
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class GoOfflineConsumer {
|
||||
|
||||
/**
|
||||
* 缓存工具
|
||||
* 存储字符串类型数据缓存工具
|
||||
*/
|
||||
private final CacheUtil<String> cacheUtil;
|
||||
|
||||
|
@ -34,7 +36,7 @@ public class GoOfflineConsumer {
|
|||
)
|
||||
)
|
||||
public void offline(String vin) {
|
||||
log.info("清除缓存,车辆vin: {}", vin);
|
||||
log.info("车辆vin码:{},该车辆已下线", vin);
|
||||
cacheUtil.remove(vin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}});
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package com.muyu.event.process.consumer;
|
|||
|
||||
import com.muyu.common.core.constant.KafkaConstants;
|
||||
import com.muyu.event.process.basic.EventPublisher;
|
||||
import com.muyu.event.process.event.IoTDBInsertDataEvent;
|
||||
import com.muyu.event.process.event.DataProcessEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
|
@ -73,7 +73,7 @@ public class VehicleConsumer implements ApplicationRunner, ApplicationListener<C
|
|||
String message = consumerRecord.value();
|
||||
log.info("接收到车辆报文数据,内容:{}", message);
|
||||
log.info("------------------------------------------------");
|
||||
eventPublisher.publish(new IoTDBInsertDataEvent(this, message));
|
||||
eventPublisher.publish(new DataProcessEvent(this, message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,16 +5,16 @@ import com.muyu.event.process.basic.BasicEvent;
|
|||
/**
|
||||
* @Author: zi run
|
||||
* @Date 2024/9/29 21:19
|
||||
* @Description 向IoTDB插入数据事件
|
||||
* @Description 数据处理事件
|
||||
*/
|
||||
public class IoTDBInsertDataEvent extends BasicEvent<String> {
|
||||
public class DataProcessEvent extends BasicEvent<String> {
|
||||
|
||||
/**
|
||||
* 构造函数,向IoTDB插入数据创建事件
|
||||
* 构造函数,数据处理创建事件
|
||||
*
|
||||
* @param messsge 消息
|
||||
*/
|
||||
public IoTDBInsertDataEvent(Object source, String messsge) {
|
||||
public DataProcessEvent(Object source, String messsge) {
|
||||
super(source, messsge);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
|
@ -5,6 +5,10 @@ import com.muyu.event.process.basic.BasicEvent;
|
|||
import com.muyu.event.process.basic.BasicEventListener;
|
||||
import com.muyu.event.process.iotdb.service.IoTDBService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,9 +19,10 @@ import java.util.stream.Collectors;
|
|||
* @Date 2024/9/29 22:12
|
||||
* @Description 向IoTDB插入数据事件监听器
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class IoTDBInsertDataListener implements BasicEventListener<String> {
|
||||
public class IoTDBInsertDataEventListener implements BasicEventListener<String> {
|
||||
|
||||
/**
|
||||
* IoTDB业务层
|
||||
|
@ -36,6 +41,7 @@ public class IoTDBInsertDataListener implements BasicEventListener<String> {
|
|||
*/
|
||||
@Override
|
||||
public void onEvent(BasicEvent<String> event) {
|
||||
log.info("触发向IoTDB插入数据事件监听器……");
|
||||
JSONObject data = JSONObject.parseObject(event.getData());
|
||||
List<String> keyList = extractKeys(data);
|
||||
List<String> valueList = extractValues(data);
|
Loading…
Reference in New Issue