package com.jeesharp.business.modules.finance.profitsharing.application;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 分账失败自动重试定时任务。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ProfitSharingRetryJob {

    private final ProfitSharingApplicationService profitSharingApplicationService;

    @XxlJob("profitSharingRetryJob")
    public void execute() {
        XxlJobHelper.log("param={}", XxlJobHelper.getJobParam());
        int count = profitSharingApplicationService.retryFailedShares();
        XxlJobHelper.log("retried={}", count);
        if (count > 0) {
            log.info("分账自动重试处理 {} 条记录", count);
        }
    }
}
