From c084d6c98af1ef4d36a61adc719df5db76589428 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期六, 07 十月 2023 18:00:08 +0800
Subject: [PATCH] 优化国标级联心跳失败判断逻辑

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
old mode 100644
new mode 100755
index eb8555a..5c977a5
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
@@ -1,5 +1,7 @@
 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
 
+import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
+import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
@@ -28,6 +30,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * 鐩綍鏌ヨ鐨勫洖澶�
@@ -53,6 +56,13 @@
     @Autowired
     private ThreadPoolTaskExecutor taskExecutor;
 
+    @Autowired
+    private CivilCodeFileConf civilCodeFileConf;
+
+    @Autowired
+    private SipConfig sipConfig;
+    private AtomicBoolean processing = new AtomicBoolean(false);
+
     @Override
     public void afterPropertiesSet() throws Exception {
         responseMessageHandler.addHandler(cmdType, this);
@@ -60,7 +70,6 @@
 
     @Override
     public void handForDevice(RequestEvent evt, Device device, Element element) {
-        boolean isEmpty = taskQueue.isEmpty();
         taskQueue.offer(new HandlerCatchData(evt, device, element));
         // 鍥炲200 OK
         try {
@@ -68,8 +77,8 @@
         } catch (SipException | InvalidArgumentException | ParseException e) {
             logger.error("[鍛戒护鍙戦�佸け璐 鐩綍鏌ヨ鍥炲: {}", e.getMessage());
         }
-        // 濡傛灉涓嶄负绌哄垯璇存槑宸茬粡寮�鍚秷鎭鐞�
-        if (isEmpty) {
+        // 宸茬粡寮�鍚秷鎭鐞嗗垯璺宠繃
+        if (processing.compareAndSet(false, true)) {
             taskExecutor.execute(() -> {
                 while (!taskQueue.isEmpty()) {
                     // 鍏ㄥ眬寮傚父鎹曡幏锛屼繚璇佷笅涓�鏉″彲浠ュ緱鍒板鐞�
@@ -100,6 +109,7 @@
                             Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
                             if (deviceListIterator != null) {
                                 List<DeviceChannel> channelList = new ArrayList<>();
+                                List<String> parentChannelIds = new ArrayList<>();
                                 // 閬嶅巻DeviceList
                                 while (deviceListIterator.hasNext()) {
                                     Element itemDevice = deviceListIterator.next();
@@ -107,11 +117,18 @@
                                     if (channelDeviceElement == null) {
                                         continue;
                                     }
-                                    DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device, null);
-                                    deviceChannel = SipUtils.updateGps(deviceChannel, device.getGeoCoordSys());
-                                    deviceChannel.setDeviceId(take.getDevice().getDeviceId());
+                                    DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, null, civilCodeFileConf);
+                                    if (channel == null) {
+                                        logger.info("[鏀跺埌鐩綍璁㈤槄]锛氫絾鏄В鏋愬け璐� {}", new String(evt.getRequest().getRawContent()));
+                                        continue;
+                                    }
+                                    if (channel.getParentId() != null && channel.getParentId().equals(sipConfig.getId())) {
+                                        channel.setParentId(null);
+                                    }
+                                    SipUtils.updateGps(channel, device.getGeoCoordSys());
+                                    channel.setDeviceId(take.getDevice().getDeviceId());
 
-                                    channelList.add(deviceChannel);
+                                    channelList.add(channel);
                                 }
                                 int sn = Integer.parseInt(snElement.getText());
                                 catalogDataCatch.put(take.getDevice().getDeviceId(), sn, sumNum, take.getDevice(), channelList);
@@ -130,11 +147,12 @@
                             }
 
                         }
-                    }catch (Exception e) {
+                    } catch (Exception e) {
                         logger.warn("[鏀跺埌閫氶亾] 鍙戠幇鏈鐞嗙殑寮傚父, \r\n{}", evt.getRequest());
                         logger.error("[鏀跺埌閫氶亾] 寮傚父鍐呭锛� ", e);
                     }
                 }
+                processing.set(false);
             });
         }
 

--
Gitblit v1.8.0