From 18a9f86a0af4863f1ec19b53d88ed2bcd46e37a7 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期一, 18 十二月 2023 09:59:06 +0800 Subject: [PATCH] Merge pull request #1209 from DavidSche/fix-1208 --- src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java | 37 +++++++++++++++++++++---------------- 1 files changed, 21 insertions(+), 16 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 e96e09b..af9454d 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 @@ -129,6 +129,7 @@ List<DeviceChannel> updateChannels = new ArrayList<>(); List<DeviceChannel> addChannels = new ArrayList<>(); + List<DeviceChannel> deleteChannels = new ArrayList<>(); StringBuilder stringBuilder = new StringBuilder(); Map<String, Integer> subContMap = new HashMap<>(); @@ -159,6 +160,7 @@ deviceChannel.setUpdateTime(DateUtil.getNow()); addChannels.add(deviceChannel); } + allChannelMap.remove(deviceChannel.getChannelId()); channels.add(deviceChannel); if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { if (subContMap.get(deviceChannel.getParentId()) == null) { @@ -169,7 +171,8 @@ } } } - if (channels.size() > 0) { + deleteChannels.addAll(allChannelMap.values()); + if (!channels.isEmpty()) { for (DeviceChannel channel : channels) { if (subContMap.get(channel.getChannelId()) != null){ Integer count = subContMap.get(channel.getChannelId()); @@ -190,20 +193,8 @@ } try { 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) { + boolean result = false; + if (!result && !addChannels.isEmpty()) { if (addChannels.size() > limitCount) { for (int i = 0; i < addChannels.size(); i += limitCount) { int toIndex = i + limitCount; @@ -216,7 +207,7 @@ result = result || deviceChannelMapper.batchAdd(addChannels) < 0; } } - if (!result && updateChannels.size() > 0) { + if (!result && !updateChannels.isEmpty()) { if (updateChannels.size() > limitCount) { for (int i = 0; i < updateChannels.size(); i += limitCount) { int toIndex = i + limitCount; @@ -229,6 +220,20 @@ result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; } } + if (!result && !deleteChannels.isEmpty()) { + System.out.println("鍒犻櫎锛� " + deleteChannels.size()); + if (deleteChannels.size() > limitCount) { + for (int i = 0; i < deleteChannels.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > deleteChannels.size()) { + toIndex = deleteChannels.size(); + } + result = result || deviceChannelMapper.batchDel(deleteChannels.subList(i, toIndex)) < 0; + } + }else { + result = result || deviceChannelMapper.batchDel(deleteChannels) < 0; + } + } if (result) { //浜嬪姟鍥炴粴 -- Gitblit v1.8.0