package org.springblade.modules.finance.entity;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * Author pangqijun
 * Date 2023/5/10
 * Description 超时订单处理类
 */
@AllArgsConstructor
@Data
public class OrderTimeoutTask implements Delayed {

    /**
     * 订单id
     */
    private Long orderId;

    /**
     * 购物车交易id
     */
    private Long transactionId;
    /**
     * 超时时间
     */
    private long timeoutPeriod;

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(timeoutPeriod - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed other) {
        long td = this.getDelay(TimeUnit.MILLISECONDS);
        long od = other.getDelay(TimeUnit.MILLISECONDS);
        return Long.compare(td,od);
    }
}
