Commit d05bce8f7ffb58fe6c9d386b96816b842d6c898d

Authored by 648540858
1 parent 5b8ffd5b

修复对接金仓数据库中的问题

src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
@@ -50,8 +50,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @@ -50,8 +50,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
50 device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId()); 50 device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId());
51 } 51 }
52 52
53 -  
54 -  
55 if ("WGS84".equals(device.getGeoCoordSys())) { 53 if ("WGS84".equals(device.getGeoCoordSys())) {
56 deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); 54 deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());
57 deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); 55 deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());
@@ -143,7 +141,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @@ -143,7 +141,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
143 } 141 }
144 } 142 }
145 } 143 }
146 - int limitCount = 300; 144 + int limitCount = 50;
147 if (addChannels.size() > 0) { 145 if (addChannels.size() > 0) {
148 if (addChannels.size() > limitCount) { 146 if (addChannels.size() > limitCount) {
149 for (int i = 0; i < addChannels.size(); i += limitCount) { 147 for (int i = 0; i < addChannels.size(); i += limitCount) {
@@ -201,7 +199,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @@ -201,7 +199,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
201 deviceChannel.setUpdateTime(now); 199 deviceChannel.setUpdateTime(now);
202 result.add(updateGps(deviceChannel, device)); 200 result.add(updateGps(deviceChannel, device));
203 }); 201 });
204 - int limitCount = 300; 202 + int limitCount = 50;
205 if (result.size() > limitCount) { 203 if (result.size() > limitCount) {
206 for (int i = 0; i < result.size(); i += limitCount) { 204 for (int i = 0; i < result.size(); i += limitCount) {
207 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
@@ -181,9 +181,19 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -181,9 +181,19 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
181 return false; 181 return false;
182 } 182 }
183 try { 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 boolean result = cleanChannelsResult < 0; 197 boolean result = cleanChannelsResult < 0;
188 if (!result && addChannels.size() > 0) { 198 if (!result && addChannels.size() > 0) {
189 if (addChannels.size() > limitCount) { 199 if (addChannels.size() > limitCount) {
@@ -239,12 +249,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -239,12 +249,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
239 allChannelMap.put(deviceChannel.getChannelId(), deviceChannel); 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 TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); 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 StringBuilder stringBuilder = new StringBuilder(); 258 StringBuilder stringBuilder = new StringBuilder();
249 Map<String, Integer> subContMap = new HashMap<>(); 259 Map<String, Integer> subContMap = new HashMap<>();
250 if (deviceChannelList.size() > 0) { 260 if (deviceChannelList.size() > 0) {
@@ -253,15 +263,24 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -253,15 +263,24 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
253 for (DeviceChannel deviceChannel : deviceChannelList) { 263 for (DeviceChannel deviceChannel : deviceChannelList) {
254 if (!gbIdSet.contains(deviceChannel.getChannelId())) { 264 if (!gbIdSet.contains(deviceChannel.getChannelId())) {
255 gbIdSet.add(deviceChannel.getChannelId()); 265 gbIdSet.add(deviceChannel.getChannelId());
  266 + deviceChannel.setUpdateTime(DateUtil.getNow());
256 if (allChannelMap.containsKey(deviceChannel.getChannelId())) { 267 if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
257 deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId()); 268 deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
258 deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio()); 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 updateChannels.add(deviceChannel); 278 updateChannels.add(deviceChannel);
261 }else { 279 }else {
262 deviceChannel.setCreateTime(DateUtil.getNow()); 280 deviceChannel.setCreateTime(DateUtil.getNow());
263 addChannels.add(deviceChannel); 281 addChannels.add(deviceChannel);
264 } 282 }
  283 + channels.add(deviceChannel);
265 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) { 284 if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
266 if (subContMap.get(deviceChannel.getParentId()) == null) { 285 if (subContMap.get(deviceChannel.getParentId()) == null) {
267 subContMap.put(deviceChannel.getParentId(), 1); 286 subContMap.put(deviceChannel.getParentId(), 1);
@@ -274,15 +293,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -274,15 +293,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
274 stringBuilder.append(deviceChannel.getChannelId()).append(","); 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 if (subContMap.get(channel.getChannelId()) != null){ 298 if (subContMap.get(channel.getChannelId()) != null){
287 channel.setSubCount(subContMap.get(channel.getChannelId())); 299 channel.setSubCount(subContMap.get(channel.getChannelId()));
288 } 300 }
@@ -293,12 +305,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -293,12 +305,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
293 if (stringBuilder.length() > 0) { 305 if (stringBuilder.length() > 0) {
294 logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder); 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 return false; 310 return false;
299 } 311 }
300 try { 312 try {
301 - int limitCount = 300; 313 + int limitCount = 50;
302 boolean result = false; 314 boolean result = false;
303 if (addChannels.size() > 0) { 315 if (addChannels.size() > 0) {
304 if (addChannels.size() > limitCount) { 316 if (addChannels.size() > limitCount) {
@@ -307,10 +319,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -307,10 +319,10 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
307 if (i + limitCount > addChannels.size()) { 319 if (i + limitCount > addChannels.size()) {
308 toIndex = addChannels.size(); 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 }else { 324 }else {
313 - result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0; 325 + result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
314 } 326 }
315 } 327 }
316 if (updateChannels.size() > 0) { 328 if (updateChannels.size() > 0) {
@@ -326,13 +338,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -326,13 +338,12 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
326 result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0; 338 result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0;
327 } 339 }
328 } 340 }
  341 +
329 if (result) { 342 if (result) {
330 //事务回滚 343 //事务回滚
331 dataSourceTransactionManager.rollback(transactionStatus); 344 dataSourceTransactionManager.rollback(transactionStatus);
332 - }else {  
333 - //手动提交  
334 - dataSourceTransactionManager.commit(transactionStatus);  
335 } 345 }
  346 + dataSourceTransactionManager.commit(transactionStatus); //手动提交
336 return true; 347 return true;
337 }catch (Exception e) { 348 }catch (Exception e) {
338 logger.error("未处理的异常 ", e); 349 logger.error("未处理的异常 ", e);