package com.jiayue.ipfcst.common.data.repository;

import com.jiayue.ipfcst.common.data.entity.integration.InForecastPowerShortTermHis;
import com.jiayue.ipfcst.common.data.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 一体化短期历史仓储
 *
 * @author yh
 * @version 1.0
 * @since 2019/8/5 9:15
 */
public interface InForecastPowerShortTermHisRepository extends BaseRepository<InForecastPowerShortTermHis, Integer> {

  /**
   * 根据时间段删除当日凌晨零点以后生成的短期历史期数据
   *
   * @param startTime 开始时间
   * @param endTime   结束时间
   */
  @Modifying
  @Query(value = "delete from InForecastPowerShortTermHis t where t.createDate >= CURRENT_DATE and t.forecastTime >=?1 and t.forecastTime<=?2")
  void deleteToday(Long startTime, Long endTime);

  /**
   *  根据时间和预测间隔查询
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @param ago 预测间隔
   * @return 结果集
   */
  List<InForecastPowerShortTermHis> findByForecastTimeBetweenAndForecastHowLongAgo(Long startTime, Long endTime,Integer ago);

  /**
   * 根据时间和预测间隔查询
   * @param time 时间
   * @param ago 预测间隔
   * @return
   */
  List<InForecastPowerShortTermHis> findByForecastTimeAndForecastHowLongAgo(Long time,Integer ago);
}
