package com.jiayue.insu.inclientqn.job;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.jiayue.insu.inclientqn.constant.CommonStant;
import com.jiayue.insu.inclientqn.entity.Record;
import com.jiayue.insu.inclientqn.entity.Station;
import com.jiayue.insu.inclientqn.inenum.StatusEnum;
import com.jiayue.insu.inclientqn.service.client.CorrforeService;

import com.jiayue.insu.inclientqn.service.RecordService;
import com.jiayue.insu.inclientqn.service.StationService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
/**
 * @description:  请求一体化 修正数据
 * @author: yuanhao
 * @createDate: 2022/6/17
 * @version: 1.0
 */
public class CorrforeDataJob implements Job {
    @Autowired
    private CorrforeService corrforeService;
    @Autowired
    private StationService stationService;
    @Autowired
    private RecordService recordService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //查询是否有今天成功记录 （为提高稳定性，该定时任务采取在规定时间段内 重复循环执行的定时策略，故：需要查询是否存在成功记录）
        Record successRecord = recordService.findTimeAndTypeAndState(
                LocalDateTimeUtil.beginOfDay(LocalDateTime.now()),
                CommonStant.RECORD_TYPE_PULL_CORRECT,
                StatusEnum.SUCCESS.getCode());

        if(successRecord == null) {
            Station station = stationService.findThis();
            corrforeService.downLoadCorrforeData(station);
        }

    }
}
