package com.jiayue.ipfcst.dataexchange.repository;

import com.jiayue.ipfcst.common.data.entity.ProtocolSenderDataPoint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 转发通达点位信息仓库
 *
 * @author 修唯xiuwei
 * @version 3.0
 */
public interface ProtocolSenderDataPointRepository extends JpaRepository<ProtocolSenderDataPoint, Integer>, JpaSpecificationExecutor<ProtocolSenderDataPoint> {
  List<ProtocolSenderDataPoint> findByTunnelIdAndAndGatherPoint(String tunnelId, Integer gatherPoint);

  List<ProtocolSenderDataPoint> findByTunnelId(String tunnelId);

  List<ProtocolSenderDataPoint> findByGatherPoint(Integer gatherPoint);

  /**
   * 获取转发通道下最末尾的点位
   *
   * @param tunnelId 通道id
   * @return {@link Integer}
   */
  @Query(value = "SELECT max(protocolPointNo) FROM ProtocolSenderDataPoint where tunnelId= :tunnelId")
  Integer getMaxProtocolNoInTunnel(@Param("tunnelId") String tunnelId);
}
