package com.bonus.system.warning;

import com.bonus.system.service.ISysLogService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class ScheduledTasks {

    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Resource(name = "ISysLogService")
    private ISysLogService service;

    // 每5分钟执行一次
    @Scheduled(fixedRate = 300000)
    public void taskWithFixedRate() {
        service.logWarn();
        System.out.println("数据库容量固定速率任务执行时间：" + LocalDateTime.now().format(formatter));
    }

//    // 每天凌晨1点执行
//    @Scheduled(cron = "0 */5 * * * ?")
//    public void taskWithCron() {
//        System.out.println("定时任务执行时间：" + LocalDateTime.now().format(formatter));
//    }
}