package com.njcn.cssystem.task;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.njcn.cssystem.service.IDataTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author xy
 */
@Component
@EnableScheduling
@RequiredArgsConstructor
@Slf4j
public class DataTask {

    private final IDataTaskService taskService;

    //每天4点计算稳态越限数据
    @Scheduled(cron = "0 0 4 * * ?")
    public void csHarmonicJob() {
        String date = DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN);
        taskService.channelHarmonic(date);
    }

    //每天5点计算运行告警数据
    @Scheduled(cron = "0 0 5 * * ?")
    public void csAlarmJob() {
        String date = DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN);
        taskService.channelRunDataAlarm(date);
    }

    //每天10点推送App消息 (稳态事件 告警数据)
    @Scheduled(cron = "0 0 10 * * ?")
    public void pushAppMsg() {
        String date = DateUtil.yesterday().toString(DatePattern.NORM_DATE_PATTERN);
        taskService.pushAppMsg(date);
    }
}
