From cc63a52884ca3c56df66b74aa508803ff91c20e0 Mon Sep 17 00:00:00 2001
From: chenjialing <595168663@qq.com>
Date: 星期五, 06 五月 2022 17:44:56 +0800
Subject: [PATCH] 开发----增加预置位查询接口开发

---
 src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java |   73 ++++++++++++++++++++++++++++--------
 1 files changed, 57 insertions(+), 16 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 94e0cd8..7a46ee7 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
@@ -20,8 +20,8 @@
 
 /**
  * 鍩轰簬dom4j鐨勫伐鍏峰寘
- * 
- * 
+ *
+ *
  */
 public class XmlUtil {
     /**
@@ -31,9 +31,9 @@
 
     /**
      * 瑙f瀽XML涓篋ocument瀵硅薄
-     * 
+     *
      * @param xml 琚В鏋愮殑XMl
-     * 
+     *
      * @return Document
      */
     public static Element parseXml(String xml) {
@@ -51,7 +51,7 @@
 
     /**
      * 鑾峰彇element瀵硅薄鐨則ext鐨勫��
-     * 
+     *
      * @param em  鑺傜偣鐨勫璞�
      * @param tag 鑺傜偣鐨則ag
      * @return 鑺傜偣
@@ -62,12 +62,12 @@
         }
         Element e = em.element(tag);
         //
-        return null == e ? null : e.getText();
+        return null == e ? null : e.getText().trim();
     }
 
     /**
      * 閫掑綊瑙f瀽xml鑺傜偣锛岄�傜敤浜� 澶氳妭鐐规暟鎹�
-     * 
+     *
      * @param node     node
      * @param nodeName nodeName
      * @return List<Map<String, Object>>
@@ -106,7 +106,7 @@
 
     /**
      * xml杞琷son
-     * 
+     *
      * @param element
      * @param json
      */
@@ -191,7 +191,7 @@
         String channelId = channdelIdElement != null ? channdelIdElement.getTextTrim().toString() : "";
         deviceChannel.setChannelId(channelId);
         // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR鐨勫吋瀹规�у鐞�
-        if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) {
+        if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {
             deviceChannel.setStatus(1);
         }
         if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
@@ -204,13 +204,49 @@
         deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
         deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
         deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
+        String businessGroupID = XmlUtil.getText(itemDevice, "BusinessGroupID");
         if (XmlUtil.getText(itemDevice, "Parental") == null
-                || XmlUtil.getText(itemDevice, "Parental") == "") {
-            deviceChannel.setParental(0);
+                || XmlUtil.getText(itemDevice, "Parental").equals("")) {
+            if (deviceChannel.getChannelId().length() <= 10
+                    || (deviceChannel.getChannelId().length() == 20 && (
+                            Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 215
+                                    || Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 216
+                            )
+                        )
+            ) {
+                deviceChannel.setParental(1);
+            }else {
+                deviceChannel.setParental(0);
+            }
         } else {
-            deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
+            // 鐢变簬娴峰悍浼氶敊璇殑鍙戦��65535浣滀负杩欓噷鐨勫彇鍊�,鎵�浠ヨ繖閲岄櫎闈炴槸0鍚﹀垯璁や负鏄�1
+            deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")) == 1?1:0);
         }
         deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
+        String parentId = XmlUtil.getText(itemDevice, "ParentID");
+        if (parentId != null) {
+            if (parentId.contains("/")) {
+                String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
+                deviceChannel.setParentId(lastParentId);
+            }else {
+                deviceChannel.setParentId(parentId);
+            }
+        }else {
+            if (deviceChannel.getChannelId().length() <= 10) { // 姝ゆ椂涓鸿鏀垮尯鍒�, 涓婁笅绾ц鏀垮尯鍒掍娇鐢―eviceId鍏宠仈
+                deviceChannel.setParentId(deviceChannel.getChannelId().substring(0, deviceChannel.getChannelId().length() - 2));
+            }else if (deviceChannel.getChannelId().length() == 20) {
+                if (Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 216) { // 铏氭嫙缁勭粐
+                    deviceChannel.setParentId(businessGroupID);
+                }else if (deviceChannel.getCivilCode() != null) {
+                    // 璁惧锛� 鏃爌arentId鐨�20浣嶆槸浣跨敤CivilCode琛ㄧず涓婄骇鐨勮澶囷紝
+                    // 娉細215 涓氬姟鍒嗙粍鏄渶瑕佹湁parentId鐨�
+                    deviceChannel.setParentId(deviceChannel.getCivilCode());
+                }
+            }else {
+                deviceChannel.setParentId(deviceChannel.getDeviceId());
+            }
+        }
+
         if (XmlUtil.getText(itemDevice, "SafetyWay") == null
                 || XmlUtil.getText(itemDevice, "SafetyWay") == "") {
             deviceChannel.setSafetyWay(0);
@@ -255,13 +291,18 @@
         } else {
             deviceChannel.setLatitude(0.00);
         }
-        if (XmlUtil.getText(itemDevice, "PTZType") == null
-                || XmlUtil.getText(itemDevice, "PTZType") == "") {
-            deviceChannel.setPTZType(0);
+        if (XmlUtil.getText(itemDevice, "PTZType") == null || "".equals(XmlUtil.getText(itemDevice, "PTZType"))) {
+            //鍏煎INFO涓殑淇℃伅
+            Element info = itemDevice.element("Info");
+            if(XmlUtil.getText(info, "PTZType") == null || "".equals(XmlUtil.getText(info, "PTZType"))){
+                deviceChannel.setPTZType(0);
+            }else{
+                deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(info, "PTZType")));
+            }
         } else {
             deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
         }
         deviceChannel.setHasAudio(true); // 榛樿鍚湁闊抽锛屾挱鏀炬椂鍐嶆鏌ユ槸鍚︽湁闊抽鍙婃槸鍚AC
         return deviceChannel;
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.8.0