package com.datacenter.job;

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

/**
 * 体验金防刷风控定时任务
 * 每 4 小时扫描一次，对满足刷返佣预警条件的用户生成预警记录
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ExperienceGiftRiskJob {

    private final ExperienceGiftRiskAlertService riskAlertService;

    @Scheduled(cron = "0 1 0,4,8,12,16,20 * * ?")
    public void checkRisk() {
        log.info("体验金防刷风控任务开始...");
        try {
            int count = riskAlertService.checkAndGenerateAlerts();
            log.info("体验金防刷风控任务完成，新增预警 {} 条", count);
        } catch (Exception e) {
            log.error("体验金防刷风控任务异常", e);
        }
    }
}
