package ink.wgink.mongo.menu.service.init;

import ink.wgink.interfaces.init.IInitMongoData;
import ink.wgink.interfaces.menu.IMongoMenuService;
import ink.wgink.properties.ServerProperties;
import ink.wgink.util.thread.CachedThreadPoolUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName: InitMongoMenu
 * @Description: 初始化mongo菜单
 * @Author: wanggeng
 * @Date: 2022/5/24 21:14
 * @Version: 1.0
 */
@Component
public class InitMongoMenu implements IInitMongoData {

    private static final Logger LOG = LoggerFactory.getLogger(InitMongoMenu.class);

    @Autowired
    private IMongoMenuService mongoMenuService;
    @Autowired
    private ServerProperties serverProperties;

    @Override
    public void init() {
        if (serverProperties.getMasterNode()) {
            LOG.debug("MASTER-NODE: {}" + serverProperties.getMasterNode());
            CachedThreadPoolUtil.execute(() -> {
                // 初始化所有账号内容
                System.out.println("****************************");
                System.out.println("** SYSTEM MENU INIT START **");
                System.out.println("****************************");
                long startTime = System.currentTimeMillis();
                mongoMenuService.updateAllSystemMenu();
                long endTime = System.currentTimeMillis();
                System.out.println("***************************");
                System.out.println("** SYSTEM MENU INIT END  **");
                System.out.println("***************************");
                LOG.debug("SYSTEM MENU INIT USED TIME: {}ms", (endTime - startTime) / 1000L);
            });
        }
    }

}
