package com.jiayue.insu.incloud.job.data.pull;

import com.jiayue.insu.incloud.constants.CommonStant;
import com.jiayue.insu.incloud.entity.Station;
import com.jiayue.insu.incloud.pulldata.PullInitData;
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;


/**
 * 清能互联 拉取原始预测数据
 *
 * @author yh
 * @version 1.0
 * @since 2022/5/22 11:29
 */
@Slf4j
public class PullInitDataJob implements Job {

    @Autowired
    private PullInitData pullInitData;
    @Autowired
    private StationService stationService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String code = jobExecutionContext.getTrigger().getJobKey().getName();
        // 校验并获取场站信息
        Station station = stationService.checkAndFindStation(code, CommonStant.RECORD_TYPE_PULL_INIT);
        //没有成功记录进行业务
        if (station != null) {
            pullInitData.pullDQAndNWPData(station);
        } else {
            log.error("========== 一体化定时任务异常:  场站信息为空  {}==========", code);
        }
    }
}
