package com.cm.common.dingding.task;

import com.cm.common.dingding.config.properties.DingDingAppProperties;
import com.cm.common.dingding.manager.app.DingDingAppManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: DingDingTask
 * @Description: 钉钉任务
 * @Author: WangGeng
 * @Date: 2020/8/31 20:09
 * @Version: 1.0
 **/
@Configuration
@EnableScheduling
public class DingDingTask {

    private static final Logger LOG = LoggerFactory.getLogger(DingDingTask.class);
    @Autowired
    private DingDingAppProperties dingDingAppProperties;

    @Scheduled(cron = "0 0/10 * * * ?")
    public void refreshAppAccessToken() {
        if (dingDingAppProperties.getActive() == null || !dingDingAppProperties.getActive()) {
            LOG.debug("钉钉应用未激活");
            return;
        }
        DingDingAppManager.getInstance().refreshAccessToken();
    }

}
