| package cc.mrbird.febs.mall.quartz; | 
|   | 
| import cc.mrbird.febs.common.enumerates.OrderStatusEnum; | 
| import cc.mrbird.febs.mall.entity.MallOrderInfo; | 
| import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper; | 
| import cn.hutool.core.collection.CollUtil; | 
| import cn.hutool.core.date.DateUnit; | 
| import cn.hutool.core.date.DateUtil; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.scheduling.annotation.Scheduled; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * @author wzy | 
|  * @date 2021-09-25 | 
|  **/ | 
| @Slf4j | 
| @Component | 
| public class OrderOvertimeJob { | 
|   | 
|     @Autowired | 
|     private MallOrderInfoMapper orderInfoMapper; | 
|   | 
|     @Scheduled(cron = "0 0/5 * * * ? ") | 
|     public void overtimeJob() { | 
|         log.info("订单超时任务执行"); | 
|         List<MallOrderInfo> orderList = orderInfoMapper.selectOrderInfoByStatus(OrderStatusEnum.WAIT_PAY.getValue()); | 
|         if (CollUtil.isNotEmpty(orderList)) { | 
|             for (MallOrderInfo orderInfo : orderList) { | 
|                 long subTime = DateUtil.between(orderInfo.getOrderTime(), new Date(), DateUnit.MINUTE, false); | 
|   | 
|                 if (subTime > 15) { | 
|                     orderInfo.setStatus(OrderStatusEnum.CANCEL.getValue()); | 
|                     orderInfo.setCancelType(MallOrderInfo.CANCEL_OVERTIME_NO_PAY); | 
|                     orderInfoMapper.updateById(orderInfo); | 
|                 } | 
|             } | 
|         } | 
|   | 
|     } | 
| } |