fix():优化协议解析中的集合遍历方法
parent
c539a55f1e
commit
b395a24329
|
@ -25,6 +25,12 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author liuxinyue
|
* @author liuxinyue
|
||||||
|
@ -49,7 +55,6 @@ public class MqttConfigure {
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
|
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private KafkaProducer kafkaProducer;
|
private KafkaProducer kafkaProducer;
|
||||||
|
|
||||||
|
@ -124,25 +129,23 @@ public class MqttConfigure {
|
||||||
SysCar carByVin = null;
|
SysCar carByVin = null;
|
||||||
List<SysCarVo> carList = service.get("carList");
|
List<SysCarVo> carList = service.get("carList");
|
||||||
if(carList==null){
|
if(carList==null){
|
||||||
log.info("redis未取到数据");
|
throw new RuntimeException("Redis未获取到车辆数据!!!");
|
||||||
}else{
|
}else{
|
||||||
for (SysCarVo sysCarVo : carList) {
|
// 使用 HashMap 存储车信息,以 VIN 作为键
|
||||||
if(sysCarVo.getCarVin().equals(carVin)){
|
Map<String, SysCarVo> carMap = carList.stream()
|
||||||
carByVin = sysCarVo;
|
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
|
||||||
}
|
carByVin = carMap.get(carVin);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("车辆信息为:" + carByVin);
|
log.info("车辆信息为:" + carByVin);
|
||||||
//对应车辆所对应的报文模版
|
//对应车辆所对应的报文模版
|
||||||
Integer templateId = carByVin.getTemplateId();
|
Integer templateId = carByVin.getTemplateId();
|
||||||
List<MessageTemplateType> templateTypeList=null;
|
|
||||||
List<MessageTemplateType> messageTemplateTypes=null;
|
List<MessageTemplateType> messageTemplateTypes=null;
|
||||||
String redisKey = "messageTemplateTypeList";
|
String redisKey = "messageTemplateTypeList";
|
||||||
//key存在
|
//key存在
|
||||||
Boolean b = redisService.hasKey(redisKey);
|
Boolean b = redisService.hasKey(redisKey);
|
||||||
if (b) {
|
if (b) {
|
||||||
messageTemplateTypes = messageTemplateTypeCacheService.get(redisKey);
|
messageTemplateTypes = messageTemplateTypeCacheService.get(redisKey);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
throw new RuntimeException("请先将配置存入Redis!!!");
|
throw new RuntimeException("请先将配置存入Redis!!!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue