From fc90cd7951600ce5173f71c3e28d78e69b4db4ae Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 19 十二月 2022 14:20:22 +0800
Subject: [PATCH] 优化tcp主动方式的语音对讲

---
 src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java |   71 ++++++++++++++++++++++++-----------
 1 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
index 7ba2c4e..d25e537 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -1,34 +1,32 @@
 package com.genersoft.iot.vmp.service.impl;
 
 import com.genersoft.iot.vmp.conf.DynamicTask;
+import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
 import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
-import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler;
-import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
-import com.genersoft.iot.vmp.service.IDeviceChannelService;
-import com.genersoft.iot.vmp.service.IDeviceService;
 import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
 import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
+import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler;
+import com.genersoft.iot.vmp.service.IDeviceChannelService;
+import com.genersoft.iot.vmp.service.IDeviceService;
 import com.genersoft.iot.vmp.service.IMediaServerService;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
 import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
 import com.genersoft.iot.vmp.storager.dao.PlatformChannelMapper;
 import com.genersoft.iot.vmp.utils.DateUtil;
 import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
+import com.genersoft.iot.vmp.vmanager.bean.ResourceBaceInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-import org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.util.ObjectUtils;
-import org.springframework.util.StringUtils;
 
 import javax.sip.InvalidArgumentException;
 import javax.sip.SipException;
@@ -80,7 +78,7 @@
     TransactionDefinition transactionDefinition;
 
     @Autowired
-    private IVideoManagerStorage storage;
+    private UserSetting userSetting;
 
     @Autowired
     private ISIPCommander commander;
@@ -118,20 +116,28 @@
             }
             sync(device);
         }else {
+
             if(device.getOnline() == 0){
                 device.setOnline(1);
                 device.setCreateTime(now);
-                logger.info("[璁惧涓婄嚎,绂荤嚎鐘舵�佷笅閲嶆柊娉ㄥ唽]: {}锛屾煡璇㈣澶囦俊鎭互鍙婇�氶亾淇℃伅", device.getDeviceId());
                 deviceMapper.update(device);
                 redisCatchStorage.updateDevice(device);
-                try {
-                    commander.deviceInfoQuery(device);
-                } catch (InvalidArgumentException | SipException | ParseException e) {
-                    logger.error("[鍛戒护鍙戦�佸け璐 鏌ヨ璁惧淇℃伅: {}", e.getMessage());
+                if (userSetting.getSyncChannelOnDeviceOnline()) {
+                    logger.info("[璁惧涓婄嚎,绂荤嚎鐘舵�佷笅閲嶆柊娉ㄥ唽]: {}锛屾煡璇㈣澶囦俊鎭互鍙婇�氶亾淇℃伅", device.getDeviceId());
+                    try {
+                        commander.deviceInfoQuery(device);
+                    } catch (InvalidArgumentException | SipException | ParseException e) {
+                        logger.error("[鍛戒护鍙戦�佸け璐 鏌ヨ璁惧淇℃伅: {}", e.getMessage());
+                    }
+                    sync(device);
+                    // TODO 濡傛灉璁惧涓嬬殑閫氶亾绾ц仈鍒颁簡鍏朵粬骞冲彴锛岄偅涔堥渶瑕佸彂閫佷簨浠舵垨鑰卬otify缁欎笂绾у钩鍙�
                 }
-                sync(device);
-                // TODO 濡傛灉璁惧涓嬬殑閫氶亾绾ц仈鍒颁簡鍏朵粬骞冲彴锛岄偅涔堥渶瑕佸彂閫佷簨浠舵垨鑰卬otify缁欎笂绾у钩鍙�
             }else {
+                if (deviceChannelMapper.queryAllChannels(device.getDeviceId()).size() == 0) {
+                    logger.info("[璁惧涓婄嚎]: {}锛岄�氶亾鏁颁负0,鏌ヨ閫氶亾淇℃伅", device.getDeviceId());
+                    sync(device);
+                }
+
                 deviceMapper.update(device);
                 redisCatchStorage.updateDevice(device);
             }
@@ -164,7 +170,7 @@
         redisCatchStorage.updateDevice(device);
         deviceMapper.update(device);
         //杩涜閫氶亾绂荤嚎
-        deviceChannelMapper.offlineByDeviceId(deviceId);
+//        deviceChannelMapper.offlineByDeviceId(deviceId);
         // 绂荤嚎閲婃斁鎵�鏈塻src
         List<SsrcTransaction> ssrcTransactions = streamSession.getSsrcTransactionForAll(deviceId, null, null, null);
         if (ssrcTransactions != null && ssrcTransactions.size() > 0) {
@@ -362,10 +368,10 @@
                 return null;
             }
             // 浣跨敤琛屾斂鍖哄垝灞曠ず鏍�
-            if (parentId.length() > 10) {
-                // TODO 鍙兘鏄鏀垮尯鍒掍笌涓氬姟鍒嗙粍娣锋潅鐨勬儏褰�
-                return null;
-            }
+//            if (parentId.length() > 10) {
+//                // TODO 鍙兘鏄鏀垮尯鍒掍笌涓氬姟鍒嗙粍娣锋潅鐨勬儏褰�
+//                return null;
+//            }
 
             if (parentId.length() == 10 ) {
                 if (onlyCatalog) {
@@ -380,7 +386,18 @@
             List<DeviceChannel> channelsForCivilCode = deviceChannelMapper.getChannelsWithCivilCodeAndLength(deviceId, parentId, parentId.length() + 2);
             if (!onlyCatalog) {
                 List<DeviceChannel> channels = deviceChannelMapper.getChannelsByCivilCode(deviceId, parentId);
-                channelsForCivilCode.addAll(channels);
+
+                for(DeviceChannel channel : channels) {
+                    boolean flag = false;
+                    for(DeviceChannel deviceChannel : channelsForCivilCode) {
+                        if(channel.getChannelId().equals(deviceChannel.getChannelId())) {
+                            flag = true;
+                        }
+                    }
+                    if(!flag) {
+                        channelsForCivilCode.add(channel);
+                    }
+                }
             }
             List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(channelsForCivilCode, parentId);
             return trees;
@@ -548,6 +565,9 @@
         if (!ObjectUtils.isEmpty(device.getMediaServerId())) {
             deviceInStore.setMediaServerId(device.getMediaServerId());
         }
+        deviceInStore.setSdpIp(device.getSdpIp());
+        deviceInStore.setCharset(device.getCharset());
+        deviceInStore.setTreeType(device.getTreeType());
 
         //  鐩綍璁㈤槄鐩稿叧鐨勪俊鎭�
         if (device.getSubscribeCycleForCatalog() > 0) {
@@ -582,6 +602,8 @@
         if (!deviceInStore.getGeoCoordSys().equals(device.getGeoCoordSys())) {
             updateDeviceChannelGeoCoordSys(device);
         }
+        // 鏇存柊redis
+        redisCatchStorage.updateDevice(device);
         deviceMapper.updateCustom(device);
     }
 
@@ -603,4 +625,9 @@
         }
         return result;
     }
+
+    @Override
+    public ResourceBaceInfo getOverview() {
+        return deviceMapper.getOverview();
+    }
 }

--
Gitblit v1.8.0