|
@@ -1,20 +1,21 @@
|
|
package org.springblade.modules.quartz.task;
|
|
package org.springblade.modules.quartz.task;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.time.DateUtils;
|
|
import org.redisson.api.RLock;
|
|
import org.redisson.api.RLock;
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
import org.springblade.common.constant.CacheBizConstant;
|
|
import org.springblade.common.constant.CacheBizConstant;
|
|
|
|
+import org.springblade.common.enums.OrderStateEnum;
|
|
import org.springblade.core.redis.cache.BladeRedis;
|
|
import org.springblade.core.redis.cache.BladeRedis;
|
|
|
|
+import org.springblade.modules.finance.entity.Order;
|
|
import org.springblade.modules.finance.service.IOrderService;
|
|
import org.springblade.modules.finance.service.IOrderService;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
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;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,16 +40,15 @@ public class OrderTimeoutTask {
|
|
RLock lock = redissonClient.getLock("order:timeout:local");
|
|
RLock lock = redissonClient.getLock("order:timeout:local");
|
|
lock.lock(10, TimeUnit.SECONDS);
|
|
lock.lock(10, TimeUnit.SECONDS);
|
|
try {
|
|
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) {
|
|
} catch (Exception e) {
|