648540858
2023-06-08 20a47729fc3349df5f08f17d1f8fd5b8db8dcb57
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -14,6 +14,7 @@
import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@@ -122,6 +123,9 @@
      TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
      // 数据去重
      List<DeviceChannel> channels = new ArrayList<>();
      List<DeviceChannel> updateChannels = new ArrayList<>();
      List<DeviceChannel> addChannels = new ArrayList<>();
      StringBuilder stringBuilder = new StringBuilder();
      Map<String, Integer> subContMap = new HashMap<>();
      if (deviceChannelList.size() > 0) {
@@ -130,18 +134,22 @@
         for (DeviceChannel deviceChannel : deviceChannelList) {
            if (!gbIdSet.contains(deviceChannel.getChannelId())) {
               gbIdSet.add(deviceChannel.getChannelId());
               deviceChannel.setUpdateTime(DateUtil.getNow());
               if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
                  deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
                  deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio());
                  if (allChannelMap.get(deviceChannel.getChannelId()).getStatus() !=deviceChannel.getStatus()){
                  if (allChannelMap.get(deviceChannel.getChannelId()).isStatus() !=deviceChannel.isStatus()){
                     List<String> strings = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getChannelId());
                     if (!CollectionUtils.isEmpty(strings)){
                        strings.forEach(platformId->{
                           eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.getStatus()==1?CatalogEvent.ON:CatalogEvent.OFF);
                           eventPublisher.catalogEventPublish(platformId, deviceChannel, deviceChannel.isStatus()?CatalogEvent.ON:CatalogEvent.OFF);
                        });
                     }
                  }
                  updateChannels.add(deviceChannel);
               }else {
                  deviceChannel.setCreateTime(DateUtil.getNow());
                  addChannels.add(deviceChannel);
               }
               channels.add(deviceChannel);
               if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
@@ -174,21 +182,36 @@
      }
      try {
         int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels);
         int limitCount = 300;
         boolean result = cleanChannelsResult < 0;
         if (!result && channels.size() > 0) {
            if (channels.size() > limitCount) {
               for (int i = 0; i < channels.size(); i += limitCount) {
         if (!result && addChannels.size() > 0) {
            if (addChannels.size() > limitCount) {
               for (int i = 0; i < addChannels.size(); i += limitCount) {
                  int toIndex = i + limitCount;
                  if (i + limitCount > channels.size()) {
                     toIndex = channels.size();
                  if (i + limitCount > addChannels.size()) {
                     toIndex = addChannels.size();
                  }
                  result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0;
                  result = result || deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0;
               }
            }else {
               result = result || deviceChannelMapper.batchAdd(channels) < 0;
               result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
            }
         }
         if (!result && updateChannels.size() > 0) {
            if (updateChannels.size() > limitCount) {
               for (int i = 0; i < updateChannels.size(); i += limitCount) {
                  int toIndex = i + limitCount;
                  if (i + limitCount > updateChannels.size()) {
                     toIndex = updateChannels.size();
                  }
                  result = result || deviceChannelMapper.batchUpdate(updateChannels.subList(i, toIndex)) < 0;
               }
            }else {
               result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0;
            }
         }
         if (result) {
            //事务回滚
            dataSourceTransactionManager.rollback(transactionStatus);
@@ -196,7 +219,7 @@
         dataSourceTransactionManager.commit(transactionStatus);     //手动提交
         return true;
      }catch (Exception e) {
         e.printStackTrace();
         logger.error("未处理的异常 ", e);
         dataSourceTransactionManager.rollback(transactionStatus);
         return false;
      }
@@ -284,10 +307,10 @@
                  if (i + limitCount > addChannels.size()) {
                     toIndex = addChannels.size();
                  }
                  result = result || deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex)) < 0;
                  result = result || deviceChannelMapper.batchAddOrUpdate(addChannels.subList(i, toIndex)) < 0;
               }
            }else {
               result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
               result = result || deviceChannelMapper.batchAddOrUpdate(addChannels) < 0;
            }
         }
         if (updateChannels.size() > 0) {
@@ -312,7 +335,7 @@
         }
         return true;
      }catch (Exception e) {
         e.printStackTrace();
         logger.error("未处理的异常 ", e);
         dataSourceTransactionManager.rollback(transactionStatus);
         return false;
      }
@@ -366,14 +389,19 @@
   }
   @Override
   public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit,List<String> channelIds) {
      return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit,channelIds);
   public List<DeviceChannelExtend> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, List<String> channelIds, String query, Boolean hasSubChannel, Boolean online, int start, int limit) {
      return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, channelIds, null, query, hasSubChannel, online, start, limit);
   }
   @Override
   public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds) {
      return deviceChannelMapper.queryChannels(deviceId, null,null, null, online,channelIds);
   }
   @Override
   public List<DeviceChannelExtend> queryChannelsByDeviceId(String deviceId, List<String> channelIds, Boolean online) {
      return deviceChannelMapper.queryChannelsWithDeviceInfo(deviceId, null,null, null, online,channelIds);
   }
   @Override
@@ -435,9 +463,6 @@
    */
   @Override
   public synchronized boolean insertMobilePosition(MobilePosition mobilePosition) {
      if (mobilePosition.getDeviceId().equals(mobilePosition.getChannelId())) {
         mobilePosition.setChannelId(null);
      }
      return deviceMobilePositionMapper.insertNewPosition(mobilePosition) > 0;
   }
@@ -516,6 +541,16 @@
   @Override
   public List<ParentPlatform> queryEnableParentPlatformList(boolean enable) {
      return platformMapper.getEnableParentPlatformList(enable);
   }
   @Override
   public List<ParentPlatform> queryEnablePlatformListWithAsMessageChannel() {
      return platformMapper.queryEnablePlatformListWithAsMessageChannel();
   }
   @Override
   public List<Device> queryDeviceWithAsMessageChannel() {
      return deviceMapper.queryDeviceWithAsMessageChannel();
   }
   @Override
@@ -906,7 +941,7 @@
      deviceChannel.setLatitude(0.0);
      deviceChannel.setDeviceId(platform.getDeviceGBId());
      deviceChannel.setManufacture("wvp-pro");
      deviceChannel.setStatus(1);
      deviceChannel.setStatus(true);
      deviceChannel.setParental(1);
      deviceChannel.setRegisterWay(1);