LuoDLeo пре 1 месец
родитељ
комит
54f13356d6
2 измењених фајлова са 14 додато и 20 уклоњено
  1. 0 6
      pom.xml
  2. 14 14
      src/main/java/org/springblade/modules/quartz/task/OrderTimeoutTask.java

+ 0 - 6
pom.xml

@@ -322,12 +322,6 @@
             <artifactId>java-sdk</artifactId>
             <version>4.16.19</version>
         </dependency>
-
-        <dependency>
-            <groupId>org.redisson</groupId>
-            <artifactId>redisson</artifactId>
-            <version>3.20.1</version>
-        </dependency>
     </dependencies>
 
     <build>

+ 14 - 14
src/main/java/org/springblade/modules/quartz/task/OrderTimeoutTask.java

@@ -1,20 +1,21 @@
 package org.springblade.modules.quartz.task;
 
 import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.date.DateUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.time.DateUtils;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
 import org.springblade.common.constant.CacheBizConstant;
+import org.springblade.common.enums.OrderStateEnum;
 import org.springblade.core.redis.cache.BladeRedis;
+import org.springblade.modules.finance.entity.Order;
 import org.springblade.modules.finance.service.IOrderService;
 import org.springframework.context.annotation.Lazy;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
-import java.util.Iterator;
-import java.util.Set;
+import java.util.Date;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -39,16 +40,15 @@ public class OrderTimeoutTask {
         RLock lock = redissonClient.getLock("order:timeout:local");
         lock.lock(10, TimeUnit.SECONDS);
         try {
-            Set set = bladeRedis.zRange(CacheBizConstant.TIMEOUT_ORDER_LIST, 0, 5);
-            if (CollUtil.isNotEmpty(set)) {
-                for (Object next : set) {
-                    long score = Math.round(bladeRedis.zScore(CacheBizConstant.TIMEOUT_ORDER_LIST, next));
-                    long currentSeconds = DateUtil.currentSeconds();
-                    if (currentSeconds >= score) {
-                        log.info("处理超时订单,orderId[{}]", next);
-                        orderService.orderTimeout((Long) next, null);
-                        bladeRedis.zRem(CacheBizConstant.TIMEOUT_ORDER_LIST, next);
-                    }
+            List<Order> list = orderService.lambdaQuery()
+                    .eq(Order::getOrderState, OrderStateEnum.WAIT_PAY.getValue())
+                    .lt(Order::getCreateTime, DateUtils.addMinutes(new Date(), -30))
+                    .list();
+            if (CollUtil.isNotEmpty(list)) {
+                for (Order next : list) {
+                    log.info("处理超时订单,orderId[{}]", next.getId());
+                    orderService.orderTimeout(next.getId(), null);
+                    bladeRedis.zRem(CacheBizConstant.TIMEOUT_ORDER_LIST, next.getId());
                 }
             }
         } catch (Exception e) {