package com.app.job;

import com.app.service.order.OpenCourseOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Profile({"prod"}) // add by 梁展鹏 20201113 这里为了只在生产模式才会执行定时任务
@Component
public class OpenCourseOrderJob {

    @Autowired
    private OpenCourseOrderService openCourseOrderService;

    /**
     * 功能描述：处理超时订单
     * 1. 定时扫描订单表，把[待支付]、[已到过期时间]的订单拿到
     * 2. 处理订单为[已过期]
     * 3. 处理订单项
     * 4. 处理选课单
     * ...
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    public void handleTimeoutOrder() {
        // todo 缺分布式锁
        openCourseOrderService.handleTimeoutOrder();
    }

}
