|
|
@@ -59,66 +59,66 @@ public class OrderExpireHandler {
|
|
|
private IFsStoreOrderScrmService fsStoreOrderService;
|
|
|
|
|
|
|
|
|
- @Scheduled(fixedDelay = 60_000) // 每分钟跑一次
|
|
|
- public void handleUnpaidOrders() {
|
|
|
- // 全局锁:防止多实例同时执行任务(粒度粗,仅控制任务入口)
|
|
|
- RLock globalLock = redissonClient.getLock("order-expire-handler-global-lock");
|
|
|
- try {
|
|
|
- if (globalLock.tryLock(LOCK_WAIT_TIME, LOCK_LEASE_TIME, TimeUnit.SECONDS)) {
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- log.info("开始处理超时未支付订单,当前时间:{}", now);
|
|
|
-
|
|
|
- // 获取配置时间
|
|
|
- String json = configService.selectConfigByKey("store.config");
|
|
|
- com.fs.store.config.StoreConfig config = JSONUtil.toBean(json, com.fs.store.config.StoreConfig.class);
|
|
|
- if (config == null || config.getUnPayTime() == null) {
|
|
|
- log.error("未获取到门店配置,unPayTime为空");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 查询所有待处理订单
|
|
|
- Map<String, Object> params = new HashMap<>(3);
|
|
|
- params.put("now", now);
|
|
|
- params.put("prescribeTimeoutMinutes", PRESCRIBE_TIMEOUT_MINUTES);
|
|
|
- params.put("unPayTime", config.getUnPayTime());
|
|
|
- List<FsStoreOrderScrm> orders = orderScrmMapper.selectTimeoutUnpaidOrders(params);
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(orders)) {
|
|
|
- log.info("暂无超时未支付订单需要处理");
|
|
|
- return;
|
|
|
- }
|
|
|
- log.info("共查询到{}个超时未支付订单,开始逐个处理", orders.size());
|
|
|
-
|
|
|
- for (FsStoreOrderScrm order : orders) {
|
|
|
- try {
|
|
|
- processExpiredOrder(order);
|
|
|
- log.info("订单{}处理完成,状态已更新为-3", order.getId());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("处理订单{}失败", order.getId(), e);
|
|
|
- // 记录失败订单,可后续补偿
|
|
|
- // failOrderService.recordFailOrder(order.getId(), "库存恢复失败:" + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.warn("获取全局分布式锁失败,跳过本次订单处理");
|
|
|
- }
|
|
|
- } catch (InterruptedException e) {
|
|
|
- Thread.currentThread().interrupt();
|
|
|
- log.error("获取全局锁时线程中断", e);
|
|
|
- } finally {
|
|
|
- if (globalLock.isHeldByCurrentThread()) {
|
|
|
- globalLock.unlock();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- void processExpiredOrder(FsStoreOrderScrm order) {
|
|
|
- Long orderId = order.getId();
|
|
|
- if (orderId == null) {
|
|
|
- log.warn("订单ID为空,跳过处理");
|
|
|
- return;
|
|
|
- }
|
|
|
- fsStoreOrderService.cancelOrderReuse(order);
|
|
|
- }
|
|
|
+// @Scheduled(fixedDelay = 60_000) // 每分钟跑一次
|
|
|
+// public void handleUnpaidOrders() {
|
|
|
+// // 全局锁:防止多实例同时执行任务(粒度粗,仅控制任务入口)
|
|
|
+// RLock globalLock = redissonClient.getLock("order-expire-handler-global-lock");
|
|
|
+// try {
|
|
|
+// if (globalLock.tryLock(LOCK_WAIT_TIME, LOCK_LEASE_TIME, TimeUnit.SECONDS)) {
|
|
|
+// LocalDateTime now = LocalDateTime.now();
|
|
|
+// log.info("开始处理超时未支付订单,当前时间:{}", now);
|
|
|
+//
|
|
|
+// // 获取配置时间
|
|
|
+// String json = configService.selectConfigByKey("store.config");
|
|
|
+// com.fs.store.config.StoreConfig config = JSONUtil.toBean(json, com.fs.store.config.StoreConfig.class);
|
|
|
+// if (config == null || config.getUnPayTime() == null) {
|
|
|
+// log.error("未获取到门店配置,unPayTime为空");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 查询所有待处理订单
|
|
|
+// Map<String, Object> params = new HashMap<>(3);
|
|
|
+// params.put("now", now);
|
|
|
+// params.put("prescribeTimeoutMinutes", PRESCRIBE_TIMEOUT_MINUTES);
|
|
|
+// params.put("unPayTime", config.getUnPayTime());
|
|
|
+// List<FsStoreOrderScrm> orders = orderScrmMapper.selectTimeoutUnpaidOrders(params);
|
|
|
+//
|
|
|
+// if (CollectionUtils.isEmpty(orders)) {
|
|
|
+// log.info("暂无超时未支付订单需要处理");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// log.info("共查询到{}个超时未支付订单,开始逐个处理", orders.size());
|
|
|
+//
|
|
|
+// for (FsStoreOrderScrm order : orders) {
|
|
|
+// try {
|
|
|
+// processExpiredOrder(order);
|
|
|
+// log.info("订单{}处理完成,状态已更新为-3", order.getId());
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("处理订单{}失败", order.getId(), e);
|
|
|
+// // 记录失败订单,可后续补偿
|
|
|
+// // failOrderService.recordFailOrder(order.getId(), "库存恢复失败:" + e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// log.warn("获取全局分布式锁失败,跳过本次订单处理");
|
|
|
+// }
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// Thread.currentThread().interrupt();
|
|
|
+// log.error("获取全局锁时线程中断", e);
|
|
|
+// } finally {
|
|
|
+// if (globalLock.isHeldByCurrentThread()) {
|
|
|
+// globalLock.unlock();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
+// void processExpiredOrder(FsStoreOrderScrm order) {
|
|
|
+// Long orderId = order.getId();
|
|
|
+// if (orderId == null) {
|
|
|
+// log.warn("订单ID为空,跳过处理");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// fsStoreOrderService.cancelOrderReuse(order);
|
|
|
+// }
|
|
|
|
|
|
}
|