package com.kxs.adminap;

import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.kxs.adminap.config.Base;
import com.kxs.adminap.service.DbConn;

import jakarta.annotation.PostConstruct;

@SpringBootApplication
public class AdminapApplication {

	@PostConstruct
	void started() {
		TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
		// initMainServer();
	}

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


	//获取数据库模型
	private void initMainServer() {
		Dictionary<String, Map<String, String>> tables = new Hashtable<>();
		List<Dictionary<String, Object>> tablecollection = DbConn.Query("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = 'KxsMainServer'", Base.main_url, Base.main_username, Base.main_password);
		for (Dictionary<String, Object> subtable : tablecollection)
		{
			Map<String, String> Columns = new Hashtable<>();
			List<Dictionary<String, Object>> columncollection = DbConn.Query("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = 'KxsMainServer' and TABLE_NAME='" + subtable.get("TABLE_NAME").toString() + "'", Base.main_url, Base.main_username, Base.main_password);
			for (Dictionary<String, Object> column : columncollection)
			{
				String datatype = column.get("DATA_TYPE").toString();
				if (datatype == "decimal")
				{
					datatype = "numeric";
				}
				Columns.put(column.get("COLUMN_NAME").toString(), datatype);
			}
			tables.put(subtable.get("TABLE_NAME").toString(), Columns);
		}
		Base.main_tables = tables;
	}
}
