package main

import (
	"log"
	qu "qfw/util"
	"time"
)

var (
	sysconfig    					map[string]interface{}
	bid_mgo,ext_mgo,qy_mgo,py_mgo  	*MongodbSim
	py_coll_one,py_coll_two			string
	bid_coll,qy_coll,ext_coll		string
	timeLayout = "2006-01-02"
	bid_tagText,qy_tagText  		[][]string
	xm_spicode,jp_spicode,kb_spicode,pb_spicode	map[string]string
)

func initMgo()  {
	bidconf := sysconfig["bid_mgodb"].(map[string]interface{})
	bid_coll = qu.ObjToString(bidconf["coll"])
	bid_mgo = &MongodbSim{
		MongodbAddr: bidconf["addr"].(string),
		DbName:      bidconf["db"].(string),
		Size:        qu.IntAllDef(bidconf["pool"], 5),
		UserName: 	 bidconf["u_name"].(string),
		Password: 	 bidconf["p_word"].(string),
	}
	bid_mgo.InitPool()

	extconf := sysconfig["ext_mgodb"].(map[string]interface{})
	ext_coll = qu.ObjToString(extconf["coll"])
	ext_mgo = &MongodbSim{
		MongodbAddr: extconf["addr"].(string),
		DbName:      extconf["db"].(string),
		Size:        qu.IntAllDef(extconf["pool"], 5),
	}
	ext_mgo.InitPool()

	qyconf := sysconfig["qy_mgodb"].(map[string]interface{})
	qy_coll = qu.ObjToString(qyconf["coll"])
	qy_mgo = &MongodbSim{
		MongodbAddr: qyconf["addr"].(string),
		DbName:      qyconf["db"].(string),
		Size:        qu.IntAllDef(qyconf["pool"], 5),
		UserName: 	 qyconf["u_name"].(string),
		Password: 	 qyconf["p_word"].(string),
	}
	qy_mgo.InitPool()


	pyconf := sysconfig["py_mgodb"].(map[string]interface{})
	py_coll_one = pyconf["coll_1"].(string)
	py_coll_two = pyconf["coll_2"].(string)
	py_mgo = &MongodbSim{
		MongodbAddr: pyconf["addr"].(string),
		DbName:      pyconf["db"].(string),
		Size:        qu.IntAllDef(pyconf["pool"], 5),
		UserName: 	 pyconf["u_name"].(string),
		Password: 	 pyconf["p_word"].(string),
	}
	py_mgo.InitPool()
}

func initConfig()  {
	bid_arr := sysconfig["bid_tagText"].([]interface{})
	for _,v := range bid_arr{
		v1 := v.([]interface{})
		new_v := qu.ObjArrToStringArr(v1)
		bid_tagText = append(bid_tagText,new_v)
	}
	qy_arr := sysconfig["qy_tagText"].([]interface{})
	for _,v := range qy_arr{
		v1 := v.([]interface{})
		new_v := qu.ObjArrToStringArr(v1)
		qy_tagText = append(qy_tagText,new_v)
	}


	spi_1 := qu.ObjArrToStringArr(sysconfig["xm_spicode"].([]interface{}))
	spi_2 := qu.ObjArrToStringArr(sysconfig["jp_spicode"].([]interface{}))
	spi_3 := qu.ObjArrToStringArr(sysconfig["kb_spicode"].([]interface{}))
	spi_4 := qu.ObjArrToStringArr(sysconfig["pb_spicode"].([]interface{}))

	xm_spicode = map[string]string{}
	jp_spicode = map[string]string{}
	kb_spicode = map[string]string{}
	pb_spicode = map[string]string{}


	for _,v := range spi_1{
		xm_spicode[v] = v
	}
	for _,v := range spi_2{
		jp_spicode[v] = v
	}
	for _,v := range spi_3{
		kb_spicode[v] = v
	}
	for _,v := range spi_4{
		pb_spicode[v] = v
	}
	log.Println(len(xm_spicode),len(jp_spicode),len(kb_spicode),len(pb_spicode))
}


func init()  {
	qu.ReadConfig(&sysconfig)
	initMgo()
	initConfig()
	initBidata()
	initQydata()

	//初始化完毕
	log.Println("初始化~完毕...")
}
func main()  {

	//go exportExtdata() //评标
	//go exportProjectSetData()//项目
	//go exportBidata() //招标-中标-开标

	//go exportQydataOne()
	//go exportQydataTwo()

	time.Sleep(99999*time.Hour)



}