From 726963ba772dde3e9bfaf52c7c398c0050ca1859 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 28 十二月 2021 18:54:50 +0800 Subject: [PATCH] 优化通道更新逻辑 --- src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java | 39 ++++++++++++++++++++++++++++++++++++--- 1 files changed, 36 insertions(+), 3 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 a1f9331..1d8d83a 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 @@ -156,7 +156,7 @@ } @Override - public void updateChannels(String deviceId, List<DeviceChannel> channels) { + public int updateChannels(String deviceId, List<DeviceChannel> channels) { List<DeviceChannel> addChannels = new ArrayList<>(); List<DeviceChannel> updateChannels = new ArrayList<>(); HashMap<String, DeviceChannel> channelsInStore = new HashMap<>(); @@ -210,13 +210,47 @@ if (i + limitCount > updateChannels.size()) { toIndex = updateChannels.size(); } - deviceChannelMapper.batchAdd(updateChannels.subList(i, toIndex)); + deviceChannelMapper.batchUpdate(updateChannels.subList(i, toIndex)); } }else { deviceChannelMapper.batchUpdate(updateChannels); } } } + return addChannels.size() + updateChannels.size(); + } + + @Override + public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) { + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + 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) { + int toIndex = i + limitCount; + if (i + limitCount > deviceChannelList.size()) { + toIndex = deviceChannelList.size(); + } + result = result || deviceChannelMapper.batchAdd(deviceChannelList.subList(i, toIndex)) < 0; + } + }else { + result = result || deviceChannelMapper.batchAdd(deviceChannelList) < 0; + } + } + if (result) { + //浜嬪姟鍥炴粴 + dataSourceTransactionManager.rollback(transactionStatus); + } + dataSourceTransactionManager.commit(transactionStatus); //鎵嬪姩鎻愪氦 + return true; + }catch (Exception e) { + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } + } @Override @@ -711,7 +745,6 @@ if (streamProxyItems == null) { platformGbStreamMapper.add(streamPushItem); } - } } } -- Gitblit v1.8.0