package com.jiayue.ipfcst.console.service;

import com.jiayue.ipfcst.common.data.entity.ChannelDisconLog;
import com.jiayue.ipfcst.common.data.repository.ChannelDisconLogRepository;
import com.jiayue.ipfcst.common.data.service.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 通道断开日志
 *
 * @author xsl
 * @version 3.0
 */
@Service
@Slf4j
public class ChannelDisconLogService extends BaseService {
  @Autowired
  ChannelDisconLogRepository channelDisconLogRepository;

  /**
   * 保存
   *
   * @param channelDisconLog 通道断开日志
   */
  @Transactional(propagation = Propagation.REQUIRED)
  public ChannelDisconLog save(ChannelDisconLog channelDisconLog) {
    return channelDisconLogRepository.save(channelDisconLog);
  }

  /**
   * 根据通道ID获取需要更新重连的
   *
   * @param channelId 通道ID
   */
  public List<ChannelDisconLog> get(String channelId) {
    return channelDisconLogRepository.findByChannelIdAndDisconnectTimeIsNotNullAndReconnectTimeIsNull(channelId);
  }
}
