package com.cm.common.dingding.startup;

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.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: DingDingStartUp
 * @Description: 钉钉启动
 * @Author: WangGeng
 * @Date: 2020/8/31 20:10
 * @Version: 1.0
 **/
@Configuration
public class DingDingStartUp implements ApplicationRunner {
    private static final Logger LOG = LoggerFactory.getLogger(DingDingStartUp.class);

    @Autowired
    private DingDingAppProperties dingDingAppProperties;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (dingDingAppProperties.getActive() == null || !dingDingAppProperties.getActive()) {
            LOG.debug("钉钉应用未激活");
            return;
        }
        DingDingAppManager dingDingAppManager = DingDingAppManager.getInstance();
        dingDingAppManager.setDingDingAppProperties(dingDingAppProperties);
        dingDingAppManager.refreshAccessToken();
    }
}
