package main

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

//地域
func SaveOnlineTidbRegionInfo() {
	infos, _ := Source_Mgo.Find("zktest_mysql_area", map[string]interface{}{}, map[string]interface{}{
		"_id": 1,
	}, nil)
	log.Debug(len(infos))
	for _, v := range infos {
		info := map[string]interface{}{}
		info["name"] = qu.ObjToString(v["name"])
		info["code"] = qu.ObjToString(v["code"])
		info["pcode"] = qu.ObjToString(v["pcode"])
		info["level"] = qu.IntAll(v["level"])
		InsertMysqlDevData("seo_area", info, info)
	}
	log.Debug("is over ~")
}

//行业
func SaveOnlineTidbIndustryInfo() {
	infos, _ := Source_Mgo.Find("zktest_mysql_industry_info", map[string]interface{}{}, map[string]interface{}{
		"_id": 1,
	}, nil)
	log.Debug(len(infos))
	for _, v := range infos {
		info := map[string]interface{}{}
		info["name"] = qu.ObjToString(v["name"])
		info["letter"] = qu.ObjToString(v["letter"])
		info["class_1"] = qu.ObjToString(v["class_1"])
		info["class_2"] = qu.ObjToString(v["class_2"])
		InsertMysqlDevData("seo_industry", info, info)
	}
	log.Debug("is over ~")
}

//资源词
func SaveOnlineTidbResourceInfo() {
	sess := Source_Mgo.GetMgoConn()
	defer Source_Mgo.DestoryMongoConn(sess)
	q := map[string]interface{}{}
	it := sess.DB(Source_Mgo.DbName).C("zktest_mysql_resource_info").Find(&q).Sort("_id").Iter()
	total := 0
	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
		if total%10000 == 0 {
			log.Debug("cur index ", total)
		}
		delete(tmp, "_id")
		InsertMysqlDevData("seo_resource", tmp, tmp)
		tmp = make(map[string]interface{})
	}
	log.Debug("is over ~", total)
}
