diff --git a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCDataUploadSyncThread.java b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCDataUploadSyncThread.java index 226c84e..ff96df1 100644 --- a/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCDataUploadSyncThread.java +++ b/tzipc-server/tzipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IPCDataUploadSyncThread.java @@ -64,6 +64,9 @@ public class IPCDataUploadSyncThread implements Runnable { for (IpcMonitorField part : partList) { // 筛选当前部位参数 List plcList = plcListRead.stream().filter(field -> part.getFieldCode().equals(field.getParentCode())).collect(Collectors.toList()); + if(plcList.isEmpty()){ + continue; + } // // 遍历生成振动数据 开始 // Map tags = new HashMap<>(); // tags.put("part",part.getFieldValue()); @@ -119,22 +122,20 @@ public class IPCDataUploadSyncThread implements Runnable { } msgMap.put("d", dataList); // 进行数据推送 -// System.out.println(msgMap.toString()); -// System.out.println(host + "----------" + clientId + "----------" + topicu); -// MqttClient sampleClient = new MqttClient(host, clientId, new MemoryPersistence()); -// MqttConnectOptions connOpts = new MqttConnectOptions(); -// connOpts.setUserName(userName); -// connOpts.setPassword(password.toCharArray()); -// sampleClient.connect(connOpts); -// MqttMessage message = new MqttMessage(changeMapToByte(msgMap)); -// sampleClient.publish(topicu, message); -// sampleClient.disconnect(); -// // 显式关闭MqttClient以释放资源 -// sampleClient.close(); -//// System.exit(0); -// } catch (MqttException me) { -// logger.info("数据推送失败,时间{},reason{},msg{},loc{},cause{},excep{}", new Date(), me.getReasonCode(), me.getMessage(), me.getLocalizedMessage(), me.getCause(), me); -// me.printStackTrace(); + MqttClient sampleClient = new MqttClient(host, clientId, new MemoryPersistence()); + MqttConnectOptions connOpts = new MqttConnectOptions(); + connOpts.setUserName(userName); + connOpts.setPassword(password.toCharArray()); + sampleClient.connect(connOpts); + MqttMessage message = new MqttMessage(changeMapToByte(msgMap)); + sampleClient.publish(topicu, message); + sampleClient.disconnect(); + // 显式关闭MqttClient以释放资源 + sampleClient.close(); + logger.info("数据推送成功,时间{},数据{}", new Date(), msgMap.toString()); + } catch (MqttException me) { + logger.info("数据推送失败,时间{},reason{},msg{},loc{},cause{},excep{}", new Date(), me.getReasonCode(), me.getMessage(), me.getLocalizedMessage(), me.getCause(), me); + me.printStackTrace(); } catch (Exception e) { logger.info("数据推送失败,时间{},{}", new Date(), e.getMessage()); e.printStackTrace();