package com.datacenter.job;

import com.datacenter.service.FollowerCleanupService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 跟单员余额不足清理定时任务
 *
 * <p>每天 0 点执行一次，扫描所有交易员的跟单员列表：
 * 若跟单员账户余额 &lt; 交易员配置的最小跟单金额，且该跟单员当前无持仓，
 * 则自动将其从该交易员的跟单列表中移除（follow.status=30）。</p>
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class FollowerCleanupJob {

    private final FollowerCleanupService cleanupService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void run() {
        log.info("跟单员余额不足清理任务开始...");
        try {
            int count = cleanupService.checkAndRemoveFollowers();
            log.info("跟单员余额不足清理任务完成，本次移除 {} 条跟随关系", count);
        } catch (Exception e) {
            log.error("跟单员余额不足清理任务异常", e);
        }
    }
}
