优化车辆上线时的故障码缓存逻辑
- 修改CarOnlineConsumer类,实现车辆上线时从VehicleCacheFaultCodeAddService获取故障码缓存并存入本地缓存 - 新增IdentifyingFailuresListener类,用于监听ES保存事件,根据车辆VIN查询并处理故障码 - 调整IotDBController类,注释掉未使用的批量插入记录方法 - 更新相关依赖配置,引入cloud-modules-enterprise-cache等依赖dev.carData
parent
fe70b7d3c1
commit
c42adb48cc
|
@ -29,3 +29,4 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -58,12 +58,6 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
<!-- 接口模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-electronic-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
|
|
|
@ -86,12 +86,6 @@
|
|||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-car</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package com.muyu.carData.consumer;
|
||||
|
||||
import com.muyu.carData.util.CacheUtil;
|
||||
import com.muyu.domain.FaultCodeCache;
|
||||
import com.muyu.enterprise.cache.car.VehicleCacheCarInformationAddService;
|
||||
import com.muyu.enterprise.cache.car.VehicleCacheCarInformationFenceRespService;
|
||||
import com.muyu.enterprise.cache.faultCode.VehicleCacheFaultCodeAddService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
|
@ -23,11 +27,20 @@ public class CarOnlineConsumer {
|
|||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
@Autowired
|
||||
private VehicleCacheFaultCodeAddService vehicleCacheCarInformationAddService;
|
||||
|
||||
|
||||
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(value = "CAR_ONLINE",durable = "true"),
|
||||
exchange = @Exchange(value = "ONLINE_EXCHANGE",type = "fanout")
|
||||
))
|
||||
public void online(String vin){
|
||||
log.info("车辆vin:{},已上线,开始消费",vin);
|
||||
FaultCodeCache faultCodeCache = vehicleCacheCarInformationAddService
|
||||
.get(vehicleCacheCarInformationAddService.keyPre()+vin);
|
||||
cacheUtil.put(vin,faultCodeCache);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/*
|
||||
package com.muyu.carData.controller;
|
||||
|
||||
import com.muyu.carData.config.lotdbconfig.IotDBSessionConfig;
|
||||
|
@ -17,13 +18,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
*/
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.testcontroller
|
||||
* @Project:cloud-server-8
|
||||
* @name:IotDBController
|
||||
* @Date:2024/9/28 23:58
|
||||
*/
|
||||
*//*
|
||||
|
||||
@RequestMapping("/iotdb")
|
||||
@RestController
|
||||
@Log4j2
|
||||
|
@ -33,6 +36,7 @@ public class IotDBController {
|
|||
@Autowired
|
||||
private IotDBSessionConfig iotDBSessionConfig;
|
||||
|
||||
*/
|
||||
/**
|
||||
* 批量插入数据
|
||||
* @param insertSize 每次插入的条数
|
||||
|
@ -40,7 +44,8 @@ public class IotDBController {
|
|||
* @return
|
||||
* @throws IoTDBConnectionException
|
||||
* @throws StatementExecutionException
|
||||
*/
|
||||
*//*
|
||||
|
||||
@GetMapping("/insertData/{insertSize}/{count}")
|
||||
public String insert(@PathVariable(name = "insertSize") int insertSize,@PathVariable(name = "count") int count) throws IoTDBConnectionException, StatementExecutionException {
|
||||
Session session = iotDBSessionConfig.iotSession();
|
||||
|
@ -82,7 +87,7 @@ public class IotDBController {
|
|||
}
|
||||
|
||||
|
||||
/* @GetMapping("/batchInsertRecords/{num}")
|
||||
@GetMapping("/batchInsertRecords/{num}")
|
||||
public String batchInsertRecords(@PathVariable Integer num){
|
||||
String deviceId = "root.yang";
|
||||
|
||||
|
@ -109,5 +114,6 @@ public class IotDBController {
|
|||
for (int i = 0; i < num; i++) {
|
||||
deviceIds.add()
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.muyu.carData.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.carData.event.EsSaveEvent;
|
||||
import com.muyu.carData.event.EventListener;
|
||||
import com.muyu.carData.util.CacheUtil;
|
||||
import com.muyu.domain.FaultCodeCache;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 判断故障信息
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.carData.listener
|
||||
* @Project:cloud-server-8
|
||||
* @name:IdentifyingFailuresListener
|
||||
* @Date:2024/10/8 11:22
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class IdentifyingFailuresListener implements EventListener {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
@Override
|
||||
public void onEvent(EsSaveEvent event) {
|
||||
log.info("规则预警事件开始...");
|
||||
JSONObject data = event.getData();
|
||||
String vin = (String) data.get("vin");
|
||||
String str = cacheUtil.get(vin).toString();
|
||||
FaultCodeCache faultCodeCache = JSON.parseObject(str, FaultCodeCache.class);
|
||||
faultCodeCache.getFaultCode().forEach(faultCode -> {
|
||||
|
||||
});
|
||||
log.info("规则预警事件结束...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(EsSaveEvent event) {
|
||||
onEvent(event);
|
||||
}
|
||||
}
|
|
@ -20,16 +20,16 @@
|
|||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-auth</artifactId>
|
||||
|
|
|
@ -107,7 +107,6 @@
|
|||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
14
pom.xml
14
pom.xml
|
@ -43,6 +43,8 @@
|
|||
<knife4j-openapi3.version>4.1.0</knife4j-openapi3.version>
|
||||
<xxl-job-core.version>2.4.1</xxl-job-core.version>
|
||||
<kafka.version>3.6.3</kafka.version>
|
||||
<enterprise.version>3.6.3</enterprise.version>
|
||||
<common.cache>3.6.3</common.cache>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
|
@ -110,6 +112,12 @@
|
|||
<version>${javax.annotation.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
<version>${common.cache}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
|
@ -149,6 +157,12 @@
|
|||
<version>${commons.io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||
<version>${enterprise.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- excel工具 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
|
|
Loading…
Reference in New Issue