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


import com.jiayue.ipfcst.common.data.entity.integration.InForecastPowerShortTerm;
import com.jiayue.ipfcst.common.data.repository.NwpHisRepository;
import com.jiayue.ipfcst.common.data.repository.NwpRepository;
import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
import com.jiayue.ipfcst.common.data.service.BaseService;
import com.jiayue.ipfcst.common.data.repository.InForecastPowerShortTermRepository;
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 InForecastPowerShortTermService extends BaseService {

    @Autowired
    NwpRepository nwpRepository;
    @Autowired
    NwpHisRepository nwpHisRepository;
    @Autowired
    InForecastPowerShortTermRepository inForecastPowerShortTermRepository;
    @Autowired
    SysParameterRepository sysParameterRepository;

    /**
     * 根据时间段删除数据
     *
     * @param startTime
     * @param endTime
     * @param data
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteBetweenAndPreTime(Long startTime, Long endTime, List<InForecastPowerShortTerm> data) {

      inForecastPowerShortTermRepository.deleteByForecastTimeBetween(startTime, endTime);
      inForecastPowerShortTermRepository.saveAll(data);
    }

  public List<InForecastPowerShortTerm> findByForecastTimeBetween(Long startTime, Long endTime){
    return inForecastPowerShortTermRepository.findByForecastTimeBetween(startTime, endTime);
  }




}
