Commit d05bce8f7ffb58fe6c9d386b96816b842d6c898d
1 parent
5b8ffd5b
修复对接金仓数据库中的问题
Showing
5 changed files
with
41 additions
and
32 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
| ... | ... | @@ -50,8 +50,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { |
| 50 | 50 | device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId()); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - | |
| 54 | - | |
| 55 | 53 | if ("WGS84".equals(device.getGeoCoordSys())) { |
| 56 | 54 | deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); |
| 57 | 55 | deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); |
| ... | ... | @@ -143,7 +141,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { |
| 143 | 141 | } |
| 144 | 142 | } |
| 145 | 143 | } |
| 146 | - int limitCount = 300; | |
| 144 | + int limitCount = 50; | |
| 147 | 145 | if (addChannels.size() > 0) { |
| 148 | 146 | if (addChannels.size() > limitCount) { |
| 149 | 147 | for (int i = 0; i < addChannels.size(); i += limitCount) { |
| ... | ... | @@ -201,7 +199,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { |
| 201 | 199 | deviceChannel.setUpdateTime(now); |
| 202 | 200 | result.add(updateGps(deviceChannel, device)); |
| 203 | 201 | }); |
| 204 | - int limitCount = 300; | |
| 202 | + int limitCount = 50; | |
| 205 | 203 | if (result.size() > limitCount) { |
| 206 | 204 | for (int i = 0; i < result.size(); i += limitCount) { |
| 207 | 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
| ... | ... | @@ -181,9 +181,19 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | 183 | try { |
| 184 | - int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); | |
| 185 | - | |
| 186 | - int limitCount = 300; | |
| 184 | + int limitCount = 50; | |
| 185 | + int cleanChannelsResult = 0; | |
| 186 | + if (channels.size() > limitCount) { | |
| 187 | + for (int i = 0; i < channels.size(); i += limitCount) { | |
| 188 | + int toIndex = i + limitCount; | |
| 189 | + if (i + limitCount > channels.size()) { | |
| 190 | + toIndex = channels.size(); | |
| 191 | + } | |
| 192 | + cleanChannelsResult += this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels.subList(i, toIndex)); | |
| 193 | + } | |
| 194 | + } else { | |
| 195 | + cleanChannelsResult = this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); | |
| 196 | + } | |
| 187 | 197 | boolean result = cleanChannelsResult < 0; |
| 188 | 198 | if (!result && addChannels.size() > 0) { |
| 189 | 199 | if (addChannels.size() > limitCount) { |
| ... | ... | @@ -239,12 +249,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 239 | 249 | allChannelMap.put(deviceChannel.getChannelId(), deviceChannel); |
| 240 | 250 | } |
| 241 | 251 | } |
| 242 | - List<DeviceChannel> addChannels = new ArrayList<>(); | |
| 243 | - List<DeviceChannel> updateChannels = new ArrayList<>(); | |
| 244 | - | |
| 245 | - | |
| 246 | 252 | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| 247 | 253 | // 数据去重 |
| 254 | + List<DeviceChannel> channels = new ArrayList<>(); | |
| 255 | + | |
| 256 | + List<DeviceChannel> updateChannels = new ArrayList<>(); | |
| 257 | + List<DeviceChannel> addChannels = new ArrayList<>(); | |
| 248 | 258 | StringBuilder stringBuilder = new StringBuilder(); |
| 249 | 259 | Map<String, Integer> subContMap = new HashMap<>(); |
| 250 | 260 | if (deviceChannelList.size() > 0) { |
| ... | ... | @@ -253,15 +263,24 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 253 | 263 | for (DeviceChannel deviceChannel : deviceChannelList) { |
| 254 | 264 | if (!gbIdSet.contains(deviceChannel.getChannelId())) { |
| 255 | 265 | gbIdSet.add(deviceChannel.getChannelId()); |
| 266 | + deviceChannel.setUpdateTime(DateUtil.getNow()); | |
| 256 | 267 | if (allChannelMap.containsKey(deviceChannel.getChannelId())) { |
| 257 | 268 | deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId()); |
| 258 | 269 | deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio()); |
| 259 | - deviceChannel.setUpdateTime(DateUtil.getNow()); | |
| 270 | + if (allChannelMap.get(deviceChannel.getChannelId()).isStatus() !=deviceChannel.isStatus()){ | |
| 271 | + List<String> strings = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getChannelId()); | |
| 272 | + if (!CollectionUtils.isEmpty(strings)){ | |
| 273 | + strings.forEach(platformId->{ | |
| 274 | + eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.isStatus()?CatalogEvent.ON:CatalogEvent.OFF); | |
| 275 | + }); | |
| 276 | + } | |
| 277 | + } | |
| 260 | 278 | updateChannels.add(deviceChannel); |
| 261 | 279 | }else { |
| 262 | 280 | deviceChannel.setCreateTime(DateUtil.getNow()); |
| 263 | 281 | addChannels.add(deviceChannel); |
| 264 | 282 | } |
| 283 | + channels.add(deviceChannel); | |
| 265 | 284 | if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { |
| 266 | 285 | if (subContMap.get(deviceChannel.getParentId()) == null) { |
| 267 | 286 | subContMap.put(deviceChannel.getParentId(), 1); |
| ... | ... | @@ -274,15 +293,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 274 | 293 | stringBuilder.append(deviceChannel.getChannelId()).append(","); |
| 275 | 294 | } |
| 276 | 295 | } |
| 277 | - if (addChannels.size() > 0) { | |
| 278 | - for (DeviceChannel channel : addChannels) { | |
| 279 | - if (subContMap.get(channel.getChannelId()) != null){ | |
| 280 | - channel.setSubCount(subContMap.get(channel.getChannelId())); | |
| 281 | - } | |
| 282 | - } | |
| 283 | - } | |
| 284 | - if (updateChannels.size() > 0) { | |
| 285 | - for (DeviceChannel channel : updateChannels) { | |
| 296 | + if (channels.size() > 0) { | |
| 297 | + for (DeviceChannel channel : channels) { | |
| 286 | 298 | if (subContMap.get(channel.getChannelId()) != null){ |
| 287 | 299 | channel.setSubCount(subContMap.get(channel.getChannelId())); |
| 288 | 300 | } |
| ... | ... | @@ -293,12 +305,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 293 | 305 | if (stringBuilder.length() > 0) { |
| 294 | 306 | logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder); |
| 295 | 307 | } |
| 296 | - if(CollectionUtils.isEmpty(updateChannels) && CollectionUtils.isEmpty(addChannels) ){ | |
| 297 | - logger.info("通道更新,数据为空={}" , deviceChannelList); | |
| 308 | + if(CollectionUtils.isEmpty(channels)){ | |
| 309 | + logger.info("通道重设,数据为空={}" , deviceChannelList); | |
| 298 | 310 | return false; |
| 299 | 311 | } |
| 300 | 312 | try { |
| 301 | - int limitCount = 300; | |
| 313 | + int limitCount = 50; | |
| 302 | 314 | boolean result = false; |
| 303 | 315 | if (addChannels.size() > 0) { |
| 304 | 316 | if (addChannels.size() > limitCount) { |
| ... | ... | @@ -307,10 +319,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 307 | 319 | if (i + limitCount > addChannels.size()) { |
| 308 | 320 | toIndex = addChannels.size(); |
| 309 | 321 | } |
| 310 | - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels.subList(i, toIndex)) < 0; | |
| 322 | + result = result || deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0; | |
| 311 | 323 | } |
| 312 | 324 | }else { |
| 313 | - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0; | |
| 325 | + result = result || deviceChannelMapper.batchAdd(addChannels) < 0; | |
| 314 | 326 | } |
| 315 | 327 | } |
| 316 | 328 | if (updateChannels.size() > 0) { |
| ... | ... | @@ -326,13 +338,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { |
| 326 | 338 | result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; |
| 327 | 339 | } |
| 328 | 340 | } |
| 341 | + | |
| 329 | 342 | if (result) { |
| 330 | 343 | //事务回滚 |
| 331 | 344 | dataSourceTransactionManager.rollback(transactionStatus); |
| 332 | - }else { | |
| 333 | - //手动提交 | |
| 334 | - dataSourceTransactionManager.commit(transactionStatus); | |
| 335 | 345 | } |
| 346 | + dataSourceTransactionManager.commit(transactionStatus); //手动提交 | |
| 336 | 347 | return true; |
| 337 | 348 | }catch (Exception e) { |
| 338 | 349 | logger.error("未处理的异常 ", e); | ... | ... |