liujie
2026-09-09 39f6fca28e3f78abe48f08e474ec011abb990b36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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<Long> 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);
            }
        }
    }
}