fix(): 修改报文数据解析获取报文数据模版方法
parent
a834f9d1bd
commit
542a656dc6
|
@ -41,7 +41,7 @@ public class VehicleType extends BaseEntity {
|
||||||
* 报文模版外键
|
* 报文模版外键
|
||||||
*/
|
*/
|
||||||
@Schema(type = "Integer",description = "报文模版外键")
|
@Schema(type = "Integer",description = "报文模版外键")
|
||||||
private Integer messageTemplateId;
|
private Long messageTemplateId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加车辆类型
|
* 添加车辆类型
|
||||||
|
|
|
@ -48,13 +48,6 @@ public class VehicleController extends BaseController {
|
||||||
//添加车辆缓存
|
//添加车辆缓存
|
||||||
@Autowired
|
@Autowired
|
||||||
private VehicleCacheService vehicleCacheService;
|
private VehicleCacheService vehicleCacheService;
|
||||||
//车辆信息
|
|
||||||
@Autowired
|
|
||||||
private AllVehicleCacheService allVehicleCacheService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate redisTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询车辆管理列表
|
* 查询车辆管理列表
|
||||||
|
@ -66,10 +59,11 @@ public class VehicleController extends BaseController {
|
||||||
public Result<TableDataInfo<VehicleManageResp>> getVehicleList(@RequestBody VehicleManageReq vehicleManageReq) {
|
public Result<TableDataInfo<VehicleManageResp>> getVehicleList(@RequestBody VehicleManageReq vehicleManageReq) {
|
||||||
startPage();
|
startPage();
|
||||||
List<VehicleManageResp> list = vehicleService.getVehicleList(vehicleManageReq);
|
List<VehicleManageResp> list = vehicleService.getVehicleList(vehicleManageReq);
|
||||||
// 将车辆信息存到Redis
|
//将车辆信息存到Redis
|
||||||
for (VehicleManageResp resp : list) {
|
List<Vehicle> vehicleList = vehicleService.list();
|
||||||
allVehicleCacheService.put(resp.getVehicleVin(), resp);
|
vehicleList.forEach(vehicle -> {
|
||||||
}
|
vehicleCacheService.put(vehicle.getVehicleVin(), vehicle);
|
||||||
|
});
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,12 @@
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
<artifactId>cloud-common-kafka</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise-cache</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -4,7 +4,14 @@ import cn.hutool.json.JSONObject;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
|
import com.muyu.cloud.protocol.parsing.feign.RemoteServiceClient;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.domain.Vehicle;
|
||||||
|
import com.muyu.domain.VehicleType;
|
||||||
import com.muyu.domain.resp.MessageValueListResp;
|
import com.muyu.domain.resp.MessageValueListResp;
|
||||||
|
import com.muyu.domain.resp.VehicleManageResp;
|
||||||
|
import com.muyu.enterprise.cache.AllMessageValueCacheService;
|
||||||
|
import com.muyu.enterprise.cache.AllVehicleCacheService;
|
||||||
|
import com.muyu.enterprise.cache.VehicleCacheService;
|
||||||
|
import com.muyu.enterprise.cache.VehicleTypeCacheService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
@ -38,6 +45,15 @@ public class ParsingTest {
|
||||||
@Resource
|
@Resource
|
||||||
private KafkaProducer<String, String> kafkaProducer;
|
private KafkaProducer<String, String> kafkaProducer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleCacheService vehicleCacheService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleTypeCacheService vehicleTypeCacheService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AllMessageValueCacheService allMessageValueCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议解析
|
* 协议解析
|
||||||
*/
|
*/
|
||||||
|
@ -92,32 +108,34 @@ public class ParsingTest {
|
||||||
String vehicleVin = result.substring(1, 18);
|
String vehicleVin = result.substring(1, 18);
|
||||||
log.info("车辆VIN码: " + vehicleVin);
|
log.info("车辆VIN码: " + vehicleVin);
|
||||||
//根据车辆VIN码查询报文模板ID
|
//根据车辆VIN码查询报文模板ID
|
||||||
Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
|
Vehicle vehicle = vehicleCacheService.get(vehicleVin);
|
||||||
Long templateId = byVehicleVin.getData();
|
Long vehicleTypeId = vehicle.getVehicleTypeId();
|
||||||
List<MessageValueListResp> templateList;
|
VehicleType vehicleType = vehicleTypeCacheService.get(String.valueOf(vehicleTypeId));
|
||||||
//从redis缓存中获取报文模板数据
|
Long templateId = vehicleType.getMessageTemplateId();
|
||||||
try {
|
List<MessageValueListResp> templateList = allMessageValueCacheService.get(String.valueOf(templateId));
|
||||||
String redisKey = "messageTemplate" + templateId;
|
// //从redis缓存中获取报文模板数据
|
||||||
if (redisTemplate.hasKey(redisKey)) {
|
// try {
|
||||||
List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
// String redisKey = "messageTemplate" + templateId;
|
||||||
templateList = list.stream()
|
// if (redisTemplate.hasKey(redisKey)) {
|
||||||
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
// List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
||||||
.toList();
|
// templateList = list.stream()
|
||||||
log.info("Redis缓存查询成功");
|
// .map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
||||||
} else {
|
// .toList();
|
||||||
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
// log.info("Redis缓存查询成功");
|
||||||
templateList = byTemplateId.getData();
|
// } else {
|
||||||
templateList.forEach(
|
// Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
||||||
listResp ->
|
// templateList = byTemplateId.getData();
|
||||||
redisTemplate.opsForList().rightPush(
|
// templateList.forEach(
|
||||||
redisKey, JSON.toJSONString(listResp)
|
// listResp ->
|
||||||
)
|
// redisTemplate.opsForList().rightPush(
|
||||||
);
|
// redisKey, JSON.toJSONString(listResp)
|
||||||
log.info("数据库查询成功");
|
// )
|
||||||
}
|
// );
|
||||||
} catch (Exception e) {
|
// log.info("数据库查询成功");
|
||||||
throw new RuntimeException("获取报文模板失败");
|
// }
|
||||||
}
|
// } catch (Exception e) {
|
||||||
|
// throw new RuntimeException("获取报文模板失败");
|
||||||
|
// }
|
||||||
//判断报文模板列表不为空
|
//判断报文模板列表不为空
|
||||||
if (templateList.isEmpty()) {
|
if (templateList.isEmpty()) {
|
||||||
throw new RuntimeException("报文模版为空");
|
throw new RuntimeException("报文模版为空");
|
||||||
|
|
Loading…
Reference in New Issue