package com.njcn.relational.job;

import cn.hutool.core.date.DatePattern;
import com.njcn.relational.service.SyncThreeDmParseService;
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("insert_up")
public class importJob {


    private final SyncThreeDmParseService syncThreeDmParseService;



    /**
     * 三区导入数据
     * 定时导出数据 - 每天早上3点执行
     * @author cdf
     * @date 2026/5/29
     */
    @Profile("insert_up")
    @Scheduled(cron = "0 55 4 * * ?")
    public void threeImport(){
        String date = LocalDate.now().minusDays(1).format(DateTimeFormatter.ofPattern(DatePattern.PURE_DATE_PATTERN));
        syncThreeDmParseService.syncFullTables(date);
    }



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

}
