package com.bizzan.bitrade.job;

import com.bizzan.bitrade.service.AirdropPoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 质押空投自动发放定时任务
 * 每天凌晨 2 点，对启用自动空投的质押配置，向当日未发放的质押中订单创建待领取记录
 */
@Component
@Slf4j
public class AirdropAutoDistributeJob {

    @Autowired
    private AirdropPoolService airdropPoolService;

    @Scheduled(cron = "0 0 2 * * *")
    public void processAutoAirdropDistribute() {
        log.info("[自动空投任务] 开始执行...");
        try {
            int count = airdropPoolService.runAutoDistribute();
            log.info("[自动空投任务] 执行完成，成功发放 {} 笔", count);
        } catch (Exception e) {
            log.error("[自动空投任务] 执行异常：{}", e.getMessage(), e);
        }
    }
}
