package com.njcn.relational.job;

import cn.hutool.core.date.DatePattern;
import com.njcn.relational.service.SyncTwoDmExportService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * data-migration
 *
 * @author cdf
 * @date 2026/5/29
 */
@Component
@RequiredArgsConstructor
@Profile("query_up")
public class reportJob {

    private final SyncTwoDmExportService syncTwoDmExportService;


    /**
     * 二区查询导出数据
     * 定时导出数据 - 每天早上2点执行
     * @author cdf
     * @date 2026/5/29
     */
    @Scheduled(cron = "0 40 4 * * ?")
    public void twoExport(){
        String date = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern(DatePattern.PURE_DATE_PATTERN));
        syncTwoDmExportService.syncAllFullTables(date);
    }



    /**
     * 定时清楚本地数据，默认保留一周
     * 定时导出数据 - 每天早上3点执行
     * @author cdf
     * @date 2026/5/29
     */
    @Scheduled(cron = "0 33 5 * * ?")
    public void removeTwoLocal(){
        syncTwoDmExportService.cleanLocalFiles(7);
    }



}
