package com.jiayue.insu.inclientqn.job;

import cn.hutool.core.date.DateUtil;
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.inenum.QNHLEnum;
import com.jiayue.insu.inclientqn.inenum.StatusEnum;
import com.jiayue.insu.inclientqn.service.RecordService;
import com.jiayue.insu.inclientqn.service.client.CorrforeService;
import com.jiayue.insu.inclientqn.util.DateTimeUtils;
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 RepairPlanJob implements Job {


    @Autowired
    private CorrforeService corrforeService;
    @Autowired
    private RecordService recordService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        long time = DateTimeUtils.get15min(DateUtil.date().getTime());
        LocalDateTime localDateTime = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
        Record record = recordService.findTimeAndTypeAndContentAndState(localDateTime, CommonStant.RECORD_TYPE_CORRECT_DATA, QNHLEnum.DATA_REPAPLAN_TYPE.getCode(), StatusEnum.SUCCESS.getSign());

        if (record == null) {
            corrforeService.downLoadRepairPlan(time);
        }

    }
}
