package beilv.wx.pay.task;

import beilv.wx.pay.service.IWxPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 订单超时处理任务
 * 定期检查Redis中的延迟队列，处理超时订单
 */
@Slf4j
@Component
public class OrderTimeoutTask {

    @Autowired
    private IWxPayService wxPayService;

    /**
     * 每隔1秒检查一次超时订单
     */
    @Scheduled(fixedRate = 1000)
    public void checkTimeoutOrders() {
        try {
//            log.info("开始检查超时订单...");
            wxPayService.processTimeoutOrders();
//            log.info("超时订单检查完成");
        } catch (Exception e) {
            log.error("检查超时订单时发生错误", e);
        }
    }
}