package com.ruoyi.novel.config;

import com.ruoyi.novel.service.IAdService;
import com.ruoyi.novel.service.IFinanceService;
import com.ruoyi.novel.service.IVoteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;


// ScheduledTasks.java
@Configuration
@EnableScheduling
public class ScheduledTasks {
    private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);
    @Autowired
    private IAdService adService;

    @Autowired
    private IVoteService voteService;

    @Autowired
    private IFinanceService financeService;

    /**
     * 每5分钟重试失败的广告同步
     */
    @Scheduled(fixedRate = 300000)
    public void retryAdSync() {
        adService.retryFailedSyncs();
    }

    /**
     * 每10分钟重试失败的PHP通知
     */
    @Scheduled(cron = "0 */10 * * * ?")
    public void retryVoteNotify() {
        voteService.retryFailedNotifications();
    }

    /**
     * 每天凌晨2点同步分账数据
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void syncRoyaltyData() {
        financeService.syncRoyaltyData();
    }

    /**
     * 每小时刷新投票计数器
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void resetVoteCounters() {
        // 实际应基于每日重置
        log.info("Resetting vote counters...");
        // 计数器重置逻辑
    }
}