From cf23816c80771c9e22bb50d0d89feb34d2edca79 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期四, 13 一月 2022 16:42:58 +0800 Subject: [PATCH] 恢复合并的limit值 --- src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java | 157 +++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 137 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java index 1d8d83a..2f4c966 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java @@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; 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.IVideoManagerStorager; import com.genersoft.iot.vmp.storager.dao.*; @@ -23,10 +24,7 @@ import org.springframework.util.StringUtils; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @description:瑙嗛璁惧鏁版嵁瀛樺偍-jdbc瀹炵幇 @@ -71,6 +69,9 @@ @Autowired private GbStreamMapper gbStreamMapper; + + @Autowired + private PlatformCatalogMapper catalogMapper; ; @Autowired @@ -223,21 +224,41 @@ @Override public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) { TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + // 鏁版嵁鍘婚噸 + List<DeviceChannel> channels = new ArrayList<>(); + StringBuilder stringBuilder = new StringBuilder(); + if (deviceChannelList.size() > 1) { + // 鏁版嵁鍘婚噸 + Set<String> gbIdSet = new HashSet<>(); + for (DeviceChannel deviceChannel : deviceChannelList) { + if (!gbIdSet.contains(deviceChannel.getChannelId())) { + gbIdSet.add(deviceChannel.getChannelId()); + channels.add(deviceChannel); + }else { + stringBuilder.append(deviceChannel.getChannelId() + ","); + } + } + }else { + channels = deviceChannelList; + } + if (stringBuilder.length() > 0) { + logger.debug("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder); + } try { int cleanChannelsResult = deviceChannelMapper.cleanChannelsByDeviceId(deviceId); int limitCount = 300; - boolean result = cleanChannelsResult <0; - if (!result && deviceChannelList.size() > 0) { - if (deviceChannelList.size() > limitCount) { - for (int i = 0; i < deviceChannelList.size(); i += limitCount) { + boolean result = cleanChannelsResult < 0; + if (!result && channels.size() > 0) { + if (channels.size() > limitCount) { + for (int i = 0; i < channels.size(); i += limitCount) { int toIndex = i + limitCount; - if (i + limitCount > deviceChannelList.size()) { - toIndex = deviceChannelList.size(); + if (i + limitCount > channels.size()) { + toIndex = channels.size(); } - result = result || deviceChannelMapper.batchAdd(deviceChannelList.subList(i, toIndex)) < 0; + result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0; } }else { - result = result || deviceChannelMapper.batchAdd(deviceChannelList) < 0; + result = result || deviceChannelMapper.batchAdd(channels) < 0; } } if (result) { @@ -449,6 +470,9 @@ @Override public boolean addParentPlatform(ParentPlatform parentPlatform) { + if (parentPlatform.getCatalogId() == null) { + parentPlatform.setCatalogId(parentPlatform.getServerGBId()); + } int result = platformMapper.addParentPlatform(parentPlatform); return result > 0; } @@ -458,6 +482,9 @@ int result = 0; ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId()); if (parentPlatform.getId() == null ) { + if (parentPlatform.getCatalogId() == null) { + parentPlatform.setCatalogId(parentPlatform.getServerGBId()); + } result = platformMapper.addParentPlatform(parentPlatform); if (parentPlatformCatch == null) { parentPlatformCatch = new ParentPlatformCatch(); @@ -477,15 +504,21 @@ // 鏇存柊缂撳瓨 parentPlatformCatch.setParentPlatform(parentPlatform); redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); - // 鍏变韩鎵�鏈夎棰戞祦锛岄渶瑕佸皢鐜版湁瑙嗛娴佹坊鍔犲埌姝ゅ钩鍙� - List<GbStream> gbStreams = gbStreamMapper.selectAll(); - if (gbStreams.size() > 0) { - if (parentPlatform.isShareAllLiveStream()) { - gbStreamService.addPlatformInfo(gbStreams, parentPlatform.getServerGBId()); - }else { - gbStreamService.delPlatformInfo(gbStreams); + if (parentPlatform.isEnable()) { + // 鍏变韩鎵�鏈夎棰戞祦锛岄渶瑕佸皢鐜版湁瑙嗛娴佹坊鍔犲埌姝ゅ钩鍙� + List<GbStream> gbStreams = gbStreamMapper.queryStreamNotInPlatform(); + if (gbStreams.size() > 0) { + for (GbStream gbStream : gbStreams) { + gbStream.setCatalogId(parentPlatform.getCatalogId()); + } + if (parentPlatform.isShareAllLiveStream()) { + gbStreamService.addPlatformInfo(gbStreams, parentPlatform.getServerGBId(), parentPlatform.getCatalogId()); + }else { + gbStreamService.delPlatformInfo(gbStreams); + } } } + return result > 0; } @@ -536,10 +569,11 @@ } @Override - public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces) { + public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId) { Map<String, ChannelReduce> deviceAndChannels = new HashMap<>(); for (ChannelReduce channelReduce : channelReduces) { + channelReduce.setCatalogId(catalogId); deviceAndChannels.put(channelReduce.getDeviceId() + "_" + channelReduce.getChannelId(), channelReduce); } List<String> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet()); @@ -574,6 +608,18 @@ public DeviceChannel queryChannelInParentPlatform(String platformId, String channelId) { DeviceChannel channel = platformChannelMapper.queryChannelInParentPlatform(platformId, channelId); return channel; + } + + @Override + public List<PlatformCatalog> queryChannelInParentPlatformAndCatalog(String platformId, String catalogId) { + List<PlatformCatalog> catalogs = platformChannelMapper.queryChannelInParentPlatformAndCatalog(platformId, catalogId); + return catalogs; + } + + @Override + public List<PlatformCatalog> queryStreamInParentPlatformAndCatalog(String platformId, String catalogId) { + List<PlatformCatalog> catalogs = platformGbStreamMapper.queryChannelInParentPlatformAndCatalogForCatlog(platformId, catalogId); + return catalogs; } @Override @@ -739,6 +785,7 @@ List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream(); if (parentPlatforms.size() > 0) { for (ParentPlatform parentPlatform : parentPlatforms) { + streamPushItem.setCatalogId(parentPlatform.getCatalogId()); streamPushItem.setPlatformId(parentPlatform.getServerGBId()); String stream = streamPushItem.getStream(); StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(streamPushItem.getApp(), stream, parentPlatform.getServerGBId()); @@ -804,4 +851,74 @@ return streamProxyMapper.selectOne(app, streamId); } + @Override + public List<PlatformCatalog> getChildrenCatalogByPlatform(String platformId, String parentId) { + return catalogMapper.selectByParentId(platformId, parentId); + } + + @Override + public int addCatalog(PlatformCatalog platformCatalog) { + return catalogMapper.add(platformCatalog); + } + + @Override + public PlatformCatalog getCatalog(String id) { + return catalogMapper.select(id); + } + + @Override + public int delCatalog(String id) { + PlatformCatalog platformCatalog = catalogMapper.select(id); + if (platformCatalog.getChildrenCount() > 0) { + List<PlatformCatalog> platformCatalogList = catalogMapper.selectByParentId(platformCatalog.getPlatformId(), platformCatalog.getId()); + for (PlatformCatalog catalog : platformCatalogList) { + if (catalog.getChildrenCount() == 0) { + catalogMapper.del(catalog.getId()); + platformGbStreamMapper.delByCatalogId(catalog.getId()); + platformChannelMapper.delByCatalogId(catalog.getId()); + }else { + delCatalog(catalog.getId()); + } + } + } + int delresult = catalogMapper.del(id); + int delStreamresult = platformGbStreamMapper.delByCatalogId(id); + int delChanneresult = platformChannelMapper.delByCatalogId(id); + return delresult + delChanneresult + delStreamresult; + } + + @Override + public int updateCatalog(PlatformCatalog platformCatalog) { + return catalogMapper.update(platformCatalog); + } + + @Override + public int setDefaultCatalog(String platformId, String catalogId) { + return platformMapper.setDefaultCatalog(platformId, catalogId); + } + + @Override + public List<PlatformCatalog> queryCatalogInPlatform(String platformId) { + return catalogMapper.selectByPlatForm(platformId); + } + + @Override + public int delRelation(PlatformCatalog platformCatalog) { + if (platformCatalog.getType() == 1) { + return platformChannelMapper.delByCatalogIdAndChannelIdAndPlatformId(platformCatalog); + }else if (platformCatalog.getType() == 2) { + List<GbStream> gbStreams = platformGbStreamMapper.queryChannelInParentPlatformAndCatalog(platformCatalog.getPlatformId(), platformCatalog.getParentId()); + for (GbStream gbStream : gbStreams) { + if (gbStream.getGbId().equals(platformCatalog.getId())) { + return platformGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream()); + } + } + } + return 0; + } + + @Override + public int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfos) { + return gbStreamMapper.updateStreamGPS(gpsMsgInfos); + } } -- Gitblit v1.8.0