package ink.wgink.module.wechat.miniapp.startup;

import ink.wgink.module.wechat.miniapp.manager.MiniappManager;
import ink.wgink.properties.wechat.miniapp.MiniappProperties;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @ClassName: MiniappStartUp
 * @Description:
 * @Author: wanggeng
 * @Date: 2022/6/22 22:37
 * @Version: 1.0
 */
@Component
public class MiniappStartUp implements ApplicationRunner {

    private static final Logger LOG = LoggerFactory.getLogger(MiniappStartUp.class);
    @Autowired
    private MiniappProperties miniAppProperties;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        removeTimeoutMiniAppUser();
    }

    /**
     * 删除小程序超时用户，每10分钟执行一次
     */
    @Scheduled(cron = "0 0/10 * * * ?")
    public void removeTimeoutMiniAppUser() {
        if (!miniAppProperties.getActive()) {
            return;
        }
        MiniappManager.getInstance().removeTimeout();
    }
}
