From 723fe4528659d70b6bc79450d86768bb51292787 Mon Sep 17 00:00:00 2001 From: xy <748613696@qq.com> Date: Wed, 24 Jun 2026 16:32:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(mqtt):=20=E4=BF=AE=E5=A4=8DMQTT=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=A4=84=E7=90=86=E4=B8=AD=E7=9A=84=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了通过逻辑子设备ID获取监测点信息的查询逻辑 - 实现了当设备注册信息为空时的备用查询方案 - 增加了对装置NDID和逻辑子设备ID的校验验证 - 统一了Redis缓存键值的生成方式为使用监测点ID - 添加了相关业务异常处理以提高系统稳定性 --- .../access/handler/MqttMessageHandler.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java index 2fe796b..aaec036 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java @@ -439,7 +439,22 @@ public class MqttMessageHandler { logDto.setOperate("系统端收到装置端"+nDid+"询问项目列表报文,code = " + res.getCode()); logDto.setResult(1); List projectInfoList = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.ProjectInfo.class); - String key3 = AppRedisKey.PROJECT_INFO + nDid + rspDataDto.getClDid(); + CsDeviceRegistry csDeviceRegistry = csDeviceRegistryFeignClient.queryByCurrentNdidAndClDid(nDid, rspDataDto.getClDid()).getData(); + String lineId; + if (Objects.isNull(csDeviceRegistry)) { + List lines = csLineFeignClient.findByNdid(nDid).getData(); + if (CollectionUtil.isEmpty(lines)) { + throw new BusinessException("通过装置NDID获取监测点信息失败"); + } + CsLinePO line = lines.stream().filter(item->Objects.equals(item.getClDid(),rspDataDto.getClDid())).findFirst().orElse(null); + if (Objects.isNull(line)) { + throw new BusinessException("通过逻辑子设备ID获取监测点信息失败"); + } + lineId = line.getLineId(); + } else { + lineId = csDeviceRegistry.getId(); + } + String key3 = AppRedisKey.PROJECT_INFO + lineId; redisUtil.saveByKeyWithExpire(key3,projectInfoList,60L); logMessageTemplate.sendMember(logDto); break; @@ -477,7 +492,15 @@ public class MqttMessageHandler { CsDeviceRegistry csDeviceRegistry = csDeviceRegistryFeignClient.queryByCurrentNdidAndClDid(nDid, item.getClDid()).getData(); String lineId; if (Objects.isNull(csDeviceRegistry)) { - lineId = nDid + item.getClDid(); + List lines = csLineFeignClient.findByNdid(nDid).getData(); + if (CollectionUtil.isEmpty(lines)) { + throw new BusinessException("通过装置NDID获取监测点信息失败"); + } + CsLinePO line = lines.stream().filter(item2->Objects.equals(item2.getClDid(),item.getClDid())).findFirst().orElse(null); + if (Objects.isNull(line)) { + throw new BusinessException("通过逻辑子设备ID获取监测点信息失败"); + } + lineId = line.getLineId(); } else { lineId = csDeviceRegistry.getId(); }