package com.datacenter.job;

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

import java.time.LocalDate;

/**
 * 今日概览定时任务 —— 每小时整点执行。
 * 每次同时计算"不含内部账户"和"含内部账户"两个变体，写入：
 *   - stat_today_overview（今日运营概览）
 *   - stat_contract_pnl（合约盈亏统计）
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TodayOverviewJob {

    private final StatTodayOverviewService statTodayOverviewService;
    private final StatContractPnlService   statContractPnlService;

    @Scheduled(cron = "0 0 * * * *")
    public void run() {
        log.info("[TodayOverviewJob] 定时任务触发");
        statTodayOverviewService.computeAndSaveBoth(LocalDate.now());
        statContractPnlService.computeAndSaveBoth(LocalDate.now());
    }
}
