Commit 90d9cd8ac8d7575d1cbd6e81ff6ed746ee82289f

Authored by xu-bin-bin
Committed by GitHub
2 parents 124d83fc 12c4128e

Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0

src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -129,6 +129,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -129,6 +129,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
129 129
130 List<DeviceChannel> updateChannels = new ArrayList<>(); 130 List<DeviceChannel> updateChannels = new ArrayList<>();
131 List<DeviceChannel> addChannels = new ArrayList<>(); 131 List<DeviceChannel> addChannels = new ArrayList<>();
  132 + List<DeviceChannel> deleteChannels = new ArrayList<>();
132 StringBuilder stringBuilder = new StringBuilder(); 133 StringBuilder stringBuilder = new StringBuilder();
133 Map<String, Integer> subContMap = new HashMap<>(); 134 Map<String, Integer> subContMap = new HashMap<>();
134 135
@@ -159,6 +160,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -159,6 +160,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
159 deviceChannel.setUpdateTime(DateUtil.getNow()); 160 deviceChannel.setUpdateTime(DateUtil.getNow());
160 addChannels.add(deviceChannel); 161 addChannels.add(deviceChannel);
161 } 162 }
  163 + allChannelMap.remove(deviceChannel.getChannelId());
162 channels.add(deviceChannel); 164 channels.add(deviceChannel);
163 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { 165 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
164 if (subContMap.get(deviceChannel.getParentId()) == null) { 166 if (subContMap.get(deviceChannel.getParentId()) == null) {
@@ -169,6 +171,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -169,6 +171,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
169 } 171 }
170 } 172 }
171 } 173 }
  174 + deleteChannels.addAll(allChannelMap.values());
172 if (!channels.isEmpty()) { 175 if (!channels.isEmpty()) {
173 for (DeviceChannel channel : channels) { 176 for (DeviceChannel channel : channels) {
174 if (subContMap.get(channel.getChannelId()) != null){ 177 if (subContMap.get(channel.getChannelId()) != null){
@@ -191,7 +194,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -191,7 +194,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
191 try { 194 try {
192 int limitCount = 50; 195 int limitCount = 50;
193 boolean result = false; 196 boolean result = false;
194 - if (!result && addChannels.size() > 0) { 197 + if (!result && !addChannels.isEmpty()) {
195 if (addChannels.size() > limitCount) { 198 if (addChannels.size() > limitCount) {
196 for (int i = 0; i < addChannels.size(); i += limitCount) { 199 for (int i = 0; i < addChannels.size(); i += limitCount) {
197 int toIndex = i + limitCount; 200 int toIndex = i + limitCount;
@@ -204,7 +207,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -204,7 +207,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
204 result = result || deviceChannelMapper.batchAdd(addChannels) < 0; 207 result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
205 } 208 }
206 } 209 }
207 - if (!result && updateChannels.size() > 0) { 210 + if (!result && !updateChannels.isEmpty()) {
208 if (updateChannels.size() > limitCount) { 211 if (updateChannels.size() > limitCount) {
209 for (int i = 0; i < updateChannels.size(); i += limitCount) { 212 for (int i = 0; i < updateChannels.size(); i += limitCount) {
210 int toIndex = i + limitCount; 213 int toIndex = i + limitCount;
@@ -217,6 +220,20 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -217,6 +220,20 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
217 result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; 220 result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0;
218 } 221 }
219 } 222 }
  223 + if (!result && !deleteChannels.isEmpty()) {
  224 + System.out.println("删除: " + deleteChannels.size());
  225 + if (deleteChannels.size() > limitCount) {
  226 + for (int i = 0; i < deleteChannels.size(); i += limitCount) {
  227 + int toIndex = i + limitCount;
  228 + if (i + limitCount > deleteChannels.size()) {
  229 + toIndex = deleteChannels.size();
  230 + }
  231 + result = result || deviceChannelMapper.batchDel(deleteChannels.subList(i, toIndex)) < 0;
  232 + }
  233 + }else {
  234 + result = result || deviceChannelMapper.batchDel(deleteChannels) < 0;
  235 + }
  236 + }
220 237
221 if (result) { 238 if (result) {
222 //事务回滚 239 //事务回滚