package com.malk.hake.schedule;

import com.malk.hake.service.HKClient;
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 HKScheduleTask {

    @Autowired
    private HKClient hkClient;

    /**
     * 同步通讯录: 早上6:00  中午11:30    下午16:00    晚上19:30
     */
    @Scheduled(cron = "0 0 6,16 * * ? ")
    public void timer_1() {
        try {
            hkClient.syncContact();
        } catch (Exception e) {
            // 记录错误信息
            e.printStackTrace();
        }
    }

    @Scheduled(cron = "0 30 11,19 * * ? ")
    public void timer_2() {
        try {
            hkClient.syncContact();
        } catch (Exception e) {
            // 记录错误信息
            e.printStackTrace();
        }
    }

    /**
     * 同步付款: 每次凌晨1点
     */
    @Scheduled(cron = "0 0 1 * * ? ")
    public void timer_3() {
        try {
//            hkClient.syncMonitor("FKSQ");
        } catch (Exception e) {
            // 记录错误信息
            e.printStackTrace();
        }
    }

    /**
     * 同步预付款: 每次凌晨2点
     */
    @Scheduled(cron = "0 0 2 * * ? ")
    public void timer_4() {
        try {
//            hkClient.syncMonitor("YFKSQ");
        } catch (Exception e) {
            // 记录错误信息
            e.printStackTrace();
        }
    }
}