package com.example.demo;

import com.example.demo.common.GlobalConfig;
import com.example.demo.common.GlobalRoot;
import com.example.demo.module.user.Player;
import com.example.demo.test.Tester;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import pers.jc.engine.JCEngine;
import pers.jc.sql.CURD;

import java.util.HashMap;
import java.util.Map;

/**
 * 入口启动类
 */
@SpringBootApplication
public class SmartBowBusinessServerApplication {

	public static void main(String[] args) {
		initDataBase();
		SpringApplication.run(SmartBowBusinessServerApplication.class, args);
	}

	@EventListener
	public void deploymentVer(ApplicationReadyEvent event) {
		System.out.println("SpringBoot准备完毕！");
		new Thread(() -> {
			JCEngine.defaultAuthValue = true;
			JCEngine.scanPackage("com.example.demo.module");
			JCEngine.boot(11333, "/SmartBowBusinessServerSK", Player.class);
		}).start();
	}

	public static void initDataBase() {
		Map<String, Object> config = new HashMap<>();
		if (GlobalConfig.isLinux) {
			config.put("username", "root");
			config.put("password", "49258ab36b97518c");
		}
		config.put("database", "smart_bow");
		GlobalRoot.db = new CURD(config);
	}
}
