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; } }