package com.ruoyi.hezhi.scheduledTask;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.hezhi.service.ITbMemberOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 定时任务服务
 */
@Component
public class ScheduledTaskService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private ITbMemberOrderService tbMemberOrderService;

    @Resource
    private RedisCache redisCache;

    @Transactional(rollbackFor =Exception.class)
    public void orderCancelTask(String redisKey) {
        try {
                // redis锁
                redisCache.setCacheObject(redisKey, 0);
                // 删除过了报名时间并且未支付的订单
                tbMemberOrderService.deleteExamCantPayOrder();
        }catch(Exception e){
            e.printStackTrace();
            logger.error(DateUtils.getNowDate()+"->定时任务执行异常："+"订单超时未支付取消");
        }finally {
            logger.info(DateUtils.getNowDate()+"->定时任务执行结束："+"订单超时未支付取消");
            // 释放锁
            redisCache.deleteObject(redisKey);
        }
    }
}
