package com.pqs9000.task;

import cn.hutool.core.date.DatePattern;
import com.pqs9000.service.responsibility.OverLimitMonitorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 类的介绍：每日定时计算监测点稳态超标的数据
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2024/3/21 16:16
 */
@Component
@EnableScheduling
public class HarmonicDetailTask {

    private static final Logger logger = LoggerFactory.getLogger(HarmonicDetailTask.class);

    @Autowired
    private OverLimitMonitorService overLimitMonitorService;

    @Scheduled(cron = "0 0 8 * * ?")
    public void timer() {
        try {
            //获取前一天时间
            LocalDate today = LocalDate.now().plusDays(-1);
            String time = today.format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATE_PATTERN));
            overLimitMonitorService.manualCalculation(time,time);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("每日指标定时计算异常,异常原因为：" + e.getMessage());
        }
    }
}
