From 7443f2b123774083af4730fdc733b6ba1ab99f7d Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 11 十月 2023 02:37:02 +0800 Subject: [PATCH] 修复目录名称修改,修复多层级目录删除,修复全部移除 --- src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java | 106 +++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 74 insertions(+), 32 deletions(-) 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 1f6bb62..7b03e2a 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 @@ -6,7 +6,6 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; -import com.genersoft.iot.vmp.service.IGbStreamService; import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; @@ -17,6 +16,7 @@ import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.sun.org.apache.xml.internal.resolver.Catalog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -74,6 +74,9 @@ private PlatformChannelMapper platformChannelMapper; @Autowired + private PlatformCatalogMapper platformCatalogMapper; + + @Autowired private StreamProxyMapper streamProxyMapper; @Autowired @@ -90,12 +93,6 @@ @Autowired private PlatformGbStreamMapper platformGbStreamMapper; - - @Autowired - private IGbStreamService gbStreamService; - - @Autowired - private ParentPlatformMapper parentPlatformMapper; /** * 鏍规嵁璁惧ID鍒ゆ柇璁惧鏄惁瀛樺湪 @@ -186,9 +183,19 @@ return false; } try { - int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); - - int limitCount = 300; + int limitCount = 50; + int cleanChannelsResult = 0; + if (channels.size() > limitCount) { + for (int i = 0; i < channels.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > channels.size()) { + toIndex = channels.size(); + } + cleanChannelsResult += this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels.subList(i, toIndex)); + } + } else { + cleanChannelsResult = this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); + } boolean result = cleanChannelsResult < 0; if (!result && addChannels.size() > 0) { if (addChannels.size() > limitCount) { @@ -244,12 +251,12 @@ allChannelMap.put(deviceChannel.getChannelId(), deviceChannel); } } - List<DeviceChannel> addChannels = new ArrayList<>(); - List<DeviceChannel> updateChannels = new ArrayList<>(); - - TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); // 鏁版嵁鍘婚噸 + List<DeviceChannel> channels = new ArrayList<>(); + + List<DeviceChannel> updateChannels = new ArrayList<>(); + List<DeviceChannel> addChannels = new ArrayList<>(); StringBuilder stringBuilder = new StringBuilder(); Map<String, Integer> subContMap = new HashMap<>(); if (deviceChannelList.size() > 0) { @@ -258,15 +265,24 @@ for (DeviceChannel deviceChannel : deviceChannelList) { if (!gbIdSet.contains(deviceChannel.getChannelId())) { gbIdSet.add(deviceChannel.getChannelId()); + deviceChannel.setUpdateTime(DateUtil.getNow()); if (allChannelMap.containsKey(deviceChannel.getChannelId())) { deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId()); deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio()); - deviceChannel.setUpdateTime(DateUtil.getNow()); + if (allChannelMap.get(deviceChannel.getChannelId()).isStatus() !=deviceChannel.isStatus()){ + List<String> strings = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getChannelId()); + if (!CollectionUtils.isEmpty(strings)){ + strings.forEach(platformId->{ + eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.isStatus()?CatalogEvent.ON:CatalogEvent.OFF); + }); + } + } updateChannels.add(deviceChannel); }else { deviceChannel.setCreateTime(DateUtil.getNow()); addChannels.add(deviceChannel); } + channels.add(deviceChannel); if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { if (subContMap.get(deviceChannel.getParentId()) == null) { subContMap.put(deviceChannel.getParentId(), 1); @@ -279,15 +295,8 @@ 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 (channels.size() > 0) { + for (DeviceChannel channel : channels) { if (subContMap.get(channel.getChannelId()) != null){ channel.setSubCount(subContMap.get(channel.getChannelId())); } @@ -298,12 +307,12 @@ if (stringBuilder.length() > 0) { logger.info("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder); } - if(CollectionUtils.isEmpty(updateChannels) && CollectionUtils.isEmpty(addChannels) ){ - logger.info("閫氶亾鏇存柊锛屾暟鎹负绌�={}" , deviceChannelList); + if(CollectionUtils.isEmpty(channels)){ + logger.info("閫氶亾閲嶈锛屾暟鎹负绌�={}" , deviceChannelList); return false; } try { - int limitCount = 300; + int limitCount = 50; boolean result = false; if (addChannels.size() > 0) { if (addChannels.size() > limitCount) { @@ -312,10 +321,10 @@ if (i + limitCount > addChannels.size()) { toIndex = addChannels.size(); } - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels.subList(i, toIndex)) < 0; + result = result || deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0; } }else { - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0; + result = result || deviceChannelMapper.batchAdd(addChannels) < 0; } } if (updateChannels.size() > 0) { @@ -331,13 +340,12 @@ result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; } } + if (result) { //浜嬪姟鍥炴粴 dataSourceTransactionManager.rollback(transactionStatus); - }else { - //鎵嬪姩鎻愪氦 - dataSourceTransactionManager.commit(transactionStatus); } + dataSourceTransactionManager.commit(transactionStatus); //鎵嬪姩鎻愪氦 return true; }catch (Exception e) { logger.error("鏈鐞嗙殑寮傚父 ", e); @@ -899,9 +907,43 @@ eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL); } int delChannelresult = platformChannelMapper.delByCatalogId(platformId, id); + // 鏌ョ湅鏄惁瀛樺湪瀛愮洰褰曪紝濡傛灉瀛樺湪涓�骞跺垹闄� + List<String> allChildCatalog = getAllChildCatalog(id, platformId); + if (!allChildCatalog.isEmpty()) { + int limitCount = 50; + if (allChildCatalog.size() > limitCount) { + for (int i = 0; i < allChildCatalog.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > allChildCatalog.size()) { + toIndex = allChildCatalog.size(); + } + delChannelresult += platformCatalogMapper.deleteAll(platformId, allChildCatalog.subList(i, toIndex)); + } + }else { + delChannelresult += platformCatalogMapper.deleteAll(platformId, allChildCatalog); + } + } return delresult + delChannelresult + delStreamresult; } + private List<String> getAllChildCatalog(String id, String platformId) { + List<String> catalogList = platformCatalogMapper.queryCatalogFromParent(id, platformId); + List<String> catalogListChild = new ArrayList<>(); + if (catalogList != null && !catalogList.isEmpty()) { + for (String childId : catalogList) { + List<String> allChildCatalog = getAllChildCatalog(childId, platformId); + if (allChildCatalog != null && !allChildCatalog.isEmpty()) { + catalogListChild.addAll(allChildCatalog); + } + + } + } + if (!catalogListChild.isEmpty()) { + catalogList.addAll(catalogListChild); + } + return catalogList; + } + @Override public int updateCatalog(PlatformCatalog platformCatalog) { -- Gitblit v1.8.0