From 32ec1cb912b026c7bc58acce6895458458655f40 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 31 Aug 2023 09:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=9A=E7=94=A8=E9=80=9A?= =?UTF-8?q?=E9=81=93=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/common.sql | 15 +-- .../vmp/gb28181/session/CatalogDataCatch.java | 9 +- .../vmp/service/ICommonGbChannelService.java | 4 + .../impl/CommonGbChannelServiceImpl.java | 10 ++ .../vmp/storager/IVideoManagerStorage.java | 2 - .../impl/VideoManagerStorageImpl.java | 116 ------------------ .../channel/CommonChannelController.java | 68 ++++++++++ 7 files changed, 91 insertions(+), 133 deletions(-) create mode 100755 src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java diff --git a/sql/common.sql b/sql/common.sql index 2aab4e13..1102d3f8 100644 --- a/sql/common.sql +++ b/sql/common.sql @@ -44,13 +44,14 @@ CREATE TABLE `wvp_common_gb_channel` CREATE TABLE `wvp_common_business_group` ( - `common_business_group_id` bigint unsigned NOT NULL AUTO_INCREMENT, - `common_business_group_device_id` varchar(50) NOT NULL, - `common_business_group_name` varchar(255) NOT NULL, - `common_business_group_parent_id` varchar(50) DEFAULT NULL, - `common_business_group_path` varchar(500) DEFAULT NULL, - `common_business_group_create_time` varchar(50) NOT NULL, - `common_business_group_update_time` varchar(50) NOT NULL, + `common_business_group_id` bigint unsigned NOT NULL AUTO_INCREMENT, + `common_business_group_device_id` varchar(50) NOT NULL, + `common_business_group_name` varchar(255) NOT NULL, + `common_business_group_parent_id` varchar(50) DEFAULT NULL, + `common_business_group_path` varchar(500) DEFAULT NULL, + `common_business_group_gb_parent_id` varchar(500) DEFAULT NULL, + `common_business_group_create_time` varchar(50) NOT NULL, + `common_business_group_update_time` varchar(50) NOT NULL, PRIMARY KEY (`common_business_group_id`), UNIQUE KEY `common_business_group_device_id` (`common_business_group_device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java index 38cdf7c4..bd966b69 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java @@ -112,16 +112,9 @@ public class CatalogDataCatch { if ( catalogData.getLastTime().isBefore(instantBefore5S)) { // 超过五秒收不到消息任务超时, 只更新这一部分数据, 收到数据与声明的总数一致,则重置通道数据,数据不全则只对收到的数据做更新操作 if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) { - if (catalogData.getTotal() == catalogData.getChannelList().size()) { - storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList()); - }else { - storager.updateChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList()); - } + storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList()); String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条"; catalogData.setErrorMsg(errorMsg); - if (catalogData.getTotal() != catalogData.getChannelList().size()) { - - } }else if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready)) { String errorMsg = "同步失败,等待回复超时"; catalogData.setErrorMsg(errorMsg); diff --git a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java index 5ef11d0e..f10cb07f 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/ICommonGbChannelService.java @@ -26,4 +26,8 @@ public interface ICommonGbChannelService { * @param syncKeys 要同步的字段 */ boolean SyncChannelFromGb28181Device(String gbDeviceId, List syncKeys); + + List getChannelsInRegion(String civilCode); + + List getChannelsInBusinessGroup(String businessGroupID); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java index 90fab55b..59c8e461 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/CommonGbChannelServiceImpl.java @@ -243,4 +243,14 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService { return commonGbChannel; } + + @Override + public List getChannelsInRegion(String civilCode) { + return null; + } + + @Override + public List getChannelsInBusinessGroup(String businessGroupID) { + return null; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java index b0ff0113..cbeebedb 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java @@ -330,8 +330,6 @@ public interface IVideoManagerStorage { */ boolean resetChannels(String deviceId, List deviceChannelList); - boolean updateChannels(String deviceId, List deviceChannelList); - /** * 获取目录信息 * @param platformId diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java index 1f6bb62d..a98c65f9 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java @@ -187,7 +187,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { } try { int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); - int limitCount = 300; boolean result = cleanChannelsResult < 0; if (!result && addChannels.size() > 0) { @@ -231,121 +230,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { } - - @Override - public boolean updateChannels(String deviceId, List deviceChannelList) { - if (CollectionUtils.isEmpty(deviceChannelList)) { - return false; - } - List allChannels = deviceChannelMapper.queryAllChannels(deviceId); - Map allChannelMap = new ConcurrentHashMap<>(); - if (allChannels.size() > 0) { - for (DeviceChannel deviceChannel : allChannels) { - allChannelMap.put(deviceChannel.getChannelId(), deviceChannel); - } - } - List addChannels = new ArrayList<>(); - List updateChannels = new ArrayList<>(); - - - TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); - // 数据去重 - StringBuilder stringBuilder = new StringBuilder(); - Map subContMap = new HashMap<>(); - if (deviceChannelList.size() > 0) { - // 数据去重 - Set gbIdSet = new HashSet<>(); - for (DeviceChannel deviceChannel : deviceChannelList) { - if (!gbIdSet.contains(deviceChannel.getChannelId())) { - gbIdSet.add(deviceChannel.getChannelId()); - if (allChannelMap.containsKey(deviceChannel.getChannelId())) { - deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId()); - deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio()); - deviceChannel.setUpdateTime(DateUtil.getNow()); - updateChannels.add(deviceChannel); - }else { - deviceChannel.setCreateTime(DateUtil.getNow()); - addChannels.add(deviceChannel); - } - if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { - if (subContMap.get(deviceChannel.getParentId()) == null) { - subContMap.put(deviceChannel.getParentId(), 1); - }else { - Integer count = subContMap.get(deviceChannel.getParentId()); - subContMap.put(deviceChannel.getParentId(), count++); - } - } - }else { - stringBuilder.append(deviceChannel.getChannelId()).append(","); - } - } - if (addChannels.size() > 0) { - for (DeviceChannel channel : addChannels) { - if (subContMap.get(channel.getChannelId()) != null){ - channel.setSubCount(subContMap.get(channel.getChannelId())); - } - } - } - if (updateChannels.size() > 0) { - for (DeviceChannel channel : updateChannels) { - if (subContMap.get(channel.getChannelId()) != null){ - channel.setSubCount(subContMap.get(channel.getChannelId())); - } - } - } - - } - if (stringBuilder.length() > 0) { - logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder); - } - if(CollectionUtils.isEmpty(updateChannels) && CollectionUtils.isEmpty(addChannels) ){ - logger.info("通道更新,数据为空={}" , deviceChannelList); - return false; - } - try { - int limitCount = 300; - boolean result = false; - if (addChannels.size() > 0) { - if (addChannels.size() > limitCount) { - for (int i = 0; i < addChannels.size(); i += limitCount) { - int toIndex = i + limitCount; - if (i + limitCount > addChannels.size()) { - toIndex = addChannels.size(); - } - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels.subList(i, toIndex)) < 0; - } - }else { - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0; - } - } - if (updateChannels.size() > 0) { - if (updateChannels.size() > limitCount) { - for (int i = 0; i < updateChannels.size(); i += limitCount) { - int toIndex = i + limitCount; - if (i + limitCount > updateChannels.size()) { - toIndex = updateChannels.size(); - } - result = result || deviceChannelMapper.batchUpdate(updateChannels.subList(i, toIndex)) < 0; - } - }else { - result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; - } - } - if (result) { - //事务回滚 - dataSourceTransactionManager.rollback(transactionStatus); - }else { - //手动提交 - dataSourceTransactionManager.commit(transactionStatus); - } - return true; - }catch (Exception e) { - logger.error("未处理的异常 ", e); - dataSourceTransactionManager.rollback(transactionStatus); - return false; - } - } - @Override public void deviceChannelOnline(String deviceId, String channelId) { deviceChannelMapper.online(deviceId, channelId); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java new file mode 100755 index 00000000..b395f35e --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/channel/CommonChannelController.java @@ -0,0 +1,68 @@ +package com.genersoft.iot.vmp.vmanager.channel; + +import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.service.ICommonGbChannelService; +import com.google.common.collect.Lists; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Tag(name = "通用国标通道") + +@RestController +@RequestMapping("/api/channel") +public class CommonChannelController { + + private final static Logger logger = LoggerFactory.getLogger(CommonChannelController.class); + + @Autowired + private ICommonGbChannelService commonGbChannelService; + + + /** + * 查询区域下的通道 + * + * @param civilCode 区域编号 + */ + @DeleteMapping("/region/list") + @Operation(summary = "查询区域下的通道") + @Parameter(name = "civilCode", description = "区域编号") + public List getChannelsInRegion(String civilCode) { + return commonGbChannelService.getChannelsInRegion(civilCode); + } + + + /** + * 查询分组下的通道 + * + * @param businessGroupID 业务分组ID + */ + @DeleteMapping("/region/list") + @Operation(summary = "查询分组下的通道") + @Parameter(name = "businessGroupID", description = "业务分组ID") + public List getChannelsInBusinessGroup(String businessGroupID) { + return commonGbChannelService.getChannelsInBusinessGroup(businessGroupID); + } + + + /** + * 从下级设备中同步通道 + * + * @param deviceId 设备编号 + */ + @DeleteMapping("/sync/device") + @Operation(summary = "从下级设备中同步通道") + @Parameter(name = "deviceId", description = "设备编号") + @Parameter(name = "syncKeys", description = "选择性同步的字段") + public boolean syncFromDevice(String deviceId, String[] syncKeys) { + return commonGbChannelService.SyncChannelFromGb28181Device(deviceId, Lists.newArrayList(syncKeys)); + } +}