package com.moka.gdtauto.task;

import java.time.LocalDateTime;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.moka.gdtauto.service.AdPlanDailyReportService;
import com.plumelog.core.TraceId;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;


/**
 * 广告日报
 * 
 */
@Component
@AllArgsConstructor
@Slf4j
public class AdPlanDailyReportSyncTask {
    
    private final AdPlanDailyReportService adPlanDailyReportService;
    @Scheduled(cron = "0 0 * * * *")
    @SchedulerLock(name = "syncReqDailyReport", lockAtMostFor = "4m", lockAtLeastFor = "1m")
    public void syncReqDailyReport() {
        try {
            TraceId.set();
            log.info("[syncReqDailyReport] 开始同步广告播放口径日报");
            LocalDateTime start = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
            LocalDateTime end = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59);
            adPlanDailyReportService.syncReqDailyReport(null, start, end);
        } catch (Exception e) {
            log.error("[syncReqDailyReport] 同步广告播放口径日报异常", e);
        }
    }

    @Scheduled(cron = "0 10 * * * *")
    @SchedulerLock(name = "syncRepDailyReport", lockAtMostFor = "4m", lockAtLeastFor = "1m")
    public void syncRepDailyReport() {
        try {
            TraceId.set();
            log.info("[syncRepDailyReport] 开始同步转化回传口径日报");
            LocalDateTime start = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
            LocalDateTime end = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59);
            adPlanDailyReportService.syncRepDailyReport(null,start, end);
        } catch (Exception e) {
            log.error("[syncRepDailyReport] 同步转化回传口径日报异常", e);
        }
    }
}
