From c6dfb63f8fd5f04fa00ac6c45da2eb6bcc5cada4 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 25 三月 2024 23:59:50 +0800
Subject: [PATCH] 优化hook通知

---
 src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 54 insertions(+), 6 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 e614b9f..70702bb 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
@@ -3,11 +3,12 @@
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.common.CivilCodePo;
-import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
+import com.genersoft.iot.vmp.utils.CivilCodeUtil;
 import com.genersoft.iot.vmp.utils.DateUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
@@ -74,6 +75,50 @@
         Element e = em.element(tag);
         //
         return null == e ? null : e.getText().trim();
+    }
+
+    /**
+     * 鑾峰彇element瀵硅薄鐨則ext鐨勫��
+     *
+     * @param em  鑺傜偣鐨勫璞�
+     * @param tag 鑺傜偣鐨則ag
+     * @return 鑺傜偣
+     */
+    public static Double getDouble(Element em, String tag) {
+        if (null == em) {
+            return null;
+        }
+        Element e = em.element(tag);
+        if (null == e) {
+            return null;
+        }
+        String text = e.getText().trim();
+        if (ObjectUtils.isEmpty(text) || !NumberUtils.isParsable(text)) {
+            return null;
+        }
+        return Double.parseDouble(text);
+    }
+
+    /**
+     * 鑾峰彇element瀵硅薄鐨則ext鐨勫��
+     *
+     * @param em  鑺傜偣鐨勫璞�
+     * @param tag 鑺傜偣鐨則ag
+     * @return 鑺傜偣
+     */
+    public static Integer getInteger(Element em, String tag) {
+        if (null == em) {
+            return null;
+        }
+        Element e = em.element(tag);
+        if (null == e) {
+            return null;
+        }
+        String text = e.getText().trim();
+        if (ObjectUtils.isEmpty(text) || !NumberUtils.isParsable(text)) {
+            return null;
+        }
+        return Integer.parseInt(text);
     }
 
     /**
@@ -195,7 +240,7 @@
         CivilCode, BusinessGroup,VirtualOrganization,Other
     }
 
-    public static DeviceChannel channelContentHandler(Element itemDevice, Device device, String event, CivilCodeFileConf civilCodeFileConf){
+    public static DeviceChannel channelContentHandler(Element itemDevice, Device device, String event){
         DeviceChannel deviceChannel = new DeviceChannel();
         deviceChannel.setDeviceId(device.getDeviceId());
         Element channdelIdElement = itemDevice.element("DeviceID");
@@ -214,12 +259,15 @@
             return deviceChannel;
         }
         Element nameElement = itemDevice.element("Name");
-        if (nameElement != null) {
+        // 褰撻�氶亾鍚嶇О涓虹┖鏃讹紝璁剧疆閫氶亾鍚嶇О涓洪�氶亾缂栫爜锛岄伩鍏嶇骇鑱旀椂鍥犻�氶亾鍚嶇О涓虹┖瀵艰嚧涓婄骇鎺ユ敹閫氶亾澶辫触
+        if (nameElement != null && StringUtils.isNotBlank(nameElement.getText())) {
             deviceChannel.setName(nameElement.getText());
+        } else {
+            deviceChannel.setName(channelId);
         }
         if(channelId.length() <= 8) {
             deviceChannel.setHasAudio(false);
-            CivilCodePo parentCode = civilCodeFileConf.getParentCode(channelId);
+            CivilCodePo parentCode = CivilCodeUtil.INSTANCE.getParentCode(channelId);
             if (parentCode != null) {
                 deviceChannel.setParentId(parentCode.getCode());
                 deviceChannel.setCivilCode(parentCode.getCode());
@@ -520,14 +568,14 @@
                         String ptzTypeFromInfo = XmlUtil.getText(info, "PTZType");
                         if(!ObjectUtils.isEmpty(ptzTypeFromInfo)){
                             try {
-                                deviceChannel.setPTZType(Integer.parseInt(ptzTypeFromInfo));
+                                deviceChannel.setPtzType(Integer.parseInt(ptzTypeFromInfo));
                             }catch (NumberFormatException e){
                                 logger.warn("[xml瑙f瀽] 浠庨�氶亾鏁版嵁info涓幏鍙朠TZType澶辫触锛� {}", ptzTypeFromInfo);
                             }
                         }
                     } else {
                         try {
-                            deviceChannel.setPTZType(Integer.parseInt(ptzType));
+                            deviceChannel.setPtzType(Integer.parseInt(ptzType));
                         }catch (NumberFormatException e){
                             logger.warn("[xml瑙f瀽] 浠庨�氶亾鏁版嵁涓幏鍙朠TZType澶辫触锛� {}", ptzType);
                         }

--
Gitblit v1.8.0