feiyu02
2025-03-21 e5bdf2e02090357cbd580d54e6cd2406dd541760
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.flightfeather.uav.scheduler
 
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
 
/**
 * 定时任务调度
 * 一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素。按顺序依次为:
 * 秒(0~59)
 * 分钟(0~59)
 * 小时(0~23)
 * 天(1~31)
 * 月(1~12)
 * 星期(1~7 1=SUN 或 SUN,MON,TUE,WED,THU,FRI,SAT)
 */
@Component
class ScheduleService(
    @Value("\${mode}")
    var mode: String,
) {
    val logger: Logger = LoggerFactory.getLogger(ScheduleService::class.java)
 
//    @Async
//    @Scheduled(cron = "0 0 0 * * *")
    fun eachDay() {
        if (mode != "pro") return
        logger.info("=====>>>>>每日任务执行 {}", System.currentTimeMillis())
 
        logger.info("=====>>>>>每日任务结束 {}", System.currentTimeMillis())
    }
 
//    @Async
//    @Scheduled(cron = "0 0 0 * * MON")
    fun eachWeek() {
        if (mode != "pro") return
        logger.info("=====>>>>>每周任务执行 {}", System.currentTimeMillis())
        // 执行上周的自评任务
 
        logger.info("=====>>>>>每周任务结束 {}", System.currentTimeMillis())
    }
 
//    @Async
//    @Scheduled(cron = "0 0 0 1 * *")
    fun eachStartOfMonth() {
        if (mode != "pro") return
        logger.info("=====>>>>>每月1号任务执行 {}", System.currentTimeMillis())
 
        logger.info("=====>>>>>每月1号任务结束 {}", System.currentTimeMillis())
    }
 
//    @Async
//    @Scheduled(cron = "0 0 0 2 * *")
    fun eachMonth() {
        if (mode != "pro") return
        logger.info("=====>>>>>每月2号任务执行 {}", System.currentTimeMillis())
 
        logger.info("=====>>>>>每月2号任务结束 {}", System.currentTimeMillis())
    }
}