feiyu02
2024-08-02 16b961c2210fe29fd494ac1f9d830dd93503961f
src/main/kotlin/cn/flightfeather/supervision/scheduler/ScheduleService.kt
@@ -6,9 +6,11 @@
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.scheduling.annotation.Async
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import java.time.LocalDate
import java.time.LocalDateTime
/**
@@ -23,6 +25,8 @@
 */
@Component
class ScheduleService(
    @Value("\${mode}")
    var mode: String,
    private val taskFinishSubtask: TaskFinishSubtask,
    private val taskFinishTopTask: TaskFinishTopTask,
    private val aopTaskCtrl: AopTaskCtrl,
@@ -32,28 +36,45 @@
    @Async
    @Scheduled(cron = "0 0 0 * * *")
    fun eachDay() {
        if (mode != "pro") return
        logger.info("=====>>>>>每日任务执行 {}", System.currentTimeMillis())
        taskFinishSubtask.handle()
        logger.info("=====>>>>>每日任务结束 {}", System.currentTimeMillis())
    }
    @Async
    @Scheduled(cron = "0 0 0 * * MON")
//    @Async
//    @Scheduled(cron = "0 0 0 * * MON")
    fun eachWeek() {
        if (mode != "pro") return
        logger.info("=====>>>>>每周任务执行 {}", System.currentTimeMillis())
        // 执行上周的自评任务
        aopTaskCtrl.startAllEvaluation(LocalDateTime.now())
        aopTaskCtrl.startAllEvaluation(LocalDate.now().atStartOfDay())
        logger.info("=====>>>>>每周任务结束 {}", System.currentTimeMillis())
    }
//    @Async
//    @Scheduled(cron = "0 0 0 1 * *")
    fun eachStartOfMonth() {
        if (mode != "pro") return
        logger.info("=====>>>>>每月1号任务执行 {}", System.currentTimeMillis())
        // 计算去除扬尘监测数据后的评分
        aopTaskCtrl.startAllEvaluation(LocalDate.now().atStartOfDay().minusMonths(1))
        logger.info("=====>>>>>每月1号任务结束 {}", System.currentTimeMillis())
    }
    @Async
    @Scheduled(cron = "0 0 0 2 * *")
    fun eachMonth() {
        logger.info("=====>>>>>每月任务执行 {}", System.currentTimeMillis())
        if (mode != "pro") return
        logger.info("=====>>>>>每月2号任务执行 {}", System.currentTimeMillis())
        // 执行上个月的完整自评任务
        aopTaskCtrl.startAll(LocalDateTime.now().minusMonths(1))
        aopTaskCtrl.startAll(LocalDate.now().atStartOfDay().minusMonths(1))
        // 执行顶层任务自动结束任务
        taskFinishTopTask.handle()
        logger.info("=====>>>>>每月任务结束 {}", System.currentTimeMillis())
        logger.info("=====>>>>>每月2号任务结束 {}", System.currentTimeMillis())
    }
}