|
@@ -19,6 +19,10 @@ import com.chelvc.framework.common.util.AssertUtils;
|
|
|
import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
import com.chelvc.framework.common.util.StringUtils;
|
|
|
import com.chelvc.framework.database.context.DatabaseContextHolder;
|
|
|
+import io.netty.util.HashedWheelTimer;
|
|
|
+import io.netty.util.Timeout;
|
|
|
+import io.netty.util.Timer;
|
|
|
+import io.netty.util.TimerTask;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.http.util.Asserts;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -30,6 +34,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* 订单Service业务层处理
|
|
@@ -310,6 +315,24 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper, OmsOrder> i
|
|
|
|
|
|
@Override
|
|
|
public void cancelOrder(Long orderId) {
|
|
|
+ List<Long> orderIds = new ArrayList<>();
|
|
|
+ orderIds.add(orderId);
|
|
|
+ this.baseMapper.updateOrderStatus(orderIds, 0);
|
|
|
+ // 初始化时间轮
|
|
|
+ Timer timer = new HashedWheelTimer();
|
|
|
+ // 定时任务
|
|
|
+ TimerTask task1 = new io.netty.util.TimerTask() {
|
|
|
+ public void run(Timeout timeout) throws Exception {
|
|
|
+ // 取消订单业务逻辑
|
|
|
+ closeOrder(orderId);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 注册此定时任务(延迟时间为900秒,也就是说900秒后订单过期)
|
|
|
+ timer.newTimeout(task1, 900, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void closeOrder(Long orderId) {
|
|
|
//查询未付款的取消订单
|
|
|
List<OmsOrder> cancelOrderList = this.lambdaQuery()
|
|
|
.eq(OmsOrder::getId,orderId)
|