From 12c4128e814d4bae84608172ccc92f6a66aa2254 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 13 Oct 2023 15:44:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=AE=E5=BD=95=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E5=B7=B2=E5=88=A0=E9=99=A4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E6=95=B4=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/VideoManagerStorageImpl.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 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 d4062255..af9454d2 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 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { List updateChannels = new ArrayList<>(); List addChannels = new ArrayList<>(); + List deleteChannels = new ArrayList<>(); StringBuilder stringBuilder = new StringBuilder(); Map subContMap = new HashMap<>(); @@ -159,6 +160,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { 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,6 +171,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { } } } + deleteChannels.addAll(allChannelMap.values()); if (!channels.isEmpty()) { for (DeviceChannel channel : channels) { if (subContMap.get(channel.getChannelId()) != null){ @@ -191,7 +194,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { try { int limitCount = 50; boolean result = false; - if (!result && addChannels.size() > 0) { + if (!result && !addChannels.isEmpty()) { if (addChannels.size() > limitCount) { for (int i = 0; i < addChannels.size(); i += limitCount) { int toIndex = i + limitCount; @@ -204,7 +207,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { 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; @@ -217,6 +220,20 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { 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) { //事务回滚