From 77d9da25c4cbd8fe9cf609b5795f704fb7927818 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 19 七月 2023 20:48:15 +0800
Subject: [PATCH] 修复civilCode判断错误导致civilCode丢失

---
 src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
index 2117c1d..8c96a8e 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
@@ -8,6 +8,7 @@
 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
 import com.genersoft.iot.vmp.utils.DateUtil;
+import org.apache.commons.lang3.math.NumberUtils;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
@@ -225,7 +226,7 @@
             }else {
                 logger.warn("[xml瑙f瀽] 鏃犳硶纭畾琛屾斂鍖哄垝{}鐨勪笂绾ц鏀垮尯鍒�", channelId);
             }
-            deviceChannel.setStatus(1);
+            deviceChannel.setStatus(true);
             return deviceChannel;
         }else {
             if(channelId.length() != 20) {
@@ -284,7 +285,7 @@
                     if (!ObjectUtils.isEmpty(address)) {
                         deviceChannel.setAddress(address);
                     }
-                    deviceChannel.setStatus(1);
+                    deviceChannel.setStatus(true);
                     if (!ObjectUtils.isEmpty(registerWay)) {
                         try {
                             deviceChannel.setRegisterWay(Integer.parseInt(registerWay));
@@ -298,7 +299,7 @@
                     return deviceChannel;
                 case 215:
                     // 涓氬姟鍒嗙粍
-                    deviceChannel.setStatus(1);
+                    deviceChannel.setStatus(true);
                     if (!ObjectUtils.isEmpty(parentID)) {
                         if (!parentID.trim().equalsIgnoreCase(device.getDeviceId())) {
                             deviceChannel.setParentId(parentID);
@@ -312,11 +313,10 @@
                     break;
                 case 216:
                     // 铏氭嫙缁勭粐
-                    deviceChannel.setStatus(1);
+                    deviceChannel.setStatus(true);
                     if (!ObjectUtils.isEmpty(businessGroupID)) {
                         deviceChannel.setBusinessGroupId(businessGroupID);
                     }
-
 
                     if (!ObjectUtils.isEmpty(parentID)) {
                         if (parentID.contains("/")) {
@@ -341,7 +341,11 @@
                     if (!ObjectUtils.isEmpty(owner)) {
                         deviceChannel.setOwner(owner);
                     }
-                    if (!ObjectUtils.isEmpty(civilCode)) {
+                    if (!ObjectUtils.isEmpty(civilCode)
+                            && civilCode.length() <= 8
+                            && NumberUtils.isParsable(civilCode)
+                            && civilCode.length()%2 == 0
+                    ) {
                         deviceChannel.setCivilCode(civilCode);
                     }
                     if (!ObjectUtils.isEmpty(businessGroupID)) {
@@ -376,19 +380,24 @@
                         }
                     }
                     // 鐖惰澶�/鍖哄煙/绯荤粺ID
-                    String realParentId = parentID;
-                    if (!ObjectUtils.isEmpty(parentID)) {
+
+                    if (!ObjectUtils.isEmpty(parentID) ) {
                         if (parentID.contains("/")) {
                             String[] parentIdArray = parentID.split("/");
-                            realParentId = parentIdArray[parentIdArray.length - 1];
+                            deviceChannel.setParentId(parentIdArray[parentIdArray.length - 1]);
+                        }else {
+                            if (parentID.length()%2 == 0) {
+                                deviceChannel.setParentId(parentID);
+                            }else {
+                                logger.warn("[xml瑙f瀽] 涓嶈鑼冪殑parentID锛歿}, 宸茶垗寮�", parentID);
+                            }
                         }
-                        deviceChannel.setParentId(realParentId);
                     }else {
                         if (!ObjectUtils.isEmpty(businessGroupID)) {
                             deviceChannel.setParentId(businessGroupID);
                         }else {
-                            if (!ObjectUtils.isEmpty(civilCode)) {
-                                deviceChannel.setParentId(civilCode);
+                            if (!ObjectUtils.isEmpty(deviceChannel.getCivilCode())) {
+                                deviceChannel.setParentId(deviceChannel.getCivilCode());
                             }
                         }
                     }
@@ -476,13 +485,13 @@
                     if (status != null) {
                         // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR鐨勫吋瀹规�у鐞�
                         if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {
-                            deviceChannel.setStatus(1);
+                            deviceChannel.setStatus(true);
                         }
                         if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
-                            deviceChannel.setStatus(0);
+                            deviceChannel.setStatus(false);
                         }
                     }else {
-                        deviceChannel.setStatus(1);
+                        deviceChannel.setStatus(true);
                     }
 
                     // 缁忓害

--
Gitblit v1.8.0