xuekang
2024-05-11 bac0878349a1db23e7b420ea164e22fb9db73a99
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
66
67
68
69
70
package com.nuvole.hnnx.orderQueryTask;
 
import io.swagger.annotations.ApiModelProperty;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
 
import java.time.Instant;
import java.util.Date;
 
/**
 * @ClassName OrderQueryTrigger
 * @Author cy
 * @Date 2024/1/2
 * @Description
 * @Version 1.0
 **/
public class OrderQueryTrigger implements Trigger {
    @ApiModelProperty("订单尝试支付时间")
    private Date orderPayTime;
 
//    @Override
//    public Date nextExecutionTime(TriggerContext triggerContext) {
//        // 根据不同的时间段返回下一次执行任务的时间
//        Date nowTime = new Date();
//
//        long lastDuration = nowTime.getTime() - orderPayTime.getTime();
//
//        // 根据时间段设置不同的执行间隔
//        //间隔时间  查询频率
//        //(0~10]    2s
//        //(10~30]   5s
//        //(30~60]   15s
//        //(60~180]  60s
//        if (lastDuration <= 10000) {
//            return new Date(System.currentTimeMillis() + 2000);
//        } else if (lastDuration <= 30000) {
//            return new Date(System.currentTimeMillis() + 5000);
//        } else if (lastDuration <= 60000) {
//            return new Date(System.currentTimeMillis() + 15000);
//        } else {
//            return new Date(System.currentTimeMillis() + 60000);
//        }
//    }
 
    @Override
    public Instant nextExecution(TriggerContext triggerContext) {
 
        // 根据不同的时间段返回下一次执行任务的时间
        long lastDuration = System.currentTimeMillis() - orderPayTime.getTime();
 
        // 根据时间段设置不同的执行间隔
        //间隔时间  查询频率
        //(0~10]    2s
        //(10~30]   5s
        //(30~60]   15s
        //(60~180]  60s
        if (lastDuration <= 10000) {
            return Instant.ofEpochMilli(System.currentTimeMillis() + 2000);
        } else if (lastDuration <= 30000) {
            return Instant.ofEpochMilli(System.currentTimeMillis() + 5000);
        } else if (lastDuration <= 60000) {
            return Instant.ofEpochMilli(System.currentTimeMillis() + 15000);
        } else {
            return Instant.ofEpochMilli(System.currentTimeMillis() + 60000);
        }
    }
    public OrderQueryTrigger(Date orderPayTime) {
        this.orderPayTime = orderPayTime;
    }
}