package io.renren.modules.kubesphere;

import io.renren.modules.kubesphere.interceptor.KubeSphereTokenManger;
import io.renren.modules.kubesphere.service.OauthTokenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时刷新token
 *
 * @author chenrj
 * @email 1412736935@qq.com
 * @since 2021/8/18
 */
@Component
@EnableScheduling   // 1.开启定时任务
public class ScheduledEvent {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    OauthTokenService oauthTokenService;

    @Scheduled(fixedRate = 10000)
    public void refreshToken() {
//        UserEntity user = KubeSphereTokenManger.get().getUser();
        String token = KubeSphereTokenManger.get().getToken();
        logger.info("token:" + token);
//        if(user != null) {
//            String token = oauthTokenService.oauthToken(user);
//            KubeSphereTokenManger.get().setToken(token);
//            logger.info("scheduleRefreshToken:"+ token);
//        }
    }

}
