package com.jiayue.insu.incloud.job.powerGeneration;

import com.jiayue.insu.incloud.entity.Station;
import com.jiayue.insu.incloud.service.MonthPowerGenerationService;
import com.jiayue.insu.incloud.service.PowerGenerationService;
import com.jiayue.insu.incloud.service.StationService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

/**
 * 月发电量定时任务
 *
 * @author yh
 * @version 1.0
 * @since 2022/5/22 11:29
 */
@Slf4j
public class MonthPowerGenerationJob implements Job {

    @Autowired
    private StationService stationService;
    @Autowired
    private MonthPowerGenerationService monthPowerGenerationService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String code = jobExecutionContext.getTrigger().getJobKey().getName();
        // 校验并获取场站信息
        Station station = stationService.checkAndFindStation(code,null);
        if (station == null) {
            log.error("========== 一体化定时任务异常:  场站不存在  {}==========",code);
        }
        monthPowerGenerationService.generatePower(LocalDateTime.now(),station.getStationCode());
    }
}
