From 1fcdf5a8f369e020e78d524db2fe3cc7ffc86293 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 08 三月 2024 09:30:48 +0800
Subject: [PATCH] Merge branch 'wvp-28181-2.0' into main-dev

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java |   25 ++++++++----
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java               |    2 +
 src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java                                      |   44 ++++++++++++++++++++++
 src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java                           |   10 ++---
 src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java                                             |   14 ++++++
 src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java                    |    2 
 6 files changed, 81 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
index 221a30a..4646b38 100755
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -35,8 +35,10 @@
 import com.genersoft.iot.vmp.utils.DateUtil;
 import gov.nist.javax.sdp.TimeDescriptionImpl;
 import gov.nist.javax.sdp.fields.TimeField;
+import gov.nist.javax.sdp.fields.URIField;
 import gov.nist.javax.sip.message.SIPRequest;
 import gov.nist.javax.sip.message.SIPResponse;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.InitializingBean;
@@ -147,8 +149,21 @@
     public void process(RequestEvent evt) {
         //  Invite Request娑堟伅瀹炵幇锛屾娑堟伅涓�鑸负绾ц仈娑堟伅锛屼笂绾х粰涓嬬骇鍙戦�佽姹傝棰戞寚浠�
         try {
-            SIPRequest request = (SIPRequest) evt.getRequest();
-            String channelId = SipUtils.getChannelIdFromRequest(request);
+            SIPRequest request = (SIPRequest)evt.getRequest();
+            String channelIdFromSub = SipUtils.getChannelIdFromRequest(request);
+
+            // 瑙f瀽sdp娑堟伅, 浣跨敤jainsip 鑷甫鐨剆dp瑙f瀽鏂瑰紡
+            String contentString = new String(request.getRawContent());
+            Gb28181Sdp gb28181Sdp = SipUtils.parseSDP(contentString);
+            SessionDescription sdp = gb28181Sdp.getBaseSdb();
+            String sessionName = sdp.getSessionName().getValue();
+            String channelIdFromSdp = null;
+            if(StringUtils.equalsIgnoreCase("Playback", sessionName)){
+                URIField uriField = (URIField)sdp.getURI();
+                channelIdFromSdp = uriField.getURI().split(":")[0];
+            }
+            final String channelId = StringUtils.isNotBlank(channelIdFromSdp) ? channelIdFromSdp : channelIdFromSub;
+
             String requesterId = SipUtils.getUserIdFromFromHeader(request);
             CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
             if (requesterId == null || channelId == null) {
@@ -257,12 +272,6 @@
                     }
                     return;
                 }
-                // 瑙f瀽sdp娑堟伅, 浣跨敤jainsip 鑷甫鐨剆dp瑙f瀽鏂瑰紡
-                String contentString = new String(request.getRawContent());
-
-                Gb28181Sdp gb28181Sdp = SipUtils.parseSDP(contentString);
-                SessionDescription sdp = gb28181Sdp.getBaseSdb();
-                String sessionName = sdp.getSessionName().getValue();
 
                 Long startTime = null;
                 Long stopTime = null;
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 14640d8..41e0570 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
@@ -78,6 +78,50 @@
     }
 
     /**
+     * 鑾峰彇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);
+    }
+
+    /**
      * 閫掑綊瑙f瀽xml鑺傜偣锛岄�傜敤浜� 澶氳妭鐐规暟鎹�
      *
      * @param node     node
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
index 12b7de1..35028df 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
@@ -136,7 +136,7 @@
                     deviceChannelList.add(deviceChannel);
                 }
                 return deviceChannelList;
-            } else if (catalog == null || !catalogId.equals(platform.getDeviceGBId())) {
+            } else if (catalog == null && !catalogId.equals(platform.getDeviceGBId())) {
                 logger.warn("鏈煡璇㈠埌鐩綍{}鐨勪俊鎭�", catalogId);
                 return null;
             }
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
index 122441b..06c621e 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java
@@ -43,12 +43,11 @@
 import javax.sip.ResponseEvent;
 import javax.sip.PeerUnavailableException;
 import javax.sip.SipException;
-import javax.sip.SipFactory;
-import javax.sip.address.Address;
-import javax.sip.address.SipURI;
-import javax.sip.header.*;
-import javax.sip.message.Request;
 import java.text.ParseException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -392,7 +391,6 @@
                         ()-> registerTask(platform, null),
                         userSetting.getRegisterAgainAfterTime() * 1000);
             }
-
         }
     }
 
diff --git a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java
index e5f9fe4..f8ba4f2 100755
--- a/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java
+++ b/src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java
@@ -31,6 +31,11 @@
 	private static final String ISO8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ss";
 
     /**
+     * iso8601鏃堕棿鏍煎紡甯︽椂鍖猴紝渚嬪锛�2024-02-21T11:10:36+08:00
+     */
+    private static final String ISO8601_ZONE_PATTERN = "yyyy-MM-dd'T'HH:mm:ssXXX";
+
+    /**
      * wvp鍐呴儴缁熶竴鏃堕棿鏍煎紡
      */
     public static final String PATTERN = "yyyy-MM-dd HH:mm:ss";
@@ -49,6 +54,7 @@
 
     public static final DateTimeFormatter formatterCompatibleISO8601 = DateTimeFormatter.ofPattern(ISO8601_COMPATIBLE_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
     public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(ISO8601_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
+    public static final DateTimeFormatter formatterZoneISO8601 = DateTimeFormatter.ofPattern(ISO8601_ZONE_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
     public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
     public static final DateTimeFormatter DateFormatter = DateTimeFormatter.ofPattern(date_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
     public static final DateTimeFormatter urlFormatter = DateTimeFormatter.ofPattern(URL_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr));
@@ -59,7 +65,13 @@
     }
 	
 	public static String ISO8601Toyyyy_MM_dd_HH_mm_ss(String formatTime) {
-        return formatter.format(formatterCompatibleISO8601.parse(formatTime));
+        // 涓夌鏃ユ湡鏍煎紡閮藉皾璇曪紝涓轰簡鍏煎涓嶅悓鍘傚鐨勬棩鏈熸牸寮�
+        if (verification(formatTime, formatterCompatibleISO8601)) {
+            return formatter.format(formatterCompatibleISO8601.parse(formatTime));
+        } else if (verification(formatTime, formatterZoneISO8601)) {
+            return formatter.format(formatterZoneISO8601.parse(formatTime));
+        }
+        return formatter.format(formatterISO8601.parse(formatTime));
     }
 
 	public static String urlToyyyy_MM_dd_HH_mm_ss(String formatTime) {
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
index 471d3df..97803f9 100755
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
@@ -239,6 +239,8 @@
         if (parentPlatformCatch == null) {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "骞冲彴涓嶅瓨鍦�");
         }
+        parentPlatform.setEnable(false);
+        storager.updateParentPlatform(parentPlatform);
         // 鍙戦�佺绾挎秷鎭�,鏃犺鏄惁鎴愬姛閮藉垹闄ょ紦瀛�
         try {
             commanderForPlatform.unregister(parentPlatform, parentPlatformCatch.getSipTransactionInfo(), (event -> {

--
Gitblit v1.8.0