package com.ruoyi.web.modules.order.job;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.web.modules.order.constant.OrderConstants;
import com.ruoyi.web.modules.order.domain.BizOrder;
import com.ruoyi.web.modules.order.mapper.BizOrderMapper;

/**
 * 待支付超时自动关单（O8）
 */
@Component("orderPayTimeoutJob")
public class OrderPayTimeoutJob
{
    @Autowired
    private BizOrderMapper orderMapper;

    public void closeExpiredOrders()
    {
        List<BizOrder> orders = orderMapper.selectExpiredPendingPay(new Date());
        if (orders == null || orders.isEmpty())
        {
            return;
        }
        for (BizOrder order : orders)
        {
            orderMapper.updateForCancelPay(order.getOrderId(), order.getMemberId(),
                    OrderConstants.CLOSE_TYPE_TIMEOUT);
        }
    }
}
