From 77602032ab72b7f44bfebb4a01ea2b1df1ccae9c Mon Sep 17 00:00:00 2001 From: zhangyue <82248909@qq.com> Date: Thu, 28 May 2026 10:44:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E4=B9=8C=E7=8F=AD=E5=9B=BE?= =?UTF-8?q?=E6=96=B0=E6=95=B0=E6=8D=AE=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lanhai/util/LhIotUtil.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/lanhai/util/LhIotUtil.java b/src/main/java/com/lanhai/util/LhIotUtil.java index 7de5ea8..c645585 100644 --- a/src/main/java/com/lanhai/util/LhIotUtil.java +++ b/src/main/java/com/lanhai/util/LhIotUtil.java @@ -71,6 +71,7 @@ public class LhIotUtil { public static WaterCommonTransVo transData(List zhibiaoList, String mqttMessage) { WaterCommonTransVo waterCommonTransVo = new WaterCommonTransVo(); ResponseCmd responseCmd = JSONObject.parseObject(mqttMessage,ResponseCmd.class); + int counts = 0; //计数器,如果没有任何监测项与配置匹配,则放弃此数据 if(responseCmd!=null){ if(responseCmd.getRw_prot()!=null){ if("rsp".equals(responseCmd.getRw_prot().getDir())) { @@ -79,21 +80,23 @@ public class LhIotUtil { for (ScEquZhibiao scEquZhibiao : zhibiaoList) { eleMap.put(scEquZhibiao.getCode(), scEquZhibiao.getEntityField()); } - - if (!responseCmd.getRw_prot().getR_data().isEmpty()) { + if (responseCmd.getRw_prot().getR_data()!=null && !responseCmd.getRw_prot().getR_data().isEmpty()) { //因为数据中不包含时间,所以使用当前时间 waterCommonTransVo.setDataDateTime(LocalDateTime.now()); waterCommonTransVo.setDataGatherType(IotConstants.MARK_REALDATA); + for (ResponseCmdData rDatum : responseCmd.getRw_prot().getR_data()) { String entityName = eleMap.get(rDatum.getName());//字段名称 if (StringUtils.isNotBlank(entityName)) { TUtil.setFieldValue(waterCommonTransVo, entityName, rDatum.getValue()); + counts++; } else { log.error("指令:{}----未匹配到监测项目:{}", mqttMessage, rDatum.getName()); } } } } + log.warn("{}-----------指令解析结果=============={}",mqttMessage,JSONObject.toJSONString(waterCommonTransVo)); }else{ log.error("----非主动请求数据,跳过解析==============回执:{}",mqttMessage); @@ -104,6 +107,10 @@ public class LhIotUtil { }else{ log.error("xxxxxxxxxxxxx解析失败,回执格式有误1xxxxxxxxxxxxx"); } + if(counts==0){ + log.error("xxxxxxxxxx未匹配到监测项,丢弃此数据{}xxxxxxxxxxxxxxx",mqttMessage); + return null; + } return waterCommonTransVo; } }