package com.jeequan.jeepay.pay.task;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.jeequan.jeepay.pay.service.StatisticsService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/***
* 数据统计 定时任务
*
* @author zx
*
* @date 2022/12/19 14:12
*/
@Slf4j
@Component
public class StatisticsTask {

    @Autowired private StatisticsService statisticsService;

    @XxlJob("statisticsTaskHandler")
    public void start() {
        log.info("开始【处理数据统计任务】");

        // 当前时间
        DateTime now = DateUtil.date();
        DateTime yesterday = DateUtil.offsetDay(now, -1);

        Date beginDate = DateUtil.beginOfDay(yesterday);
        Date endDate = DateUtil.endOfDay(yesterday);
        log.info("【处理数据统计任务】统计日期: {}", DateUtil.formatDate(beginDate));

        statisticsService.doStats(beginDate, endDate);
    }

}
