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 129  
130 130 List<DeviceChannel> updateChannels = new ArrayList<>();
131 131 List<DeviceChannel> addChannels = new ArrayList<>();
  132 + List<DeviceChannel> deleteChannels = new ArrayList<>();
132 133 StringBuilder stringBuilder = new StringBuilder();
133 134 Map<String, Integer> subContMap = new HashMap<>();
134 135  
... ... @@ -159,6 +160,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
159 160 deviceChannel.setUpdateTime(DateUtil.getNow());
160 161 addChannels.add(deviceChannel);
161 162 }
  163 + allChannelMap.remove(deviceChannel.getChannelId());
162 164 channels.add(deviceChannel);
163 165 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
164 166 if (subContMap.get(deviceChannel.getParentId()) == null) {
... ... @@ -169,6 +171,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
169 171 }
170 172 }
171 173 }
  174 + deleteChannels.addAll(allChannelMap.values());
172 175 if (!channels.isEmpty()) {
173 176 for (DeviceChannel channel : channels) {
174 177 if (subContMap.get(channel.getChannelId()) != null){
... ... @@ -191,7 +194,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
191 194 try {
192 195 int limitCount = 50;
193 196 boolean result = false;
194   - if (!result && addChannels.size() > 0) {
  197 + if (!result && !addChannels.isEmpty()) {
195 198 if (addChannels.size() > limitCount) {
196 199 for (int i = 0; i < addChannels.size(); i += limitCount) {
197 200 int toIndex = i + limitCount;
... ... @@ -204,7 +207,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
204 207 result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
205 208 }
206 209 }
207   - if (!result && updateChannels.size() > 0) {
  210 + if (!result && !updateChannels.isEmpty()) {
208 211 if (updateChannels.size() > limitCount) {
209 212 for (int i = 0; i < updateChannels.size(); i += limitCount) {
210 213 int toIndex = i + limitCount;
... ... @@ -217,6 +220,20 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
217 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 238 if (result) {
222 239 //事务回滚
... ...