From 577fb3d00df5a1e4d2125c9569a555544eeb60a7 Mon Sep 17 00:00:00 2001 From: zhanghan11 Date: Tue, 13 Aug 2024 09:38:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modbus/IPCDataUploadSyncThread.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) 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();