diff --git a/src/main/java/com/lanhai/o/iot/lhiot/ResponseCmd.java b/src/main/java/com/lanhai/o/iot/lhiot/ResponseCmd.java index 154a329..1f755a8 100644 --- a/src/main/java/com/lanhai/o/iot/lhiot/ResponseCmd.java +++ b/src/main/java/com/lanhai/o/iot/lhiot/ResponseCmd.java @@ -9,4 +9,7 @@ import java.util.List; public class ResponseCmd { @ApiModelProperty("指令") private ResponseCmdDetail rw_prot; + + @ApiModelProperty("指令") + private ResponseCmdDetail params; } diff --git a/src/main/java/com/lanhai/task/MqttDeviceTask.java b/src/main/java/com/lanhai/task/MqttDeviceTask.java index d36b5fe..f29e148 100644 --- a/src/main/java/com/lanhai/task/MqttDeviceTask.java +++ b/src/main/java/com/lanhai/task/MqttDeviceTask.java @@ -49,6 +49,7 @@ public class MqttDeviceTask { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); //监测类设备,并且是mqtt协议 wrapper.eq(SurvDeviceDeploy::getRunStatus,0) + .ne(SurvDeviceDeploy::getDeviceIotUrl,"") .eq(SurvDeviceDeploy::getDeployCate,"surv") .eq(SurvDeviceDeploy::getProtocolType, "mqtt"); diff --git a/src/main/java/com/lanhai/util/LhIotUtil.java b/src/main/java/com/lanhai/util/LhIotUtil.java index c645585..a030b8f 100644 --- a/src/main/java/com/lanhai/util/LhIotUtil.java +++ b/src/main/java/com/lanhai/util/LhIotUtil.java @@ -28,6 +28,7 @@ public class LhIotUtil { /** * 设备发送查询指令 */ + static String clientName = "lhiotMqtt"; public static boolean DeviceQuery(SurvDeviceDeploy survDeviceDeploy){ if(survDeviceDeploy!=null){ @@ -35,9 +36,11 @@ public class LhIotUtil { QueryCmd queryCmd = ConstructCmd(survDeviceDeploy); //发送指令,传入下行主题 iotUrl String cmdStr = JSONObject.toJSONString(queryCmd); - log.error("=================发送查询指令========{}=================",cmdStr); - XxlJobHelper.log("=================发送查询指令========{}=================",cmdStr); - mqttService.sendMessage(survDeviceDeploy.getDeviceIotUrl(),cmdStr); + + XxlJobHelper.log("=========={}=======发送查询指令========{}=================",cmdStr); + boolean b = mqttService.sendMessage(clientName,survDeviceDeploy.getDeviceIotUrl(),cmdStr); + log.error("==========={}======发送查询指令========{}========{}=========",survDeviceDeploy.getDeviceIotUrl(),cmdStr,b); + XxlJobHelper.log("=================发送查询指令re========{}=================",b); } return true; } @@ -97,7 +100,35 @@ public class LhIotUtil { } } - log.warn("{}-----------指令解析结果=============={}",mqttMessage,JSONObject.toJSONString(waterCommonTransVo)); + log.warn("{}-----------指令解析结果1=============={}",mqttMessage,JSONObject.toJSONString(waterCommonTransVo)); + }else{ + log.error("----非主动请求数据,跳过解析==============回执:{}",mqttMessage); + } + }else if(responseCmd.getParams()!=null){ + if("up".equals(responseCmd.getParams().getDir())) { + if (zhibiaoList != null && !zhibiaoList.isEmpty()) { + Map eleMap = new HashMap<>(); + for (ScEquZhibiao scEquZhibiao : zhibiaoList) { + eleMap.put(scEquZhibiao.getCode(), scEquZhibiao.getEntityField()); + } + if (responseCmd.getParams().getR_data()!=null && !responseCmd.getParams().getR_data().isEmpty()) { + //因为数据中不包含时间,所以使用当前时间 + waterCommonTransVo.setDataDateTime(LocalDateTime.now()); + waterCommonTransVo.setDataGatherType(IotConstants.MARK_REALDATA); + + for (ResponseCmdData rDatum : responseCmd.getParams().getR_data()) { + String entityName = eleMap.get(rDatum.getName());//字段名称 + if (StringUtils.isNotBlank(entityName)) { + TUtil.setFieldValue(waterCommonTransVo, entityName, rDatum.getValue()); + counts++; + } else { + log.error("指令2x:{}----未匹配到监测项目:{}", mqttMessage, rDatum.getName()); + } + } + } + } + + log.warn("{}-----------指令解析结果2=============={}",mqttMessage,JSONObject.toJSONString(waterCommonTransVo)); }else{ log.error("----非主动请求数据,跳过解析==============回执:{}",mqttMessage); }