fix():优化协议解析中的集合遍历方法

dev.vehiclegateway
Number7 2024-10-07 14:30:30 +08:00
parent c539a55f1e
commit b395a24329
1 changed files with 12 additions and 9 deletions

View File

@ -25,6 +25,12 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
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
@ -49,7 +55,6 @@ public class MqttConfigure {
@Autowired
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
@Autowired
private KafkaProducer kafkaProducer;
@ -124,25 +129,23 @@ public class MqttConfigure {
SysCar carByVin = null;
List<SysCarVo> carList = service.get("carList");
if(carList==null){
log.info("redis未取到数据");
throw new RuntimeException("Redis未获取到车辆数据!!!");
}else{
for (SysCarVo sysCarVo : carList) {
if(sysCarVo.getCarVin().equals(carVin)){
carByVin = sysCarVo;
}
}
// 使用 HashMap 存储车信息,以 VIN 作为键
Map<String, SysCarVo> carMap = carList.stream()
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
carByVin = carMap.get(carVin);
}
log.info("车辆信息为:" + carByVin);
//对应车辆所对应的报文模版
Integer templateId = carByVin.getTemplateId();
List<MessageTemplateType> templateTypeList=null;
List<MessageTemplateType> messageTemplateTypes=null;
String redisKey = "messageTemplateTypeList";
//key存在
Boolean b = redisService.hasKey(redisKey);
if (b) {
messageTemplateTypes = messageTemplateTypeCacheService.get(redisKey);
}else{
throw new RuntimeException("请先将配置存入Redis!!!");
}