From 735cb44142daa455c0fd3d968e66e264205e5c0d Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期五, 20 六月 2025 13:38:04 +0800
Subject: [PATCH] 修改解析MQTT水肥机协议主题的bug

---
 pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol4Mqtt/MqttMsgParser.java |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol4Mqtt/MqttMsgParser.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol4Mqtt/MqttMsgParser.java
index 11cfbd6..04f99e3 100644
--- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol4Mqtt/MqttMsgParser.java
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol4Mqtt/MqttMsgParser.java
@@ -3,6 +3,7 @@
 import com.dy.common.mw.protocol.Command;
 import com.dy.common.mw.protocol4Mqtt.pSdV1.ProtocolConstantSdV1;
 import com.dy.common.mw.protocol4Mqtt.pSdV1.ProtocolParserSdV1;
+import com.dy.common.util.NumUtil;
 import org.eclipse.paho.client.mqttv3.MqttMessage;
 
 /**
@@ -14,14 +15,21 @@
     public static MqttTopic parseSubTopic(String topic) throws Exception {
         if(topic != null && topic.trim().length() != 0){
             String[] topicGrp = topic.split("/") ;
-            if(topicGrp.length != 4){
+            if(topicGrp.length != 5){
                 throw new Exception("鎺ユ敹鐨刴qtt娑堟伅涓婚涓嶅彲璇嗗埆") ;
             }else{
+                if(!NumUtil.isPlusIntNumber(topicGrp[4])){
+                    throw new Exception("鎺ユ敹鐨刴qtt娑堟伅涓婚涓嶅彲璇嗗埆") ;
+                }
+                if(Integer.parseInt(topicGrp[4]) <= 0){
+                    throw new Exception("鎺ユ敹鐨刴qtt娑堟伅涓婚涓嶅彲璇嗗埆") ;
+                }
                 MqttTopic vo = new MqttTopic() ;
                 vo.orgTag = topicGrp[0] ;
                 vo.protocol = topicGrp[1] ;
                 vo.devId = topicGrp[2] ;
-                vo.topic = topicGrp[3] ;
+                vo.type = topicGrp[3] ;
+                vo.no = Integer.parseInt(topicGrp[4]) ;
                 return vo ;
             }
         }else{
@@ -30,7 +38,7 @@
     }
 
     public static String createPubTopic(MqttTopic tp) throws Exception {
-        return tp.orgTag + "/" + tp.protocol + "/" + tp.devId + "/" + tp.topic ;
+        return tp.orgTag + "/" + tp.protocol + "/" + tp.devId + "/" + tp.type + "/" + tp.no;
     }
 
     public static MqttSubMsg parseSubMsg(MqttTopic subTopic, MqttMessage mqttMsg, MqttCallback callback) throws Exception {
@@ -65,7 +73,7 @@
 
 
     public static void main(String[] args) {
-        String s = "ym/sd1/10000/control/m1" ;
+        String s = "jyg/sd1/2430002404000840/weather/1" ;
         String[] ss = s.split("/") ;
         for (String s1 : ss) {
             System.out.println(s1);

--
Gitblit v1.8.0