package com.malk.hangshi.schedule;

import com.malk.hangshi.service.HSService;
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;

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

    @Autowired
    private HSService hsService;

    /**
     * 每天凌晨4点同步
     */
    @Scheduled(cron = "0 0 4 * * ? ")
    public void syncDingTalkFailedList() {
        try {
            hsService.getDeptInfo(true);
        } catch (Exception e) {
            // 记录错误信息
            e.printStackTrace();
        }
    }

    /**
     * 每天8点同步
     */
    @Scheduled(cron = "0 0 3 * * ? ")
    public void syncHangShiInfo() {
        try {
            hsService.syncHangShiInfo();
        } catch (Exception e) {
            // 记录错误信息
            e.printStackTrace();
        }
    }
}