|
@@ -40,6 +40,8 @@ public class OrderCancelService {
|
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
|
private final AuctionOrderRepo auctionOrderRepo;
|
|
private final AuctionOrderRepo auctionOrderRepo;
|
|
|
private final AuctionOrderService auctionOrderService;
|
|
private final AuctionOrderService auctionOrderService;
|
|
|
|
|
+ private final PhotoAssetService photoAssetService;
|
|
|
|
|
+ private final PhotoAssetRepo photoAssetRepo;
|
|
|
|
|
|
|
|
private static int orderCancelInterval = 210;
|
|
private static int orderCancelInterval = 210;
|
|
|
|
|
|
|
@@ -103,6 +105,22 @@ public class OrderCancelService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Scheduled(fixedRate = 30000, initialDelay = 30000)
|
|
|
|
|
+ @RedisLock(value = "pic_order_batch_cancel", expire = 3, unit = TimeUnit.MINUTES)
|
|
|
|
|
+ public void batchCancelPicOrder() {
|
|
|
|
|
+ List<PhotoAsset> orders = photoAssetRepo.findByOrderStatusAndCreatedAtBeforeAndDelFalse(OrderStatus.NOT_PAID,
|
|
|
|
|
+ LocalDateTime.now().minusSeconds(orderCancelInterval));
|
|
|
|
|
+ orders.forEach(o -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ PhotoAsset order = photoAssetRepo.findById(o.getId()).orElseThrow(new BusinessException("订单不存在"));
|
|
|
|
|
+ if (order.getOrderStatus() == OrderStatus.NOT_PAID && canCancel(order.getId().toString())) {
|
|
|
|
|
+ photoAssetService.cancel(order);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception ignored) {
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private boolean canCancel(String id) {
|
|
private boolean canCancel(String id) {
|
|
|
String channel = null;
|
|
String channel = null;
|
|
|
Object payTmp = redisTemplate.opsForValue().get(RedisKeys.PAY_TMP + id);
|
|
Object payTmp = redisTemplate.opsForValue().get(RedisKeys.PAY_TMP + id);
|