mk1990
2022-05-16 e6790d88fc5b1ac33d239c0d90ce6cdea666b821
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -13,6 +13,7 @@
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.storager.dao.*;
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.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -26,8 +27,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**    
 * 视频设备数据存储-jdbc实现
@@ -91,9 +92,6 @@
   @Autowired
    private ParentPlatformMapper parentPlatformMapper;
   private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   /**
    * 根据设备ID判断设备是否存在
    *
@@ -105,45 +103,6 @@
      return deviceMapper.getDeviceByDeviceId(deviceId) != null;
   }
   /**
    * 视频设备创建
    *
    * @param device 设备对象
    * @return true:创建成功  false:创建失败
    */
   @Override
   public synchronized boolean create(Device device) {
      redisCatchStorage.updateDevice(device);
      return deviceMapper.add(device) > 0;
   }
   /**
    * 视频设备更新
    *
    * @param device 设备对象
    * @return true:更新成功  false:更新失败
    */
   @Override
   public synchronized boolean updateDevice(Device device) {
      String now = this.format.format(System.currentTimeMillis());
      device.setUpdateTime(now);
      Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
      device.setCharset(device.getCharset().toUpperCase());
      if (deviceByDeviceId == null) {
         device.setCreateTime(now);
         redisCatchStorage.updateDevice(device);
         return deviceMapper.add(device) > 0;
      }else {
         redisCatchStorage.updateDevice(device);
         return deviceMapper.update(device) > 0;
      }
   }
   @Override
   public synchronized void updateChannel(String deviceId, DeviceChannel channel) {
      String channelId = channel.getChannelId();
@@ -152,7 +111,7 @@
      if (streamInfo != null) {
         channel.setStreamId(streamInfo.getStream());
      }
      String now = this.format.format(System.currentTimeMillis());
      String now = DateUtil.getNow();
      channel.setUpdateTime(now);
      DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
      if (deviceChannel == null) {
@@ -178,7 +137,7 @@
               if (streamInfo != null) {
                  channel.setStreamId(streamInfo.getStream());
               }
               String now = this.format.format(System.currentTimeMillis());
               String now = DateUtil.getNow();
               channel.setUpdateTime(now);
               channel.setCreateTime(now);
               addChannels.add(channel);
@@ -193,7 +152,7 @@
               if (streamInfo != null) {
                  channel.setStreamId(streamInfo.getStream());
               }
               String now = this.format.format(System.currentTimeMillis());
               String now = DateUtil.getNow();
               channel.setUpdateTime(now);
               if (channelsInStore.get(channel.getChannelId()) != null) {
                  updateChannels.add(channel);
@@ -239,17 +198,27 @@
      if (deviceChannelList == null) {
         return false;
      }
      List<DeviceChannel> allChannelInPlay = deviceChannelMapper.getAllChannelInPlay();
      Map<String,DeviceChannel> allChannelMapInPlay = new ConcurrentHashMap<>();
      if (allChannelInPlay.size() > 0) {
         for (DeviceChannel deviceChannel : allChannelInPlay) {
            allChannelMapInPlay.put(deviceChannel.getChannelId(), deviceChannel);
         }
      }
      TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
      // 数据去重
      List<DeviceChannel> channels = new ArrayList<>();
      StringBuilder stringBuilder = new StringBuilder();
      Map<String, Integer> subContMap = new HashMap<>();
      if (deviceChannelList != null && deviceChannelList.size() > 1) {
      if (deviceChannelList.size() > 1) {
         // 数据去重
         Set<String> gbIdSet = new HashSet<>();
         for (DeviceChannel deviceChannel : deviceChannelList) {
            if (!gbIdSet.contains(deviceChannel.getChannelId())) {
               gbIdSet.add(deviceChannel.getChannelId());
               if (allChannelMapInPlay.containsKey(deviceChannel.getChannelId())) {
                  deviceChannel.setStreamId(allChannelMapInPlay.get(deviceChannel.getChannelId()).getStreamId());
               }
               channels.add(deviceChannel);
               if (!StringUtils.isEmpty(deviceChannel.getParentId())) {
                  if (subContMap.get(deviceChannel.getParentId()) == null) {
@@ -460,7 +429,9 @@
   public synchronized boolean outline(String deviceId) {
      logger.info("更新设备离线: " + deviceId);
      Device device = deviceMapper.getDeviceByDeviceId(deviceId);
      if (device == null) return false;
      if (device == null) {
         return false;
      }
      device.setOnline(0);
      redisCatchStorage.updateDevice(device);
      return deviceMapper.update(device) > 0;
@@ -714,6 +685,7 @@
    * 删除指定设备的所有移动位置
    * @param deviceId
    */
   @Override
   public int clearMobilePositionsByDeviceId(String deviceId) {
      return deviceMobilePositionMapper.clearMobilePositionsByDeviceId(deviceId);
   }
@@ -729,7 +701,7 @@
      boolean result = false;
      streamProxyItem.setStreamType("proxy");
      streamProxyItem.setStatus(true);
      String now = this.format.format(System.currentTimeMillis());
      String now = DateUtil.getNow();
      streamProxyItem.setCreateTime(now);
      streamProxyItem.setCreateStamp(System.currentTimeMillis());
      try {
@@ -859,7 +831,9 @@
   @Override
   public void updateMediaList(List<StreamPushItem> streamPushItems) {
      if (streamPushItems == null || streamPushItems.size() == 0) return;
      if (streamPushItems == null || streamPushItems.size() == 0) {
         return;
      }
      logger.info("updateMediaList:  " + streamPushItems.size());
      streamPushMapper.addAll(streamPushItems);
      // TODO 待优化