Commit 2d423d9668312fe75986af3c78c0228ce352e48d
Merge branch 'xinchuang' into wvp-28181-2.0
Showing
5 changed files
with
41 additions
and
30 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
| ... | ... | @@ -141,7 +141,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | - int limitCount = 300; | |
| 144 | + int limitCount = 50; | |
| 145 | 145 | if (addChannels.size() > 0) { |
| 146 | 146 | if (addChannels.size() > limitCount) { |
| 147 | 147 | for (int i = 0; i < addChannels.size(); i += limitCount) { |
| ... | ... | @@ -199,7 +199,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { |
| 199 | 199 | deviceChannel.setUpdateTime(now); |
| 200 | 200 | result.add(updateGps(deviceChannel, device)); |
| 201 | 201 | }); |
| 202 | - int limitCount = 300; | |
| 202 | + int limitCount = 50; | |
| 203 | 203 | if (result.size() > limitCount) { |
| 204 | 204 | for (int i = 0; i < result.size(); i += limitCount) { |
| 205 | 205 | int toIndex = i + limitCount; | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java
| ... | ... | @@ -82,7 +82,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { |
| 82 | 82 | int allCount = 0; |
| 83 | 83 | boolean result = false; |
| 84 | 84 | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| 85 | - int limitCount = 300; | |
| 85 | + int limitCount = 50; | |
| 86 | 86 | if (channelReducesToAdd.size() > 0) { |
| 87 | 87 | if (channelReducesToAdd.size() > limitCount) { |
| 88 | 88 | for (int i = 0; i < channelReducesToAdd.size(); i += limitCount) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java
| ... | ... | @@ -14,7 +14,7 @@ import java.util.List; |
| 14 | 14 | @Repository |
| 15 | 15 | public interface GbStreamMapper { |
| 16 | 16 | |
| 17 | - @Insert("REPLACE INTO wvp_gb_stream (app, stream, gb_id, name, " + | |
| 17 | + @Insert("INSERT INTO wvp_gb_stream (app, stream, gb_id, name, " + | |
| 18 | 18 | "longitude, latitude, stream_type,media_server_id,create_time) VALUES" + |
| 19 | 19 | "(#{app}, #{stream}, #{gbId}, #{name}, " + |
| 20 | 20 | "#{longitude}, #{latitude}, #{streamType}, " + | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformGbStreamMapper.java
| ... | ... | @@ -16,7 +16,7 @@ import java.util.List; |
| 16 | 16 | @Repository |
| 17 | 17 | public interface PlatformGbStreamMapper { |
| 18 | 18 | |
| 19 | - @Insert("REPLACE INTO wvp_platform_gb_stream (gb_stream_id, platform_id, catalog_id) VALUES" + | |
| 19 | + @Insert("INSERT INTO wvp_platform_gb_stream (gb_stream_id, platform_id, catalog_id) VALUES" + | |
| 20 | 20 | "( #{gbStreamId}, #{platformId}, #{catalogId})") |
| 21 | 21 | int add(PlatformGbStream platformGbStream); |
| 22 | 22 | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
| ... | ... | @@ -186,9 +186,19 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 186 | 186 | return false; |
| 187 | 187 | } |
| 188 | 188 | try { |
| 189 | - int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); | |
| 190 | - | |
| 191 | - int limitCount = 300; | |
| 189 | + int limitCount = 50; | |
| 190 | + int cleanChannelsResult = 0; | |
| 191 | + if (channels.size() > limitCount) { | |
| 192 | + for (int i = 0; i < channels.size(); i += limitCount) { | |
| 193 | + int toIndex = i + limitCount; | |
| 194 | + if (i + limitCount > channels.size()) { | |
| 195 | + toIndex = channels.size(); | |
| 196 | + } | |
| 197 | + cleanChannelsResult += this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels.subList(i, toIndex)); | |
| 198 | + } | |
| 199 | + } else { | |
| 200 | + cleanChannelsResult = this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); | |
| 201 | + } | |
| 192 | 202 | boolean result = cleanChannelsResult < 0; |
| 193 | 203 | if (!result && addChannels.size() > 0) { |
| 194 | 204 | if (addChannels.size() > limitCount) { |
| ... | ... | @@ -244,12 +254,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 244 | 254 | allChannelMap.put(deviceChannel.getChannelId(), deviceChannel); |
| 245 | 255 | } |
| 246 | 256 | } |
| 247 | - List<DeviceChannel> addChannels = new ArrayList<>(); | |
| 248 | - List<DeviceChannel> updateChannels = new ArrayList<>(); | |
| 249 | - | |
| 250 | - | |
| 251 | 257 | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| 252 | 258 | // 数据去重 |
| 259 | + List<DeviceChannel> channels = new ArrayList<>(); | |
| 260 | + | |
| 261 | + List<DeviceChannel> updateChannels = new ArrayList<>(); | |
| 262 | + List<DeviceChannel> addChannels = new ArrayList<>(); | |
| 253 | 263 | StringBuilder stringBuilder = new StringBuilder(); |
| 254 | 264 | Map<String, Integer> subContMap = new HashMap<>(); |
| 255 | 265 | if (deviceChannelList.size() > 0) { |
| ... | ... | @@ -258,15 +268,24 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 258 | 268 | for (DeviceChannel deviceChannel : deviceChannelList) { |
| 259 | 269 | if (!gbIdSet.contains(deviceChannel.getChannelId())) { |
| 260 | 270 | gbIdSet.add(deviceChannel.getChannelId()); |
| 271 | + deviceChannel.setUpdateTime(DateUtil.getNow()); | |
| 261 | 272 | if (allChannelMap.containsKey(deviceChannel.getChannelId())) { |
| 262 | 273 | deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId()); |
| 263 | 274 | deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio()); |
| 264 | - deviceChannel.setUpdateTime(DateUtil.getNow()); | |
| 275 | + if (allChannelMap.get(deviceChannel.getChannelId()).isStatus() !=deviceChannel.isStatus()){ | |
| 276 | + List<String> strings = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getChannelId()); | |
| 277 | + if (!CollectionUtils.isEmpty(strings)){ | |
| 278 | + strings.forEach(platformId->{ | |
| 279 | + eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.isStatus()?CatalogEvent.ON:CatalogEvent.OFF); | |
| 280 | + }); | |
| 281 | + } | |
| 282 | + } | |
| 265 | 283 | updateChannels.add(deviceChannel); |
| 266 | 284 | }else { |
| 267 | 285 | deviceChannel.setCreateTime(DateUtil.getNow()); |
| 268 | 286 | addChannels.add(deviceChannel); |
| 269 | 287 | } |
| 288 | + channels.add(deviceChannel); | |
| 270 | 289 | if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { |
| 271 | 290 | if (subContMap.get(deviceChannel.getParentId()) == null) { |
| 272 | 291 | subContMap.put(deviceChannel.getParentId(), 1); |
| ... | ... | @@ -279,15 +298,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 279 | 298 | stringBuilder.append(deviceChannel.getChannelId()).append(","); |
| 280 | 299 | } |
| 281 | 300 | } |
| 282 | - if (addChannels.size() > 0) { | |
| 283 | - for (DeviceChannel channel : addChannels) { | |
| 284 | - if (subContMap.get(channel.getChannelId()) != null){ | |
| 285 | - channel.setSubCount(subContMap.get(channel.getChannelId())); | |
| 286 | - } | |
| 287 | - } | |
| 288 | - } | |
| 289 | - if (updateChannels.size() > 0) { | |
| 290 | - for (DeviceChannel channel : updateChannels) { | |
| 301 | + if (channels.size() > 0) { | |
| 302 | + for (DeviceChannel channel : channels) { | |
| 291 | 303 | if (subContMap.get(channel.getChannelId()) != null){ |
| 292 | 304 | channel.setSubCount(subContMap.get(channel.getChannelId())); |
| 293 | 305 | } |
| ... | ... | @@ -298,12 +310,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 298 | 310 | if (stringBuilder.length() > 0) { |
| 299 | 311 | logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder); |
| 300 | 312 | } |
| 301 | - if(CollectionUtils.isEmpty(updateChannels) && CollectionUtils.isEmpty(addChannels) ){ | |
| 302 | - logger.info("通道更新,数据为空={}" , deviceChannelList); | |
| 313 | + if(CollectionUtils.isEmpty(channels)){ | |
| 314 | + logger.info("通道重设,数据为空={}" , deviceChannelList); | |
| 303 | 315 | return false; |
| 304 | 316 | } |
| 305 | 317 | try { |
| 306 | - int limitCount = 300; | |
| 318 | + int limitCount = 50; | |
| 307 | 319 | boolean result = false; |
| 308 | 320 | if (addChannels.size() > 0) { |
| 309 | 321 | if (addChannels.size() > limitCount) { |
| ... | ... | @@ -312,10 +324,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 312 | 324 | if (i + limitCount > addChannels.size()) { |
| 313 | 325 | toIndex = addChannels.size(); |
| 314 | 326 | } |
| 315 | - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels.subList(i, toIndex)) < 0; | |
| 327 | + result = result || deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0; | |
| 316 | 328 | } |
| 317 | 329 | }else { |
| 318 | - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0; | |
| 330 | + result = result || deviceChannelMapper.batchAdd(addChannels) < 0; | |
| 319 | 331 | } |
| 320 | 332 | } |
| 321 | 333 | if (updateChannels.size() > 0) { |
| ... | ... | @@ -331,13 +343,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 331 | 343 | result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; |
| 332 | 344 | } |
| 333 | 345 | } |
| 346 | + | |
| 334 | 347 | if (result) { |
| 335 | 348 | //事务回滚 |
| 336 | 349 | dataSourceTransactionManager.rollback(transactionStatus); |
| 337 | - }else { | |
| 338 | - //手动提交 | |
| 339 | - dataSourceTransactionManager.commit(transactionStatus); | |
| 340 | 350 | } |
| 351 | + dataSourceTransactionManager.commit(transactionStatus); //手动提交 | |
| 341 | 352 | return true; |
| 342 | 353 | }catch (Exception e) { |
| 343 | 354 | logger.error("未处理的异常 ", e); | ... | ... |