Commit 2d423d9668312fe75986af3c78c0228ce352e48d

Authored by 648540858
2 parents a6fb1cdb d05bce8f

Merge branch 'xinchuang' into wvp-28181-2.0

src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
@@ -141,7 +141,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @@ -141,7 +141,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
141 } 141 }
142 } 142 }
143 } 143 }
144 - int limitCount = 300; 144 + int limitCount = 50;
145 if (addChannels.size() > 0) { 145 if (addChannels.size() > 0) {
146 if (addChannels.size() > limitCount) { 146 if (addChannels.size() > limitCount) {
147 for (int i = 0; i < addChannels.size(); i += limitCount) { 147 for (int i = 0; i < addChannels.size(); i += limitCount) {
@@ -199,7 +199,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @@ -199,7 +199,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
199 deviceChannel.setUpdateTime(now); 199 deviceChannel.setUpdateTime(now);
200 result.add(updateGps(deviceChannel, device)); 200 result.add(updateGps(deviceChannel, device));
201 }); 201 });
202 - int limitCount = 300; 202 + int limitCount = 50;
203 if (result.size() > limitCount) { 203 if (result.size() > limitCount) {
204 for (int i = 0; i < result.size(); i += limitCount) { 204 for (int i = 0; i < result.size(); i += limitCount) {
205 int toIndex = i + limitCount; 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,7 +82,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
82 int allCount = 0; 82 int allCount = 0;
83 boolean result = false; 83 boolean result = false;
84 TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); 84 TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
85 - int limitCount = 300; 85 + int limitCount = 50;
86 if (channelReducesToAdd.size() > 0) { 86 if (channelReducesToAdd.size() > 0) {
87 if (channelReducesToAdd.size() > limitCount) { 87 if (channelReducesToAdd.size() > limitCount) {
88 for (int i = 0; i < channelReducesToAdd.size(); i += limitCount) { 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,7 +14,7 @@ import java.util.List;
14 @Repository 14 @Repository
15 public interface GbStreamMapper { 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 "longitude, latitude, stream_type,media_server_id,create_time) VALUES" + 18 "longitude, latitude, stream_type,media_server_id,create_time) VALUES" +
19 "(#{app}, #{stream}, #{gbId}, #{name}, " + 19 "(#{app}, #{stream}, #{gbId}, #{name}, " +
20 "#{longitude}, #{latitude}, #{streamType}, " + 20 "#{longitude}, #{latitude}, #{streamType}, " +
src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformGbStreamMapper.java
@@ -16,7 +16,7 @@ import java.util.List; @@ -16,7 +16,7 @@ import java.util.List;
16 @Repository 16 @Repository
17 public interface PlatformGbStreamMapper { 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 "( #{gbStreamId}, #{platformId}, #{catalogId})") 20 "( #{gbStreamId}, #{platformId}, #{catalogId})")
21 int add(PlatformGbStream platformGbStream); 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,9 +186,19 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
186 return false; 186 return false;
187 } 187 }
188 try { 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 boolean result = cleanChannelsResult < 0; 202 boolean result = cleanChannelsResult < 0;
193 if (!result && addChannels.size() > 0) { 203 if (!result && addChannels.size() > 0) {
194 if (addChannels.size() > limitCount) { 204 if (addChannels.size() > limitCount) {
@@ -244,12 +254,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -244,12 +254,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
244 allChannelMap.put(deviceChannel.getChannelId(), deviceChannel); 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 TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); 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 StringBuilder stringBuilder = new StringBuilder(); 263 StringBuilder stringBuilder = new StringBuilder();
254 Map<String, Integer> subContMap = new HashMap<>(); 264 Map<String, Integer> subContMap = new HashMap<>();
255 if (deviceChannelList.size() > 0) { 265 if (deviceChannelList.size() > 0) {
@@ -258,15 +268,24 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -258,15 +268,24 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
258 for (DeviceChannel deviceChannel : deviceChannelList) { 268 for (DeviceChannel deviceChannel : deviceChannelList) {
259 if (!gbIdSet.contains(deviceChannel.getChannelId())) { 269 if (!gbIdSet.contains(deviceChannel.getChannelId())) {
260 gbIdSet.add(deviceChannel.getChannelId()); 270 gbIdSet.add(deviceChannel.getChannelId());
  271 + deviceChannel.setUpdateTime(DateUtil.getNow());
261 if (allChannelMap.containsKey(deviceChannel.getChannelId())) { 272 if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
262 deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId()); 273 deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
263 deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio()); 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 updateChannels.add(deviceChannel); 283 updateChannels.add(deviceChannel);
266 }else { 284 }else {
267 deviceChannel.setCreateTime(DateUtil.getNow()); 285 deviceChannel.setCreateTime(DateUtil.getNow());
268 addChannels.add(deviceChannel); 286 addChannels.add(deviceChannel);
269 } 287 }
  288 + channels.add(deviceChannel);
270 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { 289 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
271 if (subContMap.get(deviceChannel.getParentId()) == null) { 290 if (subContMap.get(deviceChannel.getParentId()) == null) {
272 subContMap.put(deviceChannel.getParentId(), 1); 291 subContMap.put(deviceChannel.getParentId(), 1);
@@ -279,15 +298,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -279,15 +298,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
279 stringBuilder.append(deviceChannel.getChannelId()).append(","); 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 if (subContMap.get(channel.getChannelId()) != null){ 303 if (subContMap.get(channel.getChannelId()) != null){
292 channel.setSubCount(subContMap.get(channel.getChannelId())); 304 channel.setSubCount(subContMap.get(channel.getChannelId()));
293 } 305 }
@@ -298,12 +310,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -298,12 +310,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
298 if (stringBuilder.length() > 0) { 310 if (stringBuilder.length() > 0) {
299 logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder); 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 return false; 315 return false;
304 } 316 }
305 try { 317 try {
306 - int limitCount = 300; 318 + int limitCount = 50;
307 boolean result = false; 319 boolean result = false;
308 if (addChannels.size() > 0) { 320 if (addChannels.size() > 0) {
309 if (addChannels.size() > limitCount) { 321 if (addChannels.size() > limitCount) {
@@ -312,10 +324,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -312,10 +324,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
312 if (i + limitCount > addChannels.size()) { 324 if (i + limitCount > addChannels.size()) {
313 toIndex = addChannels.size(); 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 }else { 329 }else {
318 - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0; 330 + result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
319 } 331 }
320 } 332 }
321 if (updateChannels.size() > 0) { 333 if (updateChannels.size() > 0) {
@@ -331,13 +343,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -331,13 +343,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
331 result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; 343 result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0;
332 } 344 }
333 } 345 }
  346 +
334 if (result) { 347 if (result) {
335 //事务回滚 348 //事务回滚
336 dataSourceTransactionManager.rollback(transactionStatus); 349 dataSourceTransactionManager.rollback(transactionStatus);
337 - }else {  
338 - //手动提交  
339 - dataSourceTransactionManager.commit(transactionStatus);  
340 } 350 }
  351 + dataSourceTransactionManager.commit(transactionStatus); //手动提交
341 return true; 352 return true;
342 }catch (Exception e) { 353 }catch (Exception e) {
343 logger.error("未处理的异常 ", e); 354 logger.error("未处理的异常 ", e);