From d9d08181a94d727a4fe5933ac9efd1ff5c8a7c5a Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 16 七月 2025 13:49:13 +0800
Subject: [PATCH] 中间件修改内容: 1、当没农业综合站时即没相关配置项目内容为空时,启动时会产生bug; 2、整理优化代码。

---
 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java |   57 +++++++++++++++++++++++++++++++--------------------------
 1 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java
index 661696d..1c92e9d 100644
--- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java
+++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/mqtt/MqttManager.java
@@ -3,8 +3,8 @@
 import com.dy.common.mw.channel.mqtt.MqttClientPool;
 import com.dy.common.mw.protocol4Mqtt.MqttNotify;
 import com.dy.common.mw.protocol4Mqtt.MqttNotifyInfo;
-import com.dy.common.mw.protocol4Mqtt.status.DevOnLineSt;
-import com.dy.common.mw.protocol4Mqtt.status.DevRunSt;
+import com.dy.common.mw.protocol4Mqtt.status.DevOnLineInfo;
+import com.dy.common.mw.protocol4Mqtt.status.DevRunInfo;
 import com.dy.rtuMw.server.ServerProperties;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -64,34 +64,39 @@
             throw new Exception("Mqtt杩炴帴姹犺幏寰楄闃呰繛鎺ヤ笉鍙敤");
         }
         subClients.add(clientSub) ;
+
         // 璁㈤槄涓婚
-        for(int i = 0; i < this.configVo.subTopics.length; i++){
-            for(int j = 0 ; j < this.configVo.protocolAndDeviceIds.length; j++){
-                clientSub.subscribe(ServerProperties.orgTag + "/"
-                        + this.configVo.protocolAndDeviceIds[j] + "/"
-                        + this.configVo.subTopics[i],
-                        this.configVo.subTopicsQos[i],
-                        //姣忎竴涓闃呬富棰橀兘鏈変竴涓狹qttMessageListener瀹炰緥
-                        new MqttMessageListener(new MqttNotify(){
-                            @Override
-                            public void notify(String devId, MqttNotifyInfo... infos) {
-                                if(devId != null && infos != null && infos.length > 0){
-                                    for(MqttNotifyInfo info : infos){
-                                        if(info instanceof DevOnLineSt){
-                                            DevOnLineSt onLineSt = (DevOnLineSt)info;
-                                            if(onLineSt.onLine != null && onLineSt.onLine.booleanValue()){
-                                                DevStatusDealer.onLine(devId, ((DevOnLineSt)info).protocol);
-                                            }else{
-                                                DevStatusDealer.offLine(devId);
+        if(this.configVo.subTopics != null && this.configVo.subTopics.length > 0){
+            if(this.configVo.protocolAndDeviceIds != null || this.configVo.protocolAndDeviceIds.length > 0){
+                for(int i = 0; i < this.configVo.subTopics.length; i++){
+                    for(int j = 0 ; j < this.configVo.protocolAndDeviceIds.length; j++){
+                        clientSub.subscribe(ServerProperties.orgTag + "/"
+                                        + this.configVo.protocolAndDeviceIds[j] + "/"
+                                        + this.configVo.subTopics[i],
+                                this.configVo.subTopicsQos[i],
+                                //姣忎竴涓闃呬富棰橀兘鏈変竴涓狹qttMessageListener瀹炰緥
+                                new MqttMessageListener(new MqttNotify(){
+                                    @Override
+                                    public void notify(String devId, MqttNotifyInfo... infos) {
+                                        if(devId != null && infos != null && infos.length > 0){
+                                            for(MqttNotifyInfo info : infos){
+                                                if(info instanceof DevOnLineInfo){
+                                                    DevOnLineInfo onLineSt = (DevOnLineInfo)info;
+                                                    if(onLineSt.onLine != null && onLineSt.onLine.booleanValue()){
+                                                        DevStatusDealer.onLine(devId, ((DevOnLineInfo)info).protocol);
+                                                    }else{
+                                                        DevStatusDealer.offLine(devId);
+                                                    }
+                                                } else if(info instanceof DevRunInfo){
+                                                    DevStatusDealer.setStatus(devId, (DevRunInfo)info);
+                                                }
                                             }
-                                        } else if(info instanceof DevRunSt){
-                                            DevStatusDealer.setStatus(devId, (DevRunSt)info);
                                         }
                                     }
-                                }
-                            }
-                        })
-                );
+                                })
+                        );
+                    }
+                }
             }
         }
     }

--
Gitblit v1.8.0