|
|
|
@ -0,0 +1,91 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* https://www.mall4j.com/
|
|
|
|
|
*
|
|
|
|
|
* 未经允许,不可做商业用途!
|
|
|
|
|
*
|
|
|
|
|
* 版权所有,侵权必究!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.yami.shop.admin.task; // 定义类所在的包
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; // 引入Hutool工具类库中的CollectionUtil工具类
|
|
|
|
|
import cn.hutool.core.date.DateUtil; // 引入Hutool工具类库中的DateUtil工具类
|
|
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob; // 引入XXL-Job的注解
|
|
|
|
|
import com.yami.shop.bean.enums.OrderStatus; // 引入订单状态枚举类
|
|
|
|
|
import com.yami.shop.bean.model.Order; // 引入订单模型类
|
|
|
|
|
import com.yami.shop.bean.model.OrderItem; // 引入订单项模型类
|
|
|
|
|
import com.yami.shop.service.OrderService; // 引入订单服务类
|
|
|
|
|
import com.yami.shop.service.ProductService; // 引入商品服务类
|
|
|
|
|
import com.yami.shop.service.SkuService; // 引入SKU服务类
|
|
|
|
|
import org.slf4j.Logger; // 引入SLF4J的Logger类
|
|
|
|
|
import org.slf4j.LoggerFactory; // 引入SLF4J的LoggerFactory类
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 引入Spring的@Autowired注解
|
|
|
|
|
import org.springframework.stereotype.Component; // 引入Spring的@Component注解
|
|
|
|
|
|
|
|
|
|
import java.util.Date; // 引入Java的Date类
|
|
|
|
|
import java.util.List; // 引入Java的List接口
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* OrderTask类,用于管理与订单相关的定时任务操作。
|
|
|
|
|
* 定时任务的配置,请查看xxl-job的java配置文件。
|
|
|
|
|
* @作者 FrozenWatermelon
|
|
|
|
|
* @参见 com.yami.shop.admin.config.XxlJobConfig
|
|
|
|
|
*/
|
|
|
|
|
@Component("orderTask") // 标注这是一个Spring组件,并且以orderTask为组件名称
|
|
|
|
|
public class OrderTask {
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(OrderTask.class); // 日志记录器
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private OrderService orderService; // 自动注入订单服务类
|
|
|
|
|
@Autowired
|
|
|
|
|
private ProductService productService; // 自动注入商品服务类
|
|
|
|
|
@Autowired
|
|
|
|
|
private SkuService skuService; // 自动注入SKU服务类
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 取消超时未支付订单
|
|
|
|
|
*/
|
|
|
|
|
@XxlJob("cancelOrder")
|
|
|
|
|
public void cancelOrder() {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
logger.info("取消超时未支付订单。。。");
|
|
|
|
|
// 获取30分钟之前未支付的订单
|
|
|
|
|
List<Order> orders = orderService.listOrderAndOrderItems(OrderStatus.UNPAY.value(), DateUtil.offsetMinute(now, -30));
|
|
|
|
|
if (CollectionUtil.isEmpty(orders)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
orderService.cancelOrders(orders);
|
|
|
|
|
for (Order order : orders) {
|
|
|
|
|
List<OrderItem> orderItems = order.getOrderItems();
|
|
|
|
|
for (OrderItem orderItem : orderItems) {
|
|
|
|
|
productService.removeProductCacheByProdId(orderItem.getProdId());
|
|
|
|
|
skuService.removeSkuCacheBySkuId(orderItem.getSkuId(), orderItem.getProdId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 确认收货
|
|
|
|
|
*/
|
|
|
|
|
@XxlJob("confirmOrder")
|
|
|
|
|
public void confirmOrder() {
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
logger.info("系统自动确认收货订单。。。");
|
|
|
|
|
// 获取15天之前未支付的订单
|
|
|
|
|
List<Order> orders = orderService.listOrderAndOrderItems(OrderStatus.CONSIGNMENT.value(), DateUtil.offsetDay(now, -15));
|
|
|
|
|
if (CollectionUtil.isEmpty(orders)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
orderService.confirmOrder(orders);
|
|
|
|
|
for (Order order : orders) {
|
|
|
|
|
List<OrderItem> orderItems = order.getOrderItems();
|
|
|
|
|
for (OrderItem orderItem : orderItems) {
|
|
|
|
|
productService.removeProductCacheByProdId(orderItem.getProdId());
|
|
|
|
|
skuService.removeSkuCacheBySkuId(orderItem.getSkuId(), orderItem.getProdId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|