fix: 微信支付问题,新增补偿机制。
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.intc.weixin.task;
|
||||
|
||||
import com.intc.weixin.service.PayOrderBusinessService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 支付订单补偿定时任务
|
||||
* 定期扫描状态为"未支付/支付中"但已有prepayId的订单,
|
||||
* 主动向微信支付查询实际状态,对已支付成功但回调丢失的订单进行补偿处理。
|
||||
*
|
||||
* 解决问题:用户实际已付款成功,但因网络/服务器等原因未收到微信支付回调通知,
|
||||
* 导致订单一直停留在未支付状态。
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnBean(PayOrderBusinessService.class)
|
||||
public class PayOrderCompensationTask {
|
||||
|
||||
private final PayOrderBusinessService payOrderBusinessService;
|
||||
|
||||
/**
|
||||
* 每5分钟执行一次订单补偿扫描
|
||||
* 查询已创建超过5分钟但未超过24小时的未完成订单,
|
||||
* 向微信主动查单,补偿漏掉的回调。
|
||||
*/
|
||||
@Scheduled(fixedDelay = 300000)
|
||||
public void compensateOrders() {
|
||||
try {
|
||||
int count = payOrderBusinessService.compensateUnpaidOrders();
|
||||
if (count > 0) {
|
||||
log.info("[支付补偿定时任务] 本次补偿了 {} 笔订单", count);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[支付补偿定时任务] 执行异常: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user