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 71 72
| package com.delayqueue.demo.entity; import lombok.Data; import java.util.Date; import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit;
@Data public class Order implements Delayed {
private String orderNo;
private String userId;
private Integer status;
private Date createTime;
private Date cancelTime; public Order(String orderNo, String userId, Integer status, Date createTime, Date cancelTime) { this.orderNo = orderNo; this.userId = userId; this.status = status; this.createTime = createTime; this.cancelTime = cancelTime; } @Override public String toString() { return "Order{" + "orderNo='" + orderNo + '\'' + ", userId='" + userId + '\'' + ", status=" + status + ", createTime=" + createTime + ", cancelTime=" + cancelTime + '}'; }
@Override public long getDelay(TimeUnit unit) { return unit.convert(cancelTime.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS); }
@Override public int compareTo(Delayed o) { return this.getCancelTime().compareTo(((Order) o).getCancelTime()); } }
|