package main

import (
	log "github.com/donnie4w/go-logger/logger"
	"github.com/go-ego/gse"
	"go.mongodb.org/mongo-driver/bson/primitive"
	qu "qfw/util"
	"regexp"
	"strings"
)
//分词
var GSE *gse.Segmenter  = &gse.Segmenter{}
var gseReg *regexp.Regexp = regexp.MustCompile("[(（）)/、]+")



//分类-医械查
func repairYiXieChaData(){
	log.Debug("开始补......数据")
	sess := save_mgo.GetMgoConn()
	defer save_mgo.DestoryMongoConn(sess)
	q := map[string]interface{}{}
	total,isok:=0,0
	it := sess.DB(save_mgo.DbName).C("nmpa_zcyl_search").Find(&q).Sort("_id").Select(map[string]interface{}{
		"records":1,
	}).Iter()
	strReg := regexp.MustCompile(`(^[0-9][0-9]|[ \n]+)`)
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		if total%10000==0 {
			log.Debug("cur index ", total,"~",isok)
		}
		records := []map[string]interface{}{}
		if res, ok := tmp["records"].(primitive.A); ok {
			records = qu.ObjArrToMapArr(res)
		}else {
			if res, ok := tmp["records"].([]interface{}); ok {
				records = qu.ObjArrToMapArr(res)
			}
		}
		//采用对方数据
		for _,v := range records {
			largeClassName := qu.ObjToString(v["largeClassName"])
			oneProdCategory := qu.ObjToString(v["oneProdCategory"])
			twoProdCategory := qu.ObjToString(v["twoProdCategory"])
			oneProdCategory = strReg.ReplaceAllString(oneProdCategory,"")
			twoProdCategory = strReg.ReplaceAllString(twoProdCategory,"")
			update:=map[string]interface{}{
				"product_class":largeClassName,
				"product_class_1":oneProdCategory,
				"product_class_2":twoProdCategory,
				"isYiXieUpdate":true,
			}
			registNum := qu.ObjToString(v["registNum"])
			if registNum!="" && largeClassName !="" {
				data := save_mgo.FindOne("nmpa_product", map[string]interface{}{
					"reg_no" : registNum,
				})
				if data!=nil && len(data)>2 {
					isok++
					save_mgo.UpdateById("nmpa_product",BsonTOStringId(data["_id"]), map[string]interface{}{
						"$set": update,
					})
				}
			}
		}
		tmp = make(map[string]interface{})
	}
	log.Debug("is over ",total,"~",isok)
}
//处理分类-AB  C待定
func dealWithClassData(product_name string,classArr []map[string]interface{}) map[string]interface{}{
	/*
		a产品名称和品名举例（或二分类名称）绝对值相等；如果只有一个品名举例对应上，直接打上分类，如有多个，冗余字段记录
		b产品名称和品名分类，存在包含关系；如果只有一个分类对应上，直接打上分类，如有多个，冗余字段记录
		c产品名称和品名分类（或品名举例）进行切词，相似度较高的数据统计分析；

		统计1.a能打上分类产品的数量
		统计1.b能打上分类产品的数量,以及存在包含关系的数量
	*/

	//临时切词比对
	//okMap :=map[string]map[string]interface{}{}
	//updateC := map[string]interface{}{}
	//new_p_name:=gseReg.ReplaceAllString(product_name,"")
	//nameArr := GSE.Cut(new_p_name, true)
	//for _,v := range classArr{
	//	example := qu.ObjToString(v["product_example"])
	//	product_class := qu.ObjToString(v["product_class"])
	//	product_class_1 := qu.ObjToString(v["product_class_1"])
	//	product_class_2 := qu.ObjToString(v["product_class_2"])
	//	dict := map[string]interface{}{
	//		"product_class":product_class,
	//		"product_class_1":product_class_1,
	//		"product_class_2":product_class_2,
	//	}
	//
	//	new_p_c_name:=  gseReg.ReplaceAllString(product_class_2,"")
	//	class_2_Arr := GSE.Cut(new_p_c_name, true)
	//	b := cutWordThanData(nameArr,class_2_Arr)
	//	if b {
	//		okey := product_class+"~"+product_class_1+"~"+product_class_2
	//		if okMap[okey]==nil {
	//			okMap[okey] = dict
	//		}
	//		continue
	//	}
	//
	//
	//	//-品名举例
	//	exampleArr := strings.Split(example,"、")
	//	for _,v := range exampleArr { //对比品名举例
	//		new_v:=  gseReg.ReplaceAllString(v,"")
	//		v_arr := GSE.Cut(new_v, true)
	//		ok := cutWordThanData(nameArr,v_arr)
	//		if ok {
	//			okey := product_class+"~"+product_class_1+"~"+product_class_2
	//			if okMap[okey]==nil {
	//				okMap[okey] = dict
	//			}
	//			break
	//		}
	//	}
	//}
	//
	//if len(okMap)>0 {
	//	arr := []map[string]interface{}{}
	//	for _,v := range okMap{
	//		arr = append(arr,v)
	//	}
	//	updateC = map[string]interface{}{
	//		"isSegmentClass":arr,
	//		"isSegmentUpdate":true,
	//	}
	//}
	//return updateC


	isA := false
	updateA := map[string]interface{}{}
	okMap :=map[string]map[string]interface{}{}
	for _,v :=range classArr { //先对比class_2 在对比 品名举例
		example := qu.ObjToString(v["product_example"])
		product_class := qu.ObjToString(v["product_class"])
		product_class_1 := qu.ObjToString(v["product_class_1"])
		product_class_2 := qu.ObjToString(v["product_class_2"])
		dict := map[string]interface{}{
			"product_class":product_class,
			"product_class_1":product_class_1,
			"product_class_2":product_class_2,
		}
		if product_class_2==product_name{
			okey := product_class+"~"+product_class_1+"~"+product_class_2
			if okMap[okey]==nil {
				okMap[okey] = dict
			}
			continue
		}

		exampleArr := strings.Split(example,"、")
		for _,name := range exampleArr { //对比品名举例
			if name==product_name {
				okey := product_class+"~"+product_class_1+"~"+product_class_2
				if okMap[okey]==nil {
					okMap[okey] = dict
				}
				break
			}
		}
	}

	if len(okMap)==1 { //匹配
		isA = true
		for _,v := range okMap{
			updateA = map[string]interface{}{
				"product_class":v["product_class"],
				"product_class_1":v["product_class_1"],
				"product_class_2":v["product_class_2"],
				"isMustUpdate":true,
			}
		}
	}else if len(okMap)>1 { //冗余
		isA = true
		arr := []map[string]interface{}{}
		for _,v := range okMap{
			arr = append(arr,v)
		}
		updateA = map[string]interface{}{
			"isMustClass":arr,
			"isMustUpdate":true,
		}
	}else {

	}
	if isA {
		return updateA
	}

	isB := false
	updateB := map[string]interface{}{}
	okMap =map[string]map[string]interface{}{}
	for _,v :=range classArr {
		product_class := qu.ObjToString(v["product_class"])
		product_class_1 := qu.ObjToString(v["product_class_1"])
		product_class_2 := qu.ObjToString(v["product_class_2"])
		dict := map[string]interface{}{
			"product_class":product_class,
			"product_class_1":product_class_1,
			"product_class_2":product_class_2,
		}
		if strings.Contains(product_class_2,product_name)||
			strings.Contains(product_name,product_class_2) {
			okey := product_class+"~"+product_class_1+"~"+product_class_2
			if okMap[okey]==nil {
				okMap[okey] = dict
			}
		}
	}

	if len(okMap)==1 { //匹配
		isB = true
		for _,v := range okMap{
			updateB = map[string]interface{}{
				"product_class":v["product_class"],
				"product_class_1":v["product_class_1"],
				"product_class_2":v["product_class_2"],
				"isContainsUpdate":true,
			}
		}
	}else if len(okMap)>1 { //冗余
		isB = true
		arr := []map[string]interface{}{}
		for _,v := range okMap{
			arr = append(arr,v)
		}
		updateB = map[string]interface{}{
			"isContainsClass":arr,
			"isContainsUpdate":true,
		}
	}else {

	}


	if isB {
		return updateB
	}
	return map[string]interface{}{}
}
//修复数据reg_no截取
func repairEqRegNoClassData(){
	sess := save_mgo.GetMgoConn()
	defer save_mgo.DestoryMongoConn(sess)
	q,total:=map[string]interface{}{},0
	it := sess.DB(save_mgo.DbName).C("nmpa_product").Find(&q).Sort("_id").Select(map[string]interface{}{
		"reg_no":1,
		"product_class":1,
	}).Iter()
	isok:=0
	dict:=map[string]string{
		"01":"有源手术器械",
		"02":"无源手术器械",
		"03":"神经和心血管手术器械",
		"04":"骨科手术器械",
		"05":"放射治疗器械",
		"06":"医用成像器械",
		"07":"医用诊察和监护器械",
		"08":"呼吸、麻醉和急救器械",
		"09":"物理治疗器械",
		"10":"输血、透析和体外循环器械",
		"11":"医疗器械消毒灭菌器械",
		"12":"有源植入器械",
		"13":"无源植入器械",
		"14":"注输、护理和防护器械",
		"15":"患者承载器械",
		"16":"眼科器械",
		"17":"口腔科器械",
		"18":"妇产科、辅助生殖和避孕器械",
		"19":"医用康复器械",
		"20":"中医器械",
		"21":"医用软件",
		"22":"临床检验器械",
		"27": "中医器械",
		"28": "医用成像器械",
		"32": "放射治疗器械",
		"34": "医用成像器械",
		"40":"体外诊断试剂",
		"41": "临床检验器械",
		"45": "输血、透析和体外循环器械",
		"55": "口腔科器械",
		"57": "医疗器械消毒灭菌器械",
		"63": "口腔科器械",
		"64": "注输、护理和防护器械",
		"70": "医用软件",
	}

	dict_num := map[string]int{}
	//""沪食药监械(准)字2013第2401942号(变更文件)""
	reg_reg_1 := regexp.MustCompile("[\u4e00-\u9fa5]{2}20\\d{9}")
	reg_reg_2 := regexp.MustCompile("\\d{7}号")
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		if total % 10000 == 0 {
			log.Debug("cur index ",total,"~",isok)
		}
		tmpid:=BsonTOStringId(tmp["_id"])
		product_class := qu.ObjToString(tmp["product_class"])
		reg_no := qu.ObjToString(tmp["reg_no"])
		str := reg_reg_1.FindString(reg_no)
		if str=="" {
			str = reg_reg_2.FindString(reg_no)
		}
		if product_class=="" && str!=""{
			new_no := str[11:13]
			//new_no := str[1:3]
			if dict[new_no]!=""{
				isok++
				save_mgo.UpdateById("nmpa_product",tmpid, map[string]interface{}{
					"$set": map[string]interface{}{
						"product_class":dict[new_no],
					},
				})
			}

			num := qu.IntAll(dict_num[new_no])
			dict_num[new_no] = num+1

		}
		tmp = make(map[string]interface{})
	}
	log.Debug("is over ",total,"~",isok)
	log.Debug(dict_num)
}
//补充同分类数据
func repairEqClassData(){

	sess := save_mgo.GetMgoConn()
	defer save_mgo.DestoryMongoConn(sess)
	q,total:=map[string]interface{}{},0
	it := sess.DB(save_mgo.DbName).C("nmpa_product").Find(&q).Sort("_id").Select(map[string]interface{}{
		"product_class":1,
		"product_class_1":1,
		"product_class_2":1,
		"class":1,
		"product_name":1,
	}).Iter()
	P_Name_Dict := map[string][]map[string]interface{}{}
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		if total % 10000 == 0 {
			log.Debug("cur index ",total)
		}
		product_name := qu.ObjToString(tmp["product_name"])
		arr := []map[string]interface{}{}
		if P_Name_Dict[product_name]!=nil {
			arr = P_Name_Dict[product_name]
		}
		arr = append(arr,tmp)
		P_Name_Dict[product_name] = arr
		tmp = make(map[string]interface{})
	}
	log.Debug("分组完毕~",len(P_Name_Dict),"~开始处理分组数据")
	istotal,isok:=0,0
	for pn,arr:=range P_Name_Dict {
		istotal++
		if istotal%5000==0 {
			log.Debug("第",istotal,"组~",isok,"~",pn)
		}
		if len(arr)==1 {
			continue
		}
		usedArr,unUsedArr:=breakUpUsedata(arr)
		for _,v:=range unUsedArr{
			update:= breakUpdateData(usedArr,v)
			if len(update)>0 {
				isok++
				save_mgo.UpdateById("nmpa_product",BsonTOStringId(v["_id"]), map[string]interface{}{
					"$set": update,
				})
			}
		}
	}
	log.Debug("is over ",isok)
}
func breakUpUsedata(tmpArr []map[string]interface{}) ([]map[string]interface{},[]map[string]interface{}) {
	UsedArr,UnUsedArr:=[]map[string]interface{}{},[]map[string]interface{}{}
	for _,v:=range tmpArr {
		product_class:=qu.ObjToString(v["product_class"])
		product_class_1:=qu.ObjToString(v["product_class_1"])
		product_class_2:=qu.ObjToString(v["product_class_2"])
		isok:=0
		if product_class!="" {
			isok++
		}
		if product_class_1!="" {
			isok++
		}
		if product_class_2!="" {
			isok++
		}
		if isok>2 {
			UsedArr = append(UsedArr,v)
		}else {
			UnUsedArr = append(UnUsedArr,v)
		}
	}
	return UsedArr,UnUsedArr
}
func dealWithYiXieClassData(classArr []map[string]interface{},largeClassName string) map[string]interface{}{
	update := map[string]interface{}{}
	okMap := map[string]map[string]interface{}{}
	for _,v :=range classArr { //先对比class_2 在对比 品名举例
		product_class := qu.ObjToString(v["product_class"])
		product_class_1 := qu.ObjToString(v["product_class_1"])
		product_class_2 := qu.ObjToString(v["product_class_2"])
		dict := map[string]interface{}{
			"product_class":product_class,
			"product_class_1":product_class_1,
			"product_class_2":product_class_2,
		}
		if product_class_2==largeClassName{
			okey := product_class+"~"+product_class_1+"~"+product_class_2
			if okMap[okey]==nil {
				okMap[okey] = dict
			}
			continue
		}
	}
	if len(okMap)==1 {
		for _,v := range okMap{
			update = map[string]interface{}{
				"product_class":v["product_class"],
				"product_class_1":v["product_class_1"],
				"product_class_2":v["product_class_2"],
				"isYiXieUpdate":true,
			}
		}
	}else if len(okMap)>1 { //冗余
		arr := []map[string]interface{}{}
		for _,v := range okMap{
			arr = append(arr,v)
		}
		update = map[string]interface{}{
			"isYiXieClass":arr,
			"isYiXieUpdate":true,
		}
	}else {

	}
	return update
}
func exportWordRepairSpec() {
	log.Debug("匹配分词-比对......")
	GSE.LoadDict("./dictionary.txt")

	sess := save_mgo.GetMgoConn()
	defer save_mgo.DestoryMongoConn(sess)
	q,total:=map[string]interface{}{},0
	it := sess.DB(save_mgo.DbName).C("zzzzzkkkkk").Find(&q).Sort("_id").Iter()
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		tmpid := BsonTOStringId(tmp["_id"])
		if tmpid=="" {

		}
		product_name := qu.ObjToString(tmp["product_name"])
		new_p_name:=gseReg.ReplaceAllString(product_name,"")
		//new_p_name =  strings.ReplaceAll(new_p_name,"一次性","")
		//new_p_name =  strings.ReplaceAll(new_p_name,"使用","")
		nameArr := GSE.Cut(new_p_name, true)

		class_str := qu.ObjToString(tmp["class_str"])
		classArr := strings.Split(class_str,",")
		if len(classArr)>1 { //多分类
			ok_class_arr := []string{}
			for _,cs := range classArr{
				new_class_name :=  gseReg.ReplaceAllString(cs,"")
				new_class_Arr := GSE.Cut(new_class_name, true)
				b := cutWordThanData(nameArr,new_class_Arr)
				if b {
					ok_class_arr = append(ok_class_arr,cs)
				}
			}

			if len(ok_class_arr)>1 {
				ok_class_str := strings.Join(ok_class_arr,",")
				save_mgo.UpdateById("zzzzzkkkkk",tmpid, map[string]interface{}{
					"$set": map[string]interface{}{
						"ok_class_more":ok_class_str,
					},
				})
			}else {
				ok_class_str := strings.Join(ok_class_arr,",")
				save_mgo.UpdateById("zzzzzkkkkk",tmpid, map[string]interface{}{
					"$set": map[string]interface{}{
						"ok_class_one":ok_class_str,
					},
				})
			}
		}else {
			ok_class_str := qu.ObjToString(tmp["class_str"])
			save_mgo.UpdateById("zzzzzkkkkk",tmpid, map[string]interface{}{
				"$set": map[string]interface{}{
					"ok_class_one":ok_class_str,
				},
			})
		}

		tmp = make(map[string]interface{})
	}
	log.Debug("加载完毕~",total)
}
//对比是否有效
func breakUpdateData(usedArr []map[string]interface{},tmp map[string]interface{}) map[string]interface{} {
	update := map[string]interface{}{}
	class := qu.ObjToString(tmp["class"])
	for _,v:=range usedArr {
		used_class := qu.ObjToString(v["class"])
		if used_class==class && class!="" {
			update = map[string]interface{}{
				"product_class":qu.ObjToString(v["product_class"]),
				"product_class_1":qu.ObjToString(v["product_class_1"]),
				"product_class_2":qu.ObjToString(v["product_class_2"]),
			}
			break
		}
	}
	return update
}
//对比-未分类-切词比对
func exportThanWordClassData()  {
	log.Debug("匹配分词-比对......")
	GSE.LoadDict("./dictionary.txt")

	sess := save_mgo.GetMgoConn()
	defer save_mgo.DestoryMongoConn(sess)
	q,total:=map[string]interface{}{},0
	classArr := []map[string]interface{}{}
	it := sess.DB(save_mgo.DbName).C("nmpa_class_example").Find(&q).Sort("_id").Select(map[string]interface{}{
		"product_class":1,
		"product_class_1":1,
		"product_class_2":1,
		"product_example":1,
	}).Iter()
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		delete(tmp,"_id")
		classArr = append(classArr,tmp)
		tmp = make(map[string]interface{})
	}
	log.Debug("加载完毕~",len(classArr))

	isok,isup :=0,0
	it = sess.DB(save_mgo.DbName).C("nmpa_product").Find(&q).Sort("_id").Select(map[string]interface{}{
		"product_name":1,
		"isContainsUpdate":1,
		"isMustUpdate":1,
		"isYiXieUpdate":1,
	}).Iter()
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		if total%1000==0 {
			log.Debug("cur index ", total,"~",isok,"~",isup)
		}
		tmpid := BsonTOStringId(tmp["_id"])
		isMust ,isContains,isYiXie:= false,false,false
		if is,ok := tmp["isMustUpdate"].(bool);ok {
			isMust = is
		}
		if is,ok := tmp["isContainsUpdate"].(bool);ok {
			isContains = is
		}
		if is,ok := tmp["isYiXieUpdate"].(bool);ok {
			isYiXie = is
		}
		if !isContains && !isMust && !isYiXie {
			isok++
			product_name := qu.ObjToString(tmp["product_name"])
			update := dealWithClassData(product_name,classArr)
			if len(update)>0 {
				isup++
				save_mgo.UpdateById("nmpa_product",tmpid, map[string]interface{}{
					"$set": update,
				})
			}
		}
		tmp = make(map[string]interface{})
	}

	log.Debug("is over ", total,"~",isok,"~",isup)
}
//比对打标签
func exportOtherClassData() {

	sess := save_mgo.GetMgoConn()
	defer save_mgo.DestoryMongoConn(sess)
	q,total:=map[string]interface{}{},0
	classArr := []map[string]interface{}{}
	it := sess.DB(save_mgo.DbName).C("nmpa_class_example").Find(&q).Sort("_id").Iter()
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		delete(tmp,"_id")
		delete(tmp,"product_level")
		delete(tmp,"product_describe")
		delete(tmp,"product_effect")
		classArr = append(classArr,tmp)
		tmp = make(map[string]interface{})
	}
	log.Debug("加载完毕~",len(classArr))
	log.Debug("开始数据处理...")



	it = sess.DB(save_mgo.DbName).C("nmpa_product").Find(&q).Sort("_id").Select(map[string]interface{}{
		"product_name":1,
	}).Iter()
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		if total%1000==0 {
			log.Debug("cur index ", total)
		}
		product_name := qu.ObjToString(tmp["product_name"])
		tmpid := BsonTOStringId(tmp["_id"])
		update := dealWithClassData(product_name,classArr)
		save_mgo.UpdateById("nmpa_product",tmpid, map[string]interface{}{
			"$set": update,
		})
		tmp = make(map[string]interface{})
	}



	/*
		统计A:
		1、有效分类：109582
		2、疑似分类（包含有效）：112575

		统计B
		1、有效分类：43286
		2、疑似分类（包含有效）：49331

		总计：A+B
		1、有效分类：152868
		2、疑似分类（包含有效）：161906
	*/


	log.Debug("is over ... ...")
}
//切词比对
func cutWordThanData(nameArr []string,classArr []string) bool {
	isok:=0
	for _,v := range nameArr {
		for _,v1:=range classArr {
			if v==v1 {
				isok++
			}
		}
	}


	if isok>0 {
		return true
	}
	//if isok>0 && isok > len(nameArr)/2 && isok > len(classArr)/2{
	//	return true
	//}
	return false
}
//根据产品-公司导出68xx 16-01 相关数据-待定...
func exportNewClassCompanyData()  {
	sess := save_mgo.GetMgoConn()
	defer save_mgo.DestoryMongoConn(sess)
	q,total:=map[string]interface{}{},0
	it := sess.DB(save_mgo.DbName).C("nmpa_product").Find(&q).Sort("_id").Select(map[string]interface{}{
		"reg_company":1,
		"product_class":1,
		"product_class_1":1,
		"product_class_2":1,
		"product_name":1,
	}).Iter()
	isok:=0
	dict:=map[string]string{
		"01":"有源手术器械",
		"02":"无源手术器械",
		"03":"神经和心血管手术器械",
		"04":"骨科手术器械",
		"05":"放射治疗器械",
		"06":"医用成像器械",
		"07":"医用诊察和监护器械",
		"08":"呼吸、麻醉和急救器械",
		"09":"物理治疗器械",
		"10":"输血、透析和体外循环器械",
		"11":"医疗器械消毒灭菌器械",
		"12":"有源植入器械",
		"13":"无源植入器械",
		"14":"注输、护理和防护器械",
		"15":"患者承载器械",
		"16":"眼科器械",
		"17":"口腔科器械",
		"18":"妇产科、辅助生殖和避孕器械",
		"19":"医用康复器械",
		"20":"中医器械",
		"21":"医用软件",
		"22":"临床检验器械",
		"27": "中医器械",
		"28": "医用成像器械",
		"32": "放射治疗器械",
		"34": "医用成像器械",
		"40":"体外诊断试剂",
		"41": "临床检验器械",
		"45": "输血、透析和体外循环器械",
		"55": "口腔科器械",
		"57": "医疗器械消毒灭菌器械",
		"63": "口腔科器械",
		"64": "注输、护理和防护器械",
		"70": "医用软件",
	}
	reg_reg := regexp.MustCompile("[，,:：][0-1][0-9]-[0-9]+")
	clear_reg := regexp.MustCompile("[，,:：]")
	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
		if total % 10000 == 0 {
			log.Debug("cur index ",total,"~",isok)
		}
		product_name := qu.ObjToString(tmp["product_name"])
		product_class := qu.ObjToString(tmp["product_class"])
		product_class_1 := qu.ObjToString(tmp["product_class"])
		product_class_2 := qu.ObjToString(tmp["product_class"])
		reg_company := qu.ObjToString(tmp["reg_company"])
		if product_class=="" ||product_class_1==""||product_class_2==""  {
			dataArr,_ := save_mgo.Find("nmpa_company", map[string]interface{}{
				"company" : reg_company,
				"class":"生产型",
			},nil,map[string]interface{}{
				"business_range":1,
				"product_range":1,
			})

			oldArr := []string{}
			oldMap := map[string]string{}
			for _,v := range dataArr {
				range_str := ""
				business_range := qu.ObjToString(v["business_range"])
				product_range :=  qu.ObjToString(v["product_range"])
				if business_range!="" {
					range_str = business_range
				}else {
					range_str = product_range
				}
				arr := reg_reg.FindAllString(range_str,-1)
				for _,v1:=range arr{
					new_v1 := clear_reg.ReplaceAllString(v1,"")
					new_v1 = new_v1[:2]
					vvvv := dict[new_v1]
					//去重拼接
					if oldMap[vvvv]=="" && vvvv!=""{
						//映射值
						oldArr = append(oldArr,vvvv)
						oldMap[vvvv] = vvvv
					}
				}
			}

			if len(oldArr)>0 {
				isok++
				class_str := strings.Join(oldArr,",")
				save_mgo.Save("zzzzzkkkkk", map[string]interface{}{
					"_id":tmp["_id"],
					"class_str":class_str,
					"product_name":product_name,
				})
			}
		}
		tmp = make(map[string]interface{})
	}

	log.Debug("is over ",total,"~",isok)
}









