package com.jiayue.ipfcst.fileupload.job;

import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
import com.jiayue.ipfcst.common.data.entity.ForecastPowerShortTermHis;
import com.jiayue.ipfcst.common.data.job.BaseJob;
import com.jiayue.ipfcst.console.service.ForecastPowerShortTermService;
import com.jiayue.ipfcst.console.service.SysParameterService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateUtils;
import org.quartz.JobDataMap;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Slf4j
public class MakeDqUploadLineJob extends BaseJob {
  @Autowired
  private ForecastPowerShortTermService forecastPowerShortTermService;
  @Autowired
  private SysParameterService sysParameterService;
  @Override
  public boolean execute(JobDataMap jobDataMap) {
    log.info("开始执行首页上报短期数据生成定时任务");

    // 获取当前系统时间
    Date systemDate = new Date();

    // 短期默认天数
    int dqDays = sysParameterService.getTranSysParameter("FILE_FORECAST_DAYS","0");

    // 开始时间
    Long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(systemDate, 1).getTime());
    Long endTime = DateMomentUtil.getDayLastTime(DateUtils.addDays(systemDate, dqDays).getTime()) - 1000;
    List<ForecastPowerShortTermHis> forecastPowerShortTerm = this.forecastPowerShortTermService.getForecastPowerShortTerm(startTime, endTime);
    log.info("执行首页上报短期数据生成定时任务结束，生成记录数："+forecastPowerShortTerm.size());
    return true;
  }
}
