package com.malk.zhuogao.schedule;

import com.malk.zhuogao.service.ZSDClient_File;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * @EnableScheduling 开启定时任务 [配置参考McScheduleTask]
 */
@Slf4j
@Configuration
@EnableScheduling
@ConditionalOnProperty(name = {"spel.scheduling"})
public class ZSDcheduleTask {

    @Autowired
    private ZSDClient_File zsdClient_file;

    /**
     * 15分钟拉取一次文件记录
     */
    @Scheduled(cron = "0 0/15 * * * ?")
    public void syncDingTalkFailedList() {
        try {
            long endTime = new Date().getTime();
            long startTime = endTime - 15 * 60 * 1000L;
            zsdClient_file.syncFileRecords(startTime, endTime, 500, null);
        } catch (Exception e) {
            // 记录错误信息
            e.printStackTrace();
        }
    }
}