package cn.gyee.tamplate.task;

import cn.gyee.tamplate.service.analysis.AnalysisNewService;
import cn.gyee.tamplate.service.analysis.AnalysisService;
import cn.gyee.tamplate.service.benchmark.BenchmarkService;
import cn.gyee.tamplate.service.operation.OperationService;
import cn.gyee.tamplate.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.text.ParseException;
import java.time.LocalDateTime;

/**
 * @ClassName : SaticScheduleTask
 * @Author : xieshengjie
 * @Date: 2021/1/21 19:43
 * @Description : 调度
 */
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {

    @Autowired
    private OperationService operationService;
    @Autowired
    private BenchmarkService benchmarkService;
    @Resource
    private AnalysisService analysisService;
    @Resource
    private AnalysisNewService analysisNewService;

//    //3.添加定时任务
//    /**
//     * 控制指令调度
//     */
//    @Scheduled(cron = "0 0 1 * * ?")
//    //或直接指定时间间隔，例如：5秒
//    //@Scheduled(fixedRate=5000)
//    private void configureTasks1() {
//        try {
//            operationService.opeMapTask();
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//    }
//
//    /**
//     * 值际五损调度
//     */
//    @Scheduled(cron = "0 0 2 * * ?")
//    //或直接指定时间间隔，例如：5秒
//    //@Scheduled(fixedRate=5000)
//    private void configureTasks2() {
//        try {
//            benchmarkService.createBeanchmarkList();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }



    /**
     * 风电统计分析
     */
    @Scheduled(cron = "0 15 0 * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void analysisTasks() {
        String yesterday = DateUtils.getYesterdayStr("yyyy-MM-dd");
        try {
            //保存主表
            analysisNewService.savaAnalysismain(yesterday, yesterday);
            //风电表底
            analysisNewService.saveAnalysisTableBottom(yesterday, yesterday);
            //风电工程
            analysisNewService.saveWindProject(yesterday, yesterday);
            //风电场站
            analysisNewService.saveWindStation(yesterday, yesterday);
            //公司
            analysisNewService.saveCompany(yesterday, yesterday);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 光伏统计分析
     */
    @Scheduled(cron = "0 5 18 * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void analysisGfTasks() {
//        String yesterday = DateUtils.getYesterdayStr("yyyy-MM-dd");
        String yesterday = DateUtils.toDate1(DateUtils.today());

        try {
            //主表
            analysisNewService.savaAnalysismain(yesterday, yesterday);
            //光伏主表
            analysisNewService.savaAnalysisGfmain(yesterday, yesterday);
            //下午6点的表底存储
            analysisNewService.saveAnalysisTableBottom1(yesterday, yesterday);
            //光伏表底存储
            analysisNewService.saveAnalysisGfTableBottom(yesterday, yesterday);
            //光伏项目
            analysisNewService.savePvProject(yesterday, yesterday);
            //光伏场站
            analysisNewService.savePvStation(yesterday, yesterday);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
