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.RequestDataService;
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 BackStatDataJob implements Job {


    @Autowired
    private RequestDataService requestDataService;
    @Autowired
    private RecordService recordService;

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

        if (record == null) {
            requestDataService.requestBackStat(time);
        }

    }
}
