增加通用通道接口
parent
a730fc904b
commit
32ec1cb912
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -26,4 +26,8 @@ public interface ICommonGbChannelService {
|
|||
* @param syncKeys 要同步的字段
|
||||
*/
|
||||
boolean SyncChannelFromGb28181Device(String gbDeviceId, List<String> syncKeys);
|
||||
|
||||
List<CommonGbChannel> getChannelsInRegion(String civilCode);
|
||||
|
||||
List<CommonGbChannel> getChannelsInBusinessGroup(String businessGroupID);
|
||||
}
|
||||
|
|
|
@ -243,4 +243,14 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
|
|||
|
||||
return commonGbChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommonGbChannel> getChannelsInRegion(String civilCode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommonGbChannel> getChannelsInBusinessGroup(String businessGroupID) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -330,8 +330,6 @@ public interface IVideoManagerStorage {
|
|||
*/
|
||||
boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList);
|
||||
|
||||
boolean updateChannels(String deviceId, List<DeviceChannel> deviceChannelList);
|
||||
|
||||
/**
|
||||
* 获取目录信息
|
||||
* @param platformId
|
||||
|
|
|
@ -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<DeviceChannel> deviceChannelList) {
|
||||
if (CollectionUtils.isEmpty(deviceChannelList)) {
|
||||
return false;
|
||||
}
|
||||
List<DeviceChannel> allChannels = deviceChannelMapper.queryAllChannels(deviceId);
|
||||
Map<String,DeviceChannel> allChannelMap = new ConcurrentHashMap<>();
|
||||
if (allChannels.size() > 0) {
|
||||
for (DeviceChannel deviceChannel : allChannels) {
|
||||
allChannelMap.put(deviceChannel.getChannelId(), deviceChannel);
|
||||
}
|
||||
}
|
||||
List<DeviceChannel> addChannels = new ArrayList<>();
|
||||
List<DeviceChannel> updateChannels = new ArrayList<>();
|
||||
|
||||
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
// 数据去重
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
Map<String, Integer> subContMap = new HashMap<>();
|
||||
if (deviceChannelList.size() > 0) {
|
||||
// 数据去重
|
||||
Set<String> 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);
|
||||
|
|
|
@ -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<CommonGbChannel> getChannelsInRegion(String civilCode) {
|
||||
return commonGbChannelService.getChannelsInRegion(civilCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询分组下的通道
|
||||
*
|
||||
* @param businessGroupID 业务分组ID
|
||||
*/
|
||||
@DeleteMapping("/region/list")
|
||||
@Operation(summary = "查询分组下的通道")
|
||||
@Parameter(name = "businessGroupID", description = "业务分组ID")
|
||||
public List<CommonGbChannel> 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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue