package com.jiayue.ipfcst.fileupload.integration.service;


import com.jiayue.ipfcst.common.data.entity.integration.InForecastPowerShortTermHis;
import com.jiayue.ipfcst.common.data.service.BaseService;
import com.jiayue.ipfcst.common.data.repository.InForecastPowerShortTermHisRepository;
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;

@Service
@Slf4j
public class InForecastPowerShortTermHisService extends BaseService {


  @Autowired
  InForecastPowerShortTermHisRepository inForecastPowerShortTermHisRepository;


  /**
   * 根据时间段删除数据
   *
   * @param startTime
   * @param endTime
   */
  @Transactional(propagation = Propagation.REQUIRED)
  public void deleteToday(Long startTime, Long endTime) {
    inForecastPowerShortTermHisRepository.deleteToday(startTime, endTime);
  }


  @Transactional(propagation = Propagation.REQUIRED)
  public void saveAll(List<InForecastPowerShortTermHis> list) {
    inForecastPowerShortTermHisRepository.saveAll(list);
  }

  /**
   *
   * @param startTime 开始时间
   * @param endTime 结束时间
   * @param ago  预测间隔
   * @return
   */
  @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
  public List<InForecastPowerShortTermHis> findByForecastTimeBetweenAndForecastHowLongAgo(Long startTime, Long endTime, Integer ago) {
    return inForecastPowerShortTermHisRepository.findByForecastTimeBetweenAndForecastHowLongAgo(startTime, endTime, ago);
  }
  /**
   *
   * @param time 时间
   * @param ago  预测间隔
   * @return
   */
  @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
  public List<InForecastPowerShortTermHis> findByForecastTimeAndForecastHowLongAgo( Long time, Integer ago) {
    return inForecastPowerShortTermHisRepository.findByForecastTimeAndForecastHowLongAgo( time, ago);
  }


}
