src/main/java/cc/mrbird/febs/FebsShiroApplication.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/cc/mrbird/febs/mall/mapper/MallOrderInfoMapper.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/cc/mrbird/febs/mall/quartz/OrderOvertimeJob.java | ●●●●● patch | view | raw | blame | history | |
src/main/resources/mapper/modules/MallOrderInfoMapper.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/cc/mrbird/febs/FebsShiroApplication.java
@@ -5,12 +5,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.transaction.annotation.EnableTransactionManagement; /** * @author MrBird */ @EnableAsync @EnableScheduling @SpringBootApplication @EnableTransactionManagement @MapperScan("cc.mrbird.febs.*.mapper") src/main/java/cc/mrbird/febs/mall/mapper/MallOrderInfoMapper.java
@@ -36,4 +36,6 @@ AdminOrderDetailVo getMallOrderDetailById(@Param("id")long id); List<MallOrderItem> getMallOrderItemByOrderId(@Param("id")long id); List<MallOrderInfo> selectOrderInfoByStatus(@Param("status") Integer status); } src/main/java/cc/mrbird/febs/mall/quartz/OrderOvertimeJob.java
New file @@ -0,0 +1,45 @@ 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); } } } } } src/main/resources/mapper/modules/MallOrderInfoMapper.xml
@@ -139,4 +139,7 @@ select * from mall_order_item where order_id = #{id} </select> <select id="selectOrderInfoByStatus" resultType="cc.mrbird.febs.mall.entity.MallOrderInfo"> select * from mall_order_info where status=#{status} </select> </mapper>