package org.springblade.modules.quartz.task;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import org.springblade.common.enums.OrderStateEnum;
import org.springblade.modules.finance.entity.Order;
import org.springblade.modules.finance.service.IOrderService;
import org.springblade.modules.finance.service.impl.OrderTimeoutService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Author pangqijun
 * Date 2023/8/9
 * Description
 */
@Component("orderTimeoutTask")
public class OrderTimeoutTask {

    @Resource
    private OrderTimeoutService timeoutService;
    @Resource
    private IOrderService orderService;

    public void process() {
        long time = timeoutService.getTimeoutTime();
        List<Order> list = orderService.queryTimeoutOrder(time);
        if (CollUtil.isNotEmpty(list)) {
            for (Order order : list) {
                orderService.cancel(order);
            }
        }
    }
}
