package main

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

var e *ext.ExtractTask

func init()  {
	log.Debug("配置文件准备完毕...")
	ul.InitExt()
}

func main()  {
	e = &ext.ExtractTask{}
	e.InitCityInfo()  		//初始化-抽取城市
	log.Debug("城市抽取加载完毕...")
	ext.InitCheckCity()  	//初始化-校验城市

	fromSourceDataExtCity()
}
//抽取城市-源表-
func fromSourceDataExtCity()  {
	q := map[string]interface{}{}
	sess := ul.SaveMgo.GetMgoConn()
	defer ul.SaveMgo.DestoryMongoConn(sess)
	iter := sess.DB(ul.SaveMgo.DbName).C(ul.SaveColl).Find(&q).Iter()
	total,isok,ischeck:=0,0,0
	for tmp := map[string]interface{}{}; iter.Next(&tmp); total++{
		if total%10000==0 {
			log.Debug("cur index ",total,isok,ischeck)
		}
		tmpid := qu.ObjToString(tmp["_id"])
		source_field := map[string]interface{}{}
		for k,_ := range ul.SF {
			source_field[k] = qu.ObjToString(tmp[k])
		}
		if len(source_field)>0 {
			ext_res := e.NewExtractCity(source_field)
			isok++
			ul.SaveMgo.UpdateByStringId(ul.SaveColl,tmpid, map[string]interface{}{
				"$set": ext_res,
			})
			if len(ext_res)>0 { //审查-城市
				update_check := make(map[string]interface{},0)
				ext.GetCheckDataCity(ext_res,&update_check)
				if len(update_check)>0 {
					ischeck++
					ul.SaveMgo.UpdateByStringId(ul.SaveColl,tmpid, map[string]interface{}{
						"$set": update_check,
					})
				}
			}
		}
		tmp = map[string]interface{}{}
	}
	log.Debug("is over ",total,isok,ischeck)
}





