package main

import (
	log "github.com/donnie4w/go-logger/logger"
	qu "qfw/util"
)

var (
	Old_Mgo, Save_Mgo                 *MongodbSim
	Spi_Mgo, Qyxy_Mgo                 *MongodbSim
	MysqlMedicalTool, MysqlGlobalTool *Mysql
	IsLocal                           bool
	TimeLayout                        = "2006-01-02 15:04:05"
	TimeTmeplate                      = "2006-01-02"
	RegionCodeData                    = map[string]string{}
)

func initClass() {
	initMgo()
	initMysql()
	initCode()
}

//初始化mgo
func initMgo() {
	//Spi_Mgo = &MongodbSim{
	//	MongodbAddr: "127.0.0.1:12004",
	//	DbName:      "mixdata",
	//	Size:        10,
	//	UserName:    "",
	//	Password:    "",
	//}
	//Spi_Mgo.InitPool()
	//return

	if IsLocal {
		Old_Mgo = &MongodbSim{
			MongodbAddr: "127.0.0.1:27017",
			DbName:      "medical",
			Size:        10,
			UserName:    "",
			Password:    "",
		}
		Old_Mgo.InitPool()

		Save_Mgo = &MongodbSim{
			MongodbAddr: "127.0.0.1:27017",
			DbName:      "medical",
			Size:        10,
			UserName:    "",
			Password:    "",
		}
		Save_Mgo.InitPool()

		Spi_Mgo = &MongodbSim{
			MongodbAddr: "127.0.0.1:27017",
			DbName:      "medical",
			Size:        10,
			UserName:    "",
			Password:    "",
		}
		Spi_Mgo.InitPool()

		Qyxy_Mgo = &MongodbSim{
			MongodbAddr: "127.0.0.1:27017",
			DbName:      "medical",
			Size:        10,
			UserName:    "",
			Password:    "",
		}
		Qyxy_Mgo.InitPool()
	} else {
		Old_Mgo = &MongodbSim{
			MongodbAddr: "172.17.4.87:27080",
			DbName:      "py_theme",
			Size:        10,
			UserName:    "",
			Password:    "",
		}
		Old_Mgo.InitPool()

		Save_Mgo = &MongodbSim{
			MongodbAddr: "172.17.4.87:27080",
			DbName:      "zk_sqldata",
			Size:        10,
			UserName:    "",
			Password:    "",
		}
		Save_Mgo.InitPool()

		Spi_Mgo = &MongodbSim{
			MongodbAddr: "172.17.4.181:27001",
			DbName:      "mixdata",
			Size:        10,
			UserName:    "",
			Password:    "",
		}
		Spi_Mgo.InitPool()

		Qyxy_Mgo = &MongodbSim{
			MongodbAddr: "172.17.145.163:27083,172.17.4.187:27082",
			DbName:      "mixdata",
			Size:        10,
			UserName:    "zhengkun",
			Password:    "zk@123123",
		}
		Qyxy_Mgo.InitPool()
	}
}

func initMysql() {
	username, password := "zhengkun", "Zk#20220824"
	address := "127.0.0.1:15001"
	if !IsLocal {
		address = "172.17.4.242:4000"
	}
	MysqlMedicalTool = &Mysql{
		Address:  address,
		UserName: username,
		PassWord: password,
		DBName:   "medical_field_data",
	}
	MysqlMedicalTool.Init()

	MysqlGlobalTool = &Mysql{
		Address:  address,
		UserName: username,
		PassWord: password,
		DBName:   "global_common_data",
	}
	MysqlGlobalTool.Init()

}

func initCode() {
	data_regions := MysqlGlobalTool.Find("code_area", nil, "", "", -1, -1)
	//先构建所有一级数据
	for _, v := range *data_regions {
		area := qu.ObjToString(v["area"])
		city := qu.ObjToString(v["city"])
		district := qu.ObjToString(v["district"])
		code := qu.ObjToString(v["code"])
		key := area + "~" + city + "~" + district + "~"
		RegionCodeData[key] = code
	}
	log.Debug("地域信息数量~", len(RegionCodeData))
}
