package com.tourguide.modules.finance.service; import com.tourguide.modules.finance.mapper.GuideWithdrawalMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.List; /** 恢复因网络异常或异步处理中断的划账、取现流程。 */ @Service public class GuideWithdrawalPayoutScheduler { private static final Logger log = LoggerFactory.getLogger(GuideWithdrawalPayoutScheduler.class); private static final int BATCH_SIZE = 100; private final GuideWithdrawalMapper withdrawalMapper; private final GuideWithdrawalPayoutService payoutService; public GuideWithdrawalPayoutScheduler(GuideWithdrawalMapper withdrawalMapper, GuideWithdrawalPayoutService payoutService) { this.withdrawalMapper = withdrawalMapper; this.payoutService = payoutService; } @Scheduled(fixedDelayString = "${tourguide.finance.withdrawal-payout-scan-delay-millis:30000}") public void resumePendingPayouts() { List ids = withdrawalMapper.selectPendingPayoutIds( LocalDateTime.now().minusSeconds(10), BATCH_SIZE); for (Long id : ids) { try { payoutService.advance(id); } catch (RuntimeException exception) { log.error("恢复提现资金流程失败,withdrawalId={}", id, exception); } } } }