package com.kym.admin.jobs;

import com.kym.service.SettlementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 结算定时任务
 *
 * @author skyline
 * @since 2026-05-14
 */
@Component
@Slf4j
public class SettlementJob {

    private final SettlementService settlementService;

    public SettlementJob(SettlementService settlementService) {
        this.settlementService = settlementService;
    }

    /**
     * 每月5日 15:30 执行上月结算
     */
    @Async("AsyncExecutor")
    @Scheduled(cron = "0 30 15 5 * ?")
    public void executeMonthlySettlement() {
        log.info("月度结算定时任务-开始");
        try {
            settlementService.executeMonthlySettlement();
        } catch (Exception e) {
            log.error("月度结算执行失败", e);
        }
        log.info("月度结算定时任务-结束");
    }
}
