Commit 14d554987685d7a8cfef0b95edca6c7d744c6a53

Authored by 648540858
2 parents 2673fbb0 12c4128e

Merge branch 'wvp-28181-2.0' into main-dev

src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
... ... @@ -124,6 +124,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
124 124  
125 125 List<DeviceChannel> updateChannels = new ArrayList<>();
126 126 List<DeviceChannel> addChannels = new ArrayList<>();
  127 + List<DeviceChannel> deleteChannels = new ArrayList<>();
127 128 StringBuilder stringBuilder = new StringBuilder();
128 129 Map<String, Integer> subContMap = new HashMap<>();
129 130  
... ... @@ -154,6 +155,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
154 155 deviceChannel.setUpdateTime(DateUtil.getNow());
155 156 addChannels.add(deviceChannel);
156 157 }
  158 + allChannelMap.remove(deviceChannel.getChannelId());
157 159 channels.add(deviceChannel);
158 160 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
159 161 if (subContMap.get(deviceChannel.getParentId()) == null) {
... ... @@ -164,6 +166,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
164 166 }
165 167 }
166 168 }
  169 + deleteChannels.addAll(allChannelMap.values());
167 170 if (!channels.isEmpty()) {
168 171 for (DeviceChannel channel : channels) {
169 172 if (subContMap.get(channel.getChannelId()) != null){
... ... @@ -186,7 +189,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
186 189 try {
187 190 int limitCount = 50;
188 191 boolean result = false;
189   - if (!result && addChannels.size() > 0) {
  192 + if (!result && !addChannels.isEmpty()) {
190 193 if (addChannels.size() > limitCount) {
191 194 for (int i = 0; i < addChannels.size(); i += limitCount) {
192 195 int toIndex = i + limitCount;
... ... @@ -199,7 +202,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
199 202 result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
200 203 }
201 204 }
202   - if (!result && updateChannels.size() > 0) {
  205 + if (!result && !updateChannels.isEmpty()) {
203 206 if (updateChannels.size() > limitCount) {
204 207 for (int i = 0; i < updateChannels.size(); i += limitCount) {
205 208 int toIndex = i + limitCount;
... ... @@ -212,6 +215,20 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
212 215 result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0;
213 216 }
214 217 }
  218 + if (!result && !deleteChannels.isEmpty()) {
  219 + System.out.println("删除: " + deleteChannels.size());
  220 + if (deleteChannels.size() > limitCount) {
  221 + for (int i = 0; i < deleteChannels.size(); i += limitCount) {
  222 + int toIndex = i + limitCount;
  223 + if (i + limitCount > deleteChannels.size()) {
  224 + toIndex = deleteChannels.size();
  225 + }
  226 + result = result || deviceChannelMapper.batchDel(deleteChannels.subList(i, toIndex)) < 0;
  227 + }
  228 + }else {
  229 + result = result || deviceChannelMapper.batchDel(deleteChannels) < 0;
  230 + }
  231 + }
215 232  
216 233 if (result) {
217 234 //事务回滚
... ...