From b395a24329d17b4fa22a52d35ba224782d1face9 Mon Sep 17 00:00:00 2001 From: Number7 <1845377266@qq.com> Date: Mon, 7 Oct 2024 14:30:30 +0800 Subject: [PATCH] =?UTF-8?q?fix():=E4=BC=98=E5=8C=96=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E4=B8=AD=E7=9A=84=E9=9B=86=E5=90=88=E9=81=8D?= =?UTF-8?q?=E5=8E=86=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../muyu/template/config/MqttConfigure.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java index 1e81a87..48bb64c 100644 --- a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java @@ -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 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 carMap = carList.stream() + .collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity())); + carByVin = carMap.get(carVin); } + log.info("车辆信息为:" + carByVin); //对应车辆所对应的报文模版 Integer templateId = carByVin.getTemplateId(); - List templateTypeList=null; List messageTemplateTypes=null; String redisKey = "messageTemplateTypeList"; //key存在 Boolean b = redisService.hasKey(redisKey); if (b) { messageTemplateTypes = messageTemplateTypeCacheService.get(redisKey); - }else{ throw new RuntimeException("请先将配置存入Redis!!!"); }