Jelajahi Sumber

备份 医疗企业相关

zhengkun 2 tahun lalu
induk
melakukan
596dbfd39d

+ 1 - 1
data_medical/src/main.go

@@ -36,7 +36,7 @@ func main() {
 	dealWithCompanyInfo()
 
 	//医疗产品表~信息
-	//dealWithProductInfo()
+	dealWithProductInfo()
 
 	//分类代码v表修复~产品表修复
 	//repairYlqxClass()

+ 46 - 36
data_ylqx/src/remarks.go → data_ylqx/src/class/class.go

@@ -1,4 +1,4 @@
-package main
+package class
 
 import (
 	log "github.com/donnie4w/go-logger/logger"
@@ -7,10 +7,20 @@ import (
 	"regexp"
 	"strings"
 	"time"
+	ul "util"
 )
 
+func StartDealWithProductClassInfo() {
+	//拆分合并产品与企业表
+	//splitMergeMedicalInfo("nmpa_ylqx_2022")
+	//splitMergeMedicalInfo("nmpa_ylqx_2023")
+
+	//确认医疗分类,分类代码
+	//confirmYlqxInfoClass()
+
+}
+
 func confirmYlqxInfoClass() {
-	loadYlqxInfo()
 	confirmFirst()
 	confirmSecond()
 	confirmThird()
@@ -25,7 +35,7 @@ func confirmYlqxInfoClass() {
 //医疗分类打标记
 func confirmFirst() {
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"product_name": 1,
 	})
 	for _, v := range dataArr {
@@ -33,13 +43,13 @@ func confirmFirst() {
 		if product_class_1 != "" {
 			continue
 		}
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		product_name := qu.ObjToString(v["product_name"])
-		if code := YlqxNameCode[product_name]; code != "" {
+		if code := ul.YlqxNameCode[product_name]; code != "" {
 			isok++
 			_, update := calculationYlqxCode(code)
 			update["isFlag"] = flagTagLog("", "1")
-			Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+			ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 				"$set": update,
 			})
 		}
@@ -50,14 +60,14 @@ func confirmFirst() {
 func confirmSecond() {
 	codeReg := regexp.MustCompile("20\\d{3}(\\d{2})")
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"reg_no":             1,
 		"classify":           1,
 		"product_class_code": 1,
 		"isFlag":             1,
 	})
 	for _, v := range dataArr {
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		product_class_code := qu.ObjToString(v["product_class_code"])
 		if product_class_code != "" {
 			continue
@@ -68,13 +78,13 @@ func confirmSecond() {
 			code_str := codeReg.FindString(reg_no)
 			if code_str != "" {
 				code := codeReg.ReplaceAllString(code_str, "${1}")
-				name := codeRelation[code]
+				name := ul.CodeRelation[code]
 				if name != "" && code != "" {
 					isok++
-					Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+					ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 						"$set": bson.M{
 							"product_class_1":    name,
-							"product_class_code": YlqxNameCode[name],
+							"product_class_code": ul.YlqxNameCode[name],
 							"isFlag":             flagTagLog(qu.ObjToString(v["isFlag"]), "2"),
 						},
 					})
@@ -87,17 +97,17 @@ func confirmSecond() {
 }
 func confirmThird() {
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"product_name":    1,
 		"product_class_1": 1,
 		"isFlag":          1,
 	})
 	for _, v := range dataArr {
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		product_name := qu.ObjToString(v["product_name"])
 		product_class_1 := qu.ObjToString(v["product_class_1"])
 		if product_class_1 == "" && strings.Contains(product_name, "试剂") {
-			Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+			ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 				"$set": bson.M{
 					"product_class_1":    "体外诊断试剂",
 					"product_class_code": "23",
@@ -111,7 +121,7 @@ func confirmThird() {
 }
 func confirmFourth() {
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"reg_company":        1,
 		"product_name":       1,
 		"product_class_1":    1,
@@ -120,7 +130,7 @@ func confirmFourth() {
 		"isFlag":             1,
 	})
 	for _, v := range dataArr {
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		old_name := qu.ObjToString(v["product_name"])
 		old_class_code := qu.ObjToString(v["product_class_code"])
 		reg_company := qu.ObjToString(v["reg_company"])
@@ -136,7 +146,7 @@ func confirmFourth() {
 				isok++
 				res["product_class_code"] = code
 				res["isFlag"] = flagTagLog(qu.ObjToString(v["isFlag"]), "4")
-				Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+				ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 					"$set": res,
 				})
 			}
@@ -148,7 +158,7 @@ func confirmFourth() {
 func confirmFifth() {
 	temp := loadFifthInfo()
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"product_name":       1,
 		"product_class_1":    1,
 		"product_class_2":    1,
@@ -156,7 +166,7 @@ func confirmFifth() {
 		"isFlag":             1,
 	})
 	for _, v := range dataArr {
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		old_name := qu.ObjToString(v["product_name"])
 		old_class_code := qu.ObjToString(v["product_class_code"])
 		old_class_1 := qu.ObjToString(v["product_class_1"])
@@ -165,12 +175,12 @@ func confirmFifth() {
 			continue
 		}
 		if name := temp[old_name]; name != "" {
-			if code := YlqxNameCode[name]; code != "" {
+			if code := ul.YlqxNameCode[name]; code != "" {
 				b, res := calculationYlqxCode(code)
 				if b && (old_class_1 == "" || (qu.ObjToString(res["product_class_1"]) == old_class_1 && len(code) > len(old_class_code))) {
 					isok++
 					res["isFlag"] = flagTagLog(qu.ObjToString(v["isFlag"]), "5")
-					Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+					ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 						"$set": res,
 					})
 				}
@@ -183,7 +193,7 @@ func confirmFifth() {
 }
 func confirmSixth() {
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"product_name":       1,
 		"product_class_1":    1,
 		"product_class_2":    1,
@@ -191,7 +201,7 @@ func confirmSixth() {
 		"isFlag":             1,
 	})
 	for _, v := range dataArr {
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		old_name := qu.ObjToString(v["product_name"])
 		old_class_code := qu.ObjToString(v["product_class_code"])
 		old_class_1 := qu.ObjToString(v["product_class_1"])
@@ -200,12 +210,12 @@ func confirmSixth() {
 			continue
 		}
 		new_name := cleanProductName(old_name)
-		if code := YlqxNameCode[new_name]; code != "" {
+		if code := ul.YlqxNameCode[new_name]; code != "" {
 			b, res := calculationYlqxCode(code)
 			if b && (old_class_1 == "" || (qu.ObjToString(res["product_class_1"]) == old_class_1 && len(code) > len(old_class_code))) {
 				isok++
 				res["isFlag"] = flagTagLog(qu.ObjToString(v["isFlag"]), "6")
-				Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+				ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 					"$set": res,
 				})
 			}
@@ -216,14 +226,14 @@ func confirmSixth() {
 }
 func confirmSeventh() {
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"product_name":    1,
 		"product_class_1": 1,
 		"product_class_2": 1,
 		"isFlag":          1,
 	})
 	for _, v := range dataArr {
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		old_name := qu.ObjToString(v["product_name"])
 		old_class_code := qu.ObjToString(v["product_class_code"])
 		old_class_1 := qu.ObjToString(v["product_class_1"])
@@ -237,12 +247,12 @@ func confirmSeventh() {
 		matchArr := []string{}
 		logArr := []map[string]interface{}{}
 		if new_name != "" {
-			for k1, v1 := range YlqxNameCode {
+			for k1, v1 := range ul.YlqxNameCode {
 				if (new_name == "医用退热凝胶" && k1 == "凝胶") || k1 == "蜡" {
 					continue
 				}
 				if strings.Contains(new_name, k1) || strings.Contains(k1, new_name) {
-					b, res := calculationYlqxCode(YlqxNameCode[k1])
+					b, res := calculationYlqxCode(ul.YlqxNameCode[k1])
 					if b && checkYlqxInfoRight(res, old_class_1, old_name) {
 						logArr = append(logArr, map[string]interface{}{
 							"name":  k1,
@@ -250,7 +260,7 @@ func confirmSeventh() {
 							"class": res,
 						})
 						resArr = append(resArr, res)
-						codeArr = append(codeArr, YlqxNameCode[k1])
+						codeArr = append(codeArr, ul.YlqxNameCode[k1])
 						matchArr = append(matchArr, k1)
 					}
 				}
@@ -264,7 +274,7 @@ func confirmSeventh() {
 			if b && res != nil && tmpid != "" && len(code) > len(old_class_code) {
 				isok++
 				res["isFlag"] = flagTagLog(qu.ObjToString(v["isFlag"]), "7")
-				Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+				ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 					"$set": res,
 				})
 			}
@@ -276,7 +286,7 @@ func confirmSeventh() {
 func confirmEighth() {
 	loadLastClassInfo()
 	isok := 0
-	dataArr, _ := Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_product_new", nil, nil, bson.M{
 		"product_name":       1,
 		"product_class_1":    1,
 		"product_class_2":    1,
@@ -284,18 +294,18 @@ func confirmEighth() {
 		"isFlag":             1,
 	})
 	for _, v := range dataArr {
-		tmpid := BsonTOStringId(v["_id"])
+		tmpid := ul.BsonTOStringId(v["_id"])
 		product_name := qu.ObjToString(v["product_name"])
 		product_class_code := qu.ObjToString(v["product_class_code"])
 		product_class_1 := qu.ObjToString(v["product_class_1"])
 		product_class_2 := qu.ObjToString(v["product_class_2"])
-		res := LastProductInfo[product_name]
-		if product_class_2 == "" && LastProductInfo[product_name] != nil {
+		res := ul.LastProductInfo[product_name]
+		if product_class_2 == "" && ul.LastProductInfo[product_name] != nil {
 			res_class_1 := res["product_class_1"]
 			res_class_code := res["product_class_code"]
 			if (product_class_1 == res_class_1 || product_class_1 == "") && len(res_class_code) > len(product_class_code) {
 				isok++
-				Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
+				ul.Save_Mgo.UpdateById("nmpa_product_new", tmpid, map[string]interface{}{
 					"$set": map[string]interface{}{
 						"isFlag":             flagTagLog(qu.ObjToString(v["isFlag"]), "8"),
 						"product_class_1":    qu.ObjToString(res["product_class_1"]),

+ 44 - 144
data_ylqx/src/remarks_method.go → data_ylqx/src/class/class_method.go

@@ -1,112 +1,25 @@
-package main
+package class
 
 import (
 	log "github.com/donnie4w/go-logger/logger"
 	"go.mongodb.org/mongo-driver/bson"
 	qu "qfw/util"
-	"regexp"
 	"strings"
 	"unicode/utf8"
+	ul "util"
 )
 
-var (
-	codeRelation = map[string]string{
-		"06": "医用成像器械",
-		"01": "有源手术器械",
-		"02": "无源手术器械",
-		"14": "注输、护理和防护器械",
-		"16": "眼科器械",
-		"03": "神经和心血管手术器械",
-		"12": "有源植入器械",
-		"40": "体外诊断试剂",
-		"13": "无源植入器械",
-		"18": "妇产科、辅助生殖和避孕器械",
-		"17": "口腔科器械",
-		"22": "临床检验器械",
-		"07": "医用诊察和监护器械",
-		"04": "骨科手术器械",
-		"20": "中医器械",
-		"09": "物理治疗器械",
-		"08": "呼吸、麻醉和急救器械",
-		"19": "医用康复器械",
-		"21": "医用软件",
-		"10": "输血、透析和体外循环器械",
-		"11": "医疗器械消毒灭菌器械",
-		"15": "患者承载器械",
-		"05": "放射治疗器械",
-		"57": "医疗器械消毒灭菌器械",
-		"68": "体外诊断试剂",
-		"27": "中医器械",
-		"26": "物理治疗器械",
-		"46": "骨科手术器械",
-	}
-	rangeRelation = map[string]string{
-		"6801": "无源手术器械",
-		"6831": "X射线附属及辅助设备",
-		"6812": "妇产科、辅助生殖和避孕器械",
-		"6813": "妇产科手术器械",
-		"6810": "骨科手术器械",
-		"6824": "光治疗设备",
-		"6854": "呼吸、麻醉和急救器械",
-		"6856": "呼吸、麻醉和急救器械",
-		"6806": "口腔科器械",
-		"6855": "口腔科器械",
-		"6863": "口腔科器械",
-		"6840": "临床检验器械",
-		"6841": "临床检验器械",
-		"6803": "神经和心血管手术器械",
-		"6807": "神经和心血管手术器械",
-		"6877": "神经和心血管手术器械-心血管介入器械",
-		"6845": "输血、透析和体外循环器械",
-		"6805": "无源手术器械",
-		"6809": "无源手术器械",
-		"6808": "无源手术器械",
-		"6816": "无源手术器械",
-		"6846": "无源植入器械",
-		"6826": "物理治疗器械",
-		"6804": "眼科器械",
-		"6857": "医疗器械消毒灭菌器械",
-		"6822": "医用成像器械",
-		"6828": "医用成像器械",
-		"6833": "医用成像器械",
-		"6870": "医用软件",
-		"6834": "医用射线防护设备",
-		"6820": "医用诊察和监护器械",
-		"6821": "医用诊察和监护器械",
-		"6827": "中医器械",
-		"6815": "注射、穿刺器械",
-		"6864": "注输、护理和防护器械",
-	}
-	productTemp  = map[string]string{}
-	companyTemp  = map[string]string{}
-	YlqxCodeName = map[string]string{}
-	YlqxNameCode = map[string]string{}
-
-	LastProductInfo = map[string]map[string]string{}
-	ScRangeReg1     = regexp.MustCompile("(\\d{2}|\\d{4})-(\\d{2}|\\d{1})([\\s -::]+)?([\u4e00-\u9fa5()、()/\\s ]+)")
-	ScRangeReg2     = regexp.MustCompile("\\d{2}([\\s -::]+)?([\u4e00-\u9fa5()、()/\\s ]+)")
-	ScRangeClean1   = regexp.MustCompile("[\\s ]+")
-	ScRangeClean2   = regexp.MustCompile("(生产范围).*")
-	SpecRangeReg    = regexp.MustCompile("(检测试剂|试剂盒|抗体试剂|保存试剂|提取试剂)")
-)
-
-var cleanPN0 = regexp.MustCompile("[ \\s]+")
-var cleanPN1 = regexp.MustCompile("[\u30A0-\u30FF]+")
-var cleanPN2 = regexp.MustCompile("([A-Za-z]+)$")
-var cleanPN3 = regexp.MustCompile("[()()]+")
-var cleanPN4 = regexp.MustCompile("^([0-9]+)")
-
 //清洗产品名称
 func cleanProductName(product_name string) string {
-	product_name = cleanPN0.ReplaceAllString(product_name, "")
-	product_name = cleanPN1.ReplaceAllString(product_name, "")
-	product_name = cleanPN2.ReplaceAllString(product_name, "")
+	product_name = ul.CleanPN0.ReplaceAllString(product_name, "")
+	product_name = ul.CleanPN1.ReplaceAllString(product_name, "")
+	product_name = ul.CleanPN2.ReplaceAllString(product_name, "")
 	product_name = cleanParenthesesName(product_name)
-	product_name = cleanPN4.ReplaceAllString(product_name, "")
+	product_name = ul.CleanPN4.ReplaceAllString(product_name, "")
 	return product_name
 }
 func cleanParenthesesName(name string) string {
-	indexArr := cleanPN3.FindAllStringIndex(name, -1)
+	indexArr := ul.CleanPN3.FindAllStringIndex(name, -1)
 	strArr, start, end := []string{}, 0, 0
 	for k, v := range indexArr {
 		if k%2 == 0 {
@@ -124,19 +37,6 @@ func cleanParenthesesName(name string) string {
 	return name
 }
 
-//加载医疗器械代码
-func loadYlqxInfo() {
-	ylqxs := *MysqlMedicalTool.Find("code_productclass", nil, "", "", -1, -1)
-	for _, v := range ylqxs {
-		name := qu.ObjToString(v["name"])
-		code := qu.ObjToString(v["code"])
-		if name != "" && code != "" {
-			YlqxCodeName[code] = name
-			YlqxNameCode[name] = code
-		}
-	}
-	log.Debug("产品数量~", len(YlqxCodeName))
-}
 func loadFifthInfo() map[string]string {
 	info := map[string]string{}
 	arr1 := []string{
@@ -1249,7 +1149,7 @@ func loadFifthInfo() map[string]string {
 	return info
 }
 func loadLastClassInfo() {
-	dataArr, _ := Save_Mgo.Find("zktest_mysql_product_info", nil, nil, map[string]interface{}{
+	dataArr, _ := ul.Save_Mgo.Find("zktest_mysql_product_info", nil, nil, map[string]interface{}{
 		"product_class1": 1,
 		"product_class2": 1,
 		"product_class3": 1,
@@ -1260,7 +1160,7 @@ func loadLastClassInfo() {
 	for _, v := range dataArr {
 		key := qu.ObjToString(v["product_name"])
 		if qu.ObjToString(v["product_class1"]) != "" {
-			LastProductInfo[key] = map[string]string{
+			ul.LastProductInfo[key] = map[string]string{
 				"product_class_1":    qu.ObjToString(v["product_class1"]),
 				"product_class_2":    qu.ObjToString(v["product_class2"]),
 				"product_class_3":    qu.ObjToString(v["product_class3"]),
@@ -1270,26 +1170,26 @@ func loadLastClassInfo() {
 			}
 		}
 	}
-	log.Debug("产品数量~", len(LastProductInfo))
+	log.Debug("产品数量~", len(ul.LastProductInfo))
 }
 
 //具体方法
 func calculationYlqxCode(yl_code string) (bool, map[string]interface{}) {
 	update := map[string]interface{}{}
 	if len(yl_code) == 2 {
-		update["product_class_1"] = YlqxCodeName[yl_code]
+		update["product_class_1"] = ul.YlqxCodeName[yl_code]
 	} else if len(yl_code) == 4 {
-		update["product_class_1"] = YlqxCodeName[yl_code[:2]]
-		update["product_class_2"] = YlqxCodeName[yl_code]
+		update["product_class_1"] = ul.YlqxCodeName[yl_code[:2]]
+		update["product_class_2"] = ul.YlqxCodeName[yl_code]
 	} else if len(yl_code) == 7 {
-		update["product_class_1"] = YlqxCodeName[yl_code[:2]]
-		update["product_class_2"] = YlqxCodeName[yl_code[:4]]
-		update["product_class_3"] = YlqxCodeName[yl_code]
+		update["product_class_1"] = ul.YlqxCodeName[yl_code[:2]]
+		update["product_class_2"] = ul.YlqxCodeName[yl_code[:4]]
+		update["product_class_3"] = ul.YlqxCodeName[yl_code]
 	} else if len(yl_code) == 11 {
-		update["product_class_1"] = YlqxCodeName[yl_code[:2]]
-		update["product_class_2"] = YlqxCodeName[yl_code[:4]]
-		update["product_class_3"] = YlqxCodeName[yl_code[:7]]
-		update["product_class_4"] = YlqxCodeName[yl_code]
+		update["product_class_1"] = ul.YlqxCodeName[yl_code[:2]]
+		update["product_class_2"] = ul.YlqxCodeName[yl_code[:4]]
+		update["product_class_3"] = ul.YlqxCodeName[yl_code[:7]]
+		update["product_class_4"] = ul.YlqxCodeName[yl_code]
 	} else {
 		return false, update
 	}
@@ -1297,38 +1197,38 @@ func calculationYlqxCode(yl_code string) (bool, map[string]interface{}) {
 	return true, update
 }
 func calculationYlqxScRange(company string, old_class string, old_name string) ([]map[string]interface{}, []string) {
-	dataArr, _ := Save_Mgo.Find("nmpa_company_new", bson.M{"company": company}, nil, bson.M{"product_range": 1})
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_company_new", bson.M{"company": company}, nil, bson.M{"product_range": 1})
 	infoArr := []map[string]interface{}{}
 	codeArr := []string{}
 	for _, v := range dataArr {
 		product_range := qu.ObjToString(v["product_range"])
-		matchArr1 := ScRangeReg1.FindAllString(product_range, -1)
+		matchArr1 := ul.ScRangeReg1.FindAllString(product_range, -1)
 		if len(matchArr1) > 0 {
 			for _, v1 := range matchArr1 {
-				name := ScRangeReg1.ReplaceAllString(v1, "${4}")
-				name = ScRangeClean1.ReplaceAllString(name, "")
-				name = ScRangeClean2.ReplaceAllString(name, "")
-				b, res := calculationYlqxCode(YlqxNameCode[name])
+				name := ul.ScRangeReg1.ReplaceAllString(v1, "${4}")
+				name = ul.ScRangeClean1.ReplaceAllString(name, "")
+				name = ul.ScRangeClean2.ReplaceAllString(name, "")
+				b, res := calculationYlqxCode(ul.YlqxNameCode[name])
 				//根据结果校验一下,是否有效合理
 				if b && checkYlqxInfoRight(res, old_class, old_name) {
 					infoArr = append(infoArr, res)
-					codeArr = append(codeArr, YlqxNameCode[name])
+					codeArr = append(codeArr, ul.YlqxNameCode[name])
 				}
 			}
 		} else {
-			matchArr2 := ScRangeReg2.FindAllString(product_range, -1)
+			matchArr2 := ul.ScRangeReg2.FindAllString(product_range, -1)
 			for _, v1 := range matchArr2 {
 				if strings.Contains(v1, "分类目录") {
 					continue
 				}
-				name := ScRangeReg2.ReplaceAllString(v1, "${2}")
-				name = ScRangeClean1.ReplaceAllString(name, "")
-				name = ScRangeClean2.ReplaceAllString(name, "")
-				b, res := calculationYlqxCode(YlqxNameCode[name])
+				name := ul.ScRangeReg2.ReplaceAllString(v1, "${2}")
+				name = ul.ScRangeClean1.ReplaceAllString(name, "")
+				name = ul.ScRangeClean2.ReplaceAllString(name, "")
+				b, res := calculationYlqxCode(ul.YlqxNameCode[name])
 				//根据结果校验一下,是否有效合理
 				if b && checkYlqxInfoRight(res, old_class, old_name) {
 					infoArr = append(infoArr, res)
-					codeArr = append(codeArr, YlqxNameCode[name])
+					codeArr = append(codeArr, ul.YlqxNameCode[name])
 				}
 			}
 		}
@@ -1399,7 +1299,7 @@ func checkYlqxInfoRight(res map[string]interface{}, class string, name string) b
 			}
 		}
 	}
-	if SpecRangeReg.MatchString(name) {
+	if ul.SpecRangeReg.MatchString(name) {
 		if qu.ObjToString(res["product_class_1"]) != "体外诊断试剂" {
 			return false
 		}
@@ -1434,7 +1334,7 @@ func checkYlqxResultRightSeventh(resArr []map[string]interface{}, codeArr []stri
 		return false, map[string]interface{}{}, ""
 	}
 	if new_class := getMaxFirstClassName(resArr); new_class != "" {
-		code := YlqxNameCode[new_class]
+		code := ul.YlqxNameCode[new_class]
 		return true, map[string]interface{}{"product_class_1": new_class, "product_class_code": code}, code
 	}
 	return false, map[string]interface{}{}, ""
@@ -1487,13 +1387,13 @@ func flagTagLog(flag string, tag string) string {
 
 //拆分合并医疗产品与企业信息
 func splitMergeMedicalInfo(coll string) {
-	sess := Old_Mgo.GetMgoConn()
-	defer Old_Mgo.DestoryMongoConn(sess)
+	sess := ul.Old_Mgo.GetMgoConn()
+	defer ul.Old_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Old_Mgo.DbName).C(coll).Find(&q).Sort("_id").Iter()
+	it := sess.DB(ul.Old_Mgo.DbName).C(coll).Find(&q).Sort("_id").Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%10000 == 0 {
-			log.Debug("cur index ", total, "~", len(companyTemp), "~", len(productTemp))
+			log.Debug("cur index ", total, "~", len(ul.CompanyTemp), "~", len(ul.ProductTemp))
 		}
 		classify := qu.ObjToString(tmp["classify"])
 		reg_no := qu.ObjToString(tmp["reg_no"])
@@ -1505,21 +1405,21 @@ func splitMergeMedicalInfo(coll string) {
 			classify == "医疗器械经营企业(许可)" || classify == "医疗器械经营企业(备案)" {
 			company := qu.ObjToString(tmp["company"])
 			if company != "" {
-				if companyTemp[reg_no] == "" {
-					companyTemp[reg_no] = company
+				if ul.CompanyTemp[reg_no] == "" {
+					ul.CompanyTemp[reg_no] = company
 					//Save_Mgo.Save("nmpa_company_new", tmp)
 				}
 			}
 		} else {
 			product_name := qu.ObjToString(tmp["product_name"])
 			if product_name != "" {
-				if productTemp[reg_no] == "" {
-					productTemp[reg_no] = product_name
+				if ul.ProductTemp[reg_no] == "" {
+					ul.ProductTemp[reg_no] = product_name
 					//Save_Mgo.Save("nmpa_product_new", tmp)
 				}
 			}
 		}
 		tmp = make(map[string]interface{})
 	}
-	log.Debug("is over ", total, "~", len(companyTemp), "~", len(productTemp))
+	log.Debug("is over ", total, "~", len(ul.CompanyTemp), "~", len(ul.ProductTemp))
 }

+ 72 - 97
data_ylqx/src/dealer.go → data_ylqx/src/dealer/dealer.go

@@ -1,4 +1,4 @@
-package main
+package dealer
 
 import (
 	log "github.com/donnie4w/go-logger/logger"
@@ -6,8 +6,34 @@ import (
 	qu "qfw/util"
 	"strings"
 	"time"
+	ul "util"
 )
 
+func StartDealWithDealerAllInfo() {
+	//经销商,基本信息
+	//exportDealerBaseInfo()
+	//testDealerTag()
+	//importDealerBaseInfoTidb()
+
+	//经销商,注册备案信息
+	//exportDealerRegisterInfo()
+	//testDealerRegisterTag()
+	//importDealerRegisterInfoTidb()
+	//importDealerScopeInfoTidb()
+
+	//经销商,产品基本信息
+	//exportDealerProductBaseInfo()
+	//exportHistoryProductBaseInfo()
+	//testProductBaseInfoTag()
+	//importProductBaseInfoTidb()
+
+	//确认企业生产分类代码
+	//exportDealerProClass()
+	//importDealerClassCodeInfoTidb()
+	//exportDealerProductClassInfo()
+	//importDealerProductClassInfoTidb()
+}
+
 //经销商-非重复信息全部入库
 func exportDealerBaseInfo() {
 	//企业信息去重
@@ -16,15 +42,15 @@ func exportDealerBaseInfo() {
 		if index%10000 == 0 {
 			log.Debug("curent index ", index)
 		}
-		pool_mgo <- true
-		wg_mgo.Add(1)
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
 		go func(tmp map[string]string) {
 			defer func() {
-				<-pool_mgo
-				wg_mgo.Done()
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
 			}()
 			for k, v := range tmp {
-				infoArr, _ := Qyxy_Mgo.Find("qyxy_std", map[string]interface{}{
+				infoArr, _ := ul.Qyxy_Mgo.Find("qyxy_std", map[string]interface{}{
 					"company_name": k,
 				}, nil, map[string]interface{}{
 					"company_name":     1,
@@ -33,14 +59,15 @@ func exportDealerBaseInfo() {
 					"company_district": 1,
 					"company_address":  1,
 					"capital":          1,
+					"use_flag":         1,
 				})
 				if len(infoArr) > 0 { //选取最优-企业信息
-					ind := getOneBaseCompany(infoArr)
+					ind := ul.GetOneBaseCompany(infoArr)
 					info := infoArr[ind]
 					new_info := createDealerInfo(info, v)
-					Save_Mgo.Save("nmpa_company_dealer", new_info)
+					ul.Save_Mgo.Save("nmpa_company_dealer", new_info)
 				} else {
-					Save_Mgo.Save("nmpa_company_dealer_err", map[string]interface{}{
+					ul.Save_Mgo.Save("nmpa_company_dealer_err", map[string]interface{}{
 						"dealer_name":    k,
 						"business_model": v,
 					})
@@ -48,7 +75,7 @@ func exportDealerBaseInfo() {
 			}
 		}(tmp)
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("经销商处理~~~", len(dataArr))
 	time.Sleep(time.Second * 2)
 }
@@ -60,7 +87,7 @@ func createDealerInfo(tmp map[string]interface{}, business_model string) map[str
 	dealer_name := qu.ObjToString(tmp["company_name"])
 	company_id := qu.ObjToString(tmp["_id"])
 	name_id := ""
-	ent := MysqlGlobalTool.FindOne("dws_f_ent_baseinfo", map[string]interface{}{
+	ent := ul.MysqlGlobalTool.FindOne("dws_f_ent_baseinfo", map[string]interface{}{
 		"name": dealer_name,
 	}, "name_id", "-id")
 	if ent != nil {
@@ -74,7 +101,7 @@ func createDealerInfo(tmp map[string]interface{}, business_model string) map[str
 	info["dealer_name"] = dealer_name
 	info["company_id"] = company_id
 	info["name_id"] = name_id
-	area_code, city_code, district_code := dealWithRegionCode(qu.ObjToString(tmp["company_area"]), qu.ObjToString(tmp["company_city"]), qu.ObjToString(tmp["company_district"]))
+	area_code, city_code, district_code := ul.DealWithRegionCode(qu.ObjToString(tmp["company_area"]), qu.ObjToString(tmp["company_city"]), qu.ObjToString(tmp["company_district"]))
 	info["area_code"] = area_code
 	info["city_code"] = city_code
 	info["district_code"] = district_code
@@ -97,33 +124,12 @@ func createDealerInfo(tmp map[string]interface{}, business_model string) map[str
 	return info
 }
 
-//获取最优企业
-func getOneBaseCompany(arr []map[string]interface{}) int {
-	index := 0
-	flag := 100
-	if len(arr) > 1 {
-		for k, tmp := range arr {
-			use_flag := qu.IntAll(tmp["use_flag"])
-			if use_flag == 0 {
-				index = k
-				break
-			} else {
-				if use_flag < flag {
-					flag = use_flag
-					index = k
-				}
-			}
-		}
-	}
-	return index
-}
-
 //重复企业-过滤
 func repeatNameQyxyInfo() []map[string]string {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_new").Find(&q).Select(map[string]interface{}{
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_new").Find(&q).Select(map[string]interface{}{
 		"company":  1,
 		"classify": 1,
 	}).Iter()
@@ -177,103 +183,72 @@ func repeatNameQyxyInfo() []map[string]string {
 	return newArr
 }
 
-//处理地域代码
-func dealWithRegionCode(area string, city string, district string) (area_code string, city_code string, district_code string) {
-	area_code, city_code, district_code = "000000", "", ""
-	if district != "" {
-		key := area + "~" + city + "~" + district + "~"
-		code := RegionCodeData[key]
-		if code != "" {
-			district_code = code
-			city_code = code[:4] + "00"
-			area_code = code[:2] + "0000"
-			return
-		}
-	}
-	if city != "" {
-		key := area + "~" + city + "~" + "" + "~"
-		code := RegionCodeData[key]
-		if code != "" {
-			city_code = code
-			area_code = city_code[:2] + "0000"
-			return
-		}
-	}
-	if area != "" {
-		key := area + "~" + "" + "~" + "" + "~"
-		code := RegionCodeData[key]
-		if code != "" {
-			area_code = code
-			return
-		}
-	}
-	return
-}
-
 func testDealerTag() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
-		"name_id": 1,
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
+		"company_id": 1,
 	}).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%10000 == 0 {
 			log.Debug("curent index ", total)
 		}
-		pool_mgo <- true
-		wg_mgo.Add(1)
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
 		go func(tmp map[string]interface{}) {
 			defer func() {
-				<-pool_mgo
-				wg_mgo.Done()
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
 			}()
-			tmpid := BsonTOStringId(tmp["_id"])
-			name_id := qu.ObjToString(tmp["name_id"])
-			info := MysqlSubjectTool.FindOne("dwd_f_yl_dealer_baseinfo", map[string]interface{}{
-				"name_id": name_id,
+			tmpid := ul.BsonTOStringId(tmp["_id"])
+			company_id := qu.ObjToString(tmp["company_id"])
+			update := map[string]interface{}{}
+			info := ul.MysqlSubjectTool.FindOne("dwd_f_yl_dealer_baseinfo", map[string]interface{}{
+				"company_id": company_id,
 			}, "", "")
-			isAdd := 1
+			update["isAdd"] = 1
 			if info != nil {
-				isAdd = 0
+				update["isAdd"] = 0
+				update["name_id"] = (*info)["name_id"]
 			}
-			Save_Mgo.UpdateById("nmpa_company_dealer", tmpid, map[string]interface{}{
-				"$set": map[string]interface{}{"isAdd": isAdd},
+			ul.Save_Mgo.UpdateById("nmpa_company_dealer", tmpid, map[string]interface{}{
+				"$set": update,
 			})
 		}(tmp)
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }
 
 //导入tidb数据
 func importDealerBaseInfoTidb() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Iter()
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%1000 == 0 {
 			log.Debug("curent index ", total)
 		}
 		if qu.IntAll(tmp["isAdd"]) == 1 {
-			pool_mgo <- true
-			wg_mgo.Add(1)
+			ul.Pool_Mgo <- true
+			ul.Wg_Mgo.Add(1)
 			go func(tmp map[string]interface{}) {
 				defer func() {
-					<-pool_mgo
-					wg_mgo.Done()
+					<-ul.Pool_Mgo
+					ul.Wg_Mgo.Done()
 				}()
-				tmpid := BsonTOStringId(tmp["_id"])
-				deleteField(&tmp, "_id", "isAdd")
-				InsertMysqlSubjectData("zktest_dwd_f_yl_dealer_baseinfo", tmp, tmpid)
+				tmpid := ul.BsonTOStringId(tmp["_id"])
+				ul.DeleteField(&tmp, "_id", "isAdd")
+				ul.InsertMysqlSubjectData("dwd_f_yl_dealer_baseinfo", tmp, tmpid)
 			}(tmp)
 		}
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }

+ 375 - 0
data_ylqx/src/dealer/dealer_class.go

@@ -0,0 +1,375 @@
+package dealer
+
+import (
+	log "github.com/donnie4w/go-logger/logger"
+	qu "qfw/util"
+	"regexp"
+	"strings"
+	"time"
+	ul "util"
+)
+
+func exportDealerProClass() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
+		"dealer_name": 1,
+		"company_id":  1,
+		"name_id":     1,
+	}).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%10000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			dealWithDealerProClassInfo(tmp)
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ... ")
+	time.Sleep(time.Second * 2)
+}
+
+func dealWithDealerProClassInfo(tmp map[string]interface{}) {
+	//去查生产经营等范围
+	dealer_id := qu.ObjToString(tmp["name_id"])
+	company_id := qu.ObjToString(tmp["company_id"])
+	dealer_name := qu.ObjToString(tmp["dealer_name"])
+	dataArr, _ := ul.Save_Mgo.Find("nmpa_company_new", map[string]interface{}{
+		"company": dealer_name,
+	}, nil, nil)
+	ScRangeArr, JyRangeArr := []string{}, []string{}
+	for _, v := range dataArr {
+		classify := qu.ObjToString(v["classify"])
+		if strings.Contains(classify, "生产") {
+			ScRangeArr = append(ScRangeArr, qu.ObjToString(v["product_range"]))
+		} else if strings.Contains(classify, "经营") {
+			JyRangeArr = append(JyRangeArr, qu.ObjToString(v["business_range"]))
+		}
+	}
+	ScCodeArr, JyCodeArr := []string{}, []string{}
+	for _, v := range ScRangeArr {
+		ScCodeArr = append(ScCodeArr, figureScRangeInfo(qu.ObjToString(v))...)
+	}
+	for _, v := range JyRangeArr {
+		JyCodeArr = append(JyCodeArr, figureJyRangeInfo(qu.ObjToString(v))...)
+	}
+	//对数组去重
+	ScCodeArr, JyCodeArr = figureRepeatArr(ScCodeArr), figureRepeatArr(JyCodeArr)
+	ScCodeArr, JyCodeArr = figureMergerArr(ScCodeArr), figureMergerArr(JyCodeArr)
+
+	for _, v := range ScCodeArr {
+		info := map[string]interface{}{}
+		info["dealer_id"] = dealer_id
+		info["company_id"] = company_id
+		info["dealer_name"] = dealer_name
+		info["business_model"] = 1
+		info["sdequipment_code"] = v
+		ul.Save_Mgo.Save("nmpa_dealer_classcode", info)
+	}
+	for _, v := range JyCodeArr {
+		info := map[string]interface{}{}
+		info["dealer_id"] = dealer_id
+		info["company_id"] = company_id
+		info["dealer_name"] = dealer_name
+		info["business_model"] = 2
+		info["sdequipment_code"] = v
+		ul.Save_Mgo.Save("nmpa_dealer_classcode", info)
+	}
+}
+
+//生产范围计算
+func figureScRangeInfo(product_range string) []string {
+	codeArr := []string{}
+	matchArr1 := ul.ScRangeReg1.FindAllString(product_range, -1)
+	if len(matchArr1) > 0 {
+		for _, v1 := range matchArr1 {
+			name := ul.ScRangeReg1.ReplaceAllString(v1, "${4}")
+			name = ul.ScRangeClean1.ReplaceAllString(name, "")
+			name = ul.ScRangeClean2.ReplaceAllString(name, "")
+			yl_code := ul.YlqxNameCode[name]
+			if yl_code != "" {
+				codeArr = append(codeArr, yl_code)
+			}
+		}
+	}
+	matchArr2 := ul.ScRangeReg2.FindAllString(product_range, -1)
+	for _, v1 := range matchArr2 {
+		if strings.Contains(v1, "分类目录") {
+			continue
+		}
+		name := ul.ScRangeReg2.ReplaceAllString(v1, "${2}")
+		name = ul.ScRangeClean1.ReplaceAllString(name, "")
+		name = ul.ScRangeClean2.ReplaceAllString(name, "")
+		yl_code := ul.YlqxNameCode[name]
+		if yl_code != "" {
+			codeArr = append(codeArr, yl_code)
+		}
+	}
+	return codeArr
+}
+
+//经营范围范围计算
+func figureJyRangeInfo(business_range string) []string {
+	codesArr := []string{}
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg1, "A")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg2, "")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg3, "A")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg4, "B")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg5, "")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg6, "C")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg7, "A")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg8, "B")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JyRangeReg9, "C")
+	figureRuleRegexpInfo(&codesArr, business_range, ul.JySpecReg1, "S")
+	return codesArr
+}
+
+func figureRuleRegexpInfo(codesArr *[]string, business_range string, JyRangeReg *regexp.Regexp, ruleCode string) {
+	arr := JyRangeReg.FindAllString(business_range, -1)
+	for _, v := range arr {
+		text := JyRangeReg.ReplaceAllString(v, "${1}")
+		yl_code := ""
+		if ruleCode == "A" {
+			yl_code = ul.JyCodeA[text]
+		} else if ruleCode == "B" {
+			yl_code = ul.JyCodeB[text]
+		} else if ruleCode == "C" {
+			yl_code = ul.JyCodeC[text]
+		} else if ruleCode == "S" {
+			if strings.Contains(text, "体外诊断试剂") && !ul.JyExcludeReg1.MatchString(text) {
+				yl_code = "23"
+			} else {
+				yl_code = "22"
+			}
+		} else {
+			yl_code = ul.YlqxNameCode[text]
+		}
+		if yl_code != "" {
+			*codesArr = append(*codesArr, yl_code)
+		}
+	}
+}
+
+func figureRepeatArr(arr []string) []string {
+	new_arr := []string{}
+	temp := map[string]string{}
+	for _, v := range arr {
+		if temp[v] == "" {
+			temp[v] = v
+			new_arr = append(new_arr, v)
+		}
+	}
+	return new_arr
+}
+
+func figureMergerArr(arr []string) []string {
+	//2 2 3 4 位
+	temp := map[string]string{}
+	for _, v := range arr {
+		temp[v] = v
+	}
+	new_arr := []string{}
+	for _, v := range arr {
+		isValid := false
+		l := len(v)
+		if l == 2 {
+			isValid = true
+		} else if l == 4 {
+			if temp[v[:2]] == "" {
+				isValid = true
+			}
+		} else if l == 7 {
+			if temp[v[:2]] == "" && temp[v[:4]] == "" {
+				isValid = true
+			}
+		} else if l == 11 {
+			if temp[v[:2]] == "" && temp[v[:4]] == "" && temp[v[:7]] == "" {
+				isValid = true
+			}
+		} else {
+
+		}
+		if isValid {
+			new_arr = append(new_arr, v)
+		}
+	}
+	return new_arr
+}
+
+func exportDealerProductClassInfo() {
+	classCodeArr := ul.MysqlSubjectTool.Find("dwd_f_yl_dealer_pro_classify", nil, "", "", -1, -1)
+	productsArr := ul.MysqlSubjectTool.Find("dwd_f_yl_dealer_pro_baseinfo", nil, "dealer_id,company_id,company_name,product_name,sdproduct_name,sdequipment_code,medical_equipment_class1,medical_equipment_class2,medical_equipment_class3", "", -1, -1)
+	if productsArr == nil || classCodeArr == nil {
+		log.Debug("无数据 ...")
+		return
+	}
+	ScClassTemp, JyClassTemp := map[string][]string{}, map[string][]string{}
+	for _, v := range *classCodeArr {
+		dealer_id := qu.ObjToString(v["dealer_id"])
+		sdequipment_code := qu.ObjToString(v["sdequipment_code"])
+		business_model := qu.IntAll(v["business_model"])
+		if business_model == 1 {
+			sc_info := ScClassTemp[dealer_id]
+			if sc_info == nil {
+				ScClassTemp[dealer_id] = []string{sdequipment_code}
+			} else {
+				sc_info = append(sc_info, sdequipment_code)
+				ScClassTemp[dealer_id] = sc_info
+			}
+		} else if business_model == 2 {
+			jy_info := JyClassTemp[dealer_id]
+			if jy_info == nil {
+				JyClassTemp[dealer_id] = []string{sdequipment_code}
+			} else {
+				jy_info = append(jy_info, sdequipment_code)
+				JyClassTemp[dealer_id] = jy_info
+			}
+		} else {
+
+		}
+	}
+	log.Debug("企业能力~", len(ScClassTemp), "~", len(JyClassTemp))
+	log.Debug("企业产品数量~", len(*productsArr))
+
+	for _, v := range *productsArr {
+		dealer_id := qu.ObjToString(v["dealer_id"])
+		company_id := qu.ObjToString(v["company_id"])
+		company_name := qu.ObjToString(v["company_name"])
+		product_name := qu.ObjToString(v["product_name"])
+		sdproduct_name := qu.ObjToString(v["sdproduct_name"])
+		sdequipment_code := qu.ObjToString(v["sdequipment_code"])
+		medical_equipment_class1 := qu.ObjToString(v["medical_equipment_class1"])
+		medical_equipment_class2 := qu.ObjToString(v["medical_equipment_class2"])
+		medical_equipment_class3 := qu.ObjToString(v["medical_equipment_class3"])
+		if sdequipment_code == "" {
+			continue
+		}
+		if ScClassTemp[dealer_id] != nil {
+			if figureConformToClass(ScClassTemp[dealer_id], sdequipment_code) {
+				//符合
+				info := map[string]interface{}{}
+				info["company_id"] = company_id
+				info["dealer_id"] = dealer_id
+				info["dealer_name"] = company_name
+				info["sdequipment_code"] = sdequipment_code
+				info["business_model"] = 1
+				info["medical_equipment_class1"] = medical_equipment_class1
+				info["medical_equipment_class2"] = medical_equipment_class2
+				info["medical_equipment_class3"] = medical_equipment_class3
+				info["sdproduct_name"] = sdproduct_name
+				info["product_name"] = product_name
+				ul.Save_Mgo.Save("nmpa_dealer_class_product", info)
+			}
+		}
+		if JyClassTemp[dealer_id] != nil {
+			if figureConformToClass(JyClassTemp[dealer_id], sdequipment_code) {
+				//符合
+				info := map[string]interface{}{}
+				info["company_id"] = company_id
+				info["dealer_id"] = dealer_id
+				info["dealer_name"] = company_name
+				info["sdequipment_code"] = sdequipment_code
+				info["business_model"] = 2
+				info["medical_equipment_class1"] = medical_equipment_class1
+				info["medical_equipment_class2"] = medical_equipment_class2
+				info["medical_equipment_class3"] = medical_equipment_class3
+				info["sdproduct_name"] = sdproduct_name
+				info["product_name"] = product_name
+				ul.Save_Mgo.Save("nmpa_dealer_class_product", info)
+			}
+		}
+	}
+	log.Debug("is over ...")
+	time.Sleep(time.Second * 2)
+}
+
+func figureConformToClass(arr []string, code string) bool {
+	l := len(code)
+	for _, v := range arr {
+		if v == code {
+			return true
+		}
+		if l == 4 {
+			c2 := code[:2]
+			if c2 == v {
+				return true
+			}
+		} else if l == 7 {
+			c2, c4 := code[:2], code[:4]
+			if c2 == v || c4 == v {
+				return true
+			}
+		} else if l == 11 {
+			c2, c4, c7 := code[:2], code[:4], code[:7]
+			if c2 == v || c4 == v || c7 == v {
+				return true
+			}
+		} else {
+
+		}
+	}
+	return false
+}
+
+//导入tidb数据
+func importDealerClassCodeInfoTidb() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_dealer_classcode").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%10000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			tmpid := ul.BsonTOStringId(tmp["_id"])
+			ul.DeleteField(&tmp, "_id")
+			ul.InsertMysqlSubjectData("dwd_f_yl_dealer_pro_classify", tmp, tmpid)
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ... ")
+	time.Sleep(time.Second * 2)
+}
+func importDealerProductClassInfoTidb() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_dealer_class_product").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%10000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			tmpid := ul.BsonTOStringId(tmp["_id"])
+			ul.DeleteField(&tmp, "_id")
+			ul.InsertMysqlSubjectData("dwd_f_yl_dealer_product_info", tmp, tmpid)
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ... ")
+	time.Sleep(time.Second * 2)
+}

+ 229 - 0
data_ylqx/src/dealer/dealer_info.go

@@ -0,0 +1,229 @@
+package dealer
+
+import (
+	log "github.com/donnie4w/go-logger/logger"
+	"github.com/uuid"
+	qu "qfw/util"
+	"strings"
+	"time"
+	ul "util"
+)
+
+//经销商-非重复信息全部入库
+func ExportDealerBaseInfo() {
+	//企业信息去重
+	dataArr := repeatNameQyxyInfo()
+	for index, tmp := range dataArr {
+		if index%10000 == 0 {
+			log.Debug("curent index ", index)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]string) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			for k, v := range tmp {
+				infoArr, _ := ul.Qyxy_Mgo.Find("qyxy_std", map[string]interface{}{
+					"company_name": k,
+				}, nil, map[string]interface{}{
+					"company_name":     1,
+					"company_area":     1,
+					"company_city":     1,
+					"company_district": 1,
+					"company_address":  1,
+					"capital":          1,
+					"use_flag":         1,
+				})
+				if len(infoArr) > 0 { //选取最优-企业信息
+					ind := ul.GetOneBaseCompany(infoArr)
+					info := infoArr[ind]
+					new_info := createDealerInfo(info, v)
+					ul.Save_Mgo.Save("nmpa_company_dealer", new_info)
+				} else {
+					ul.Save_Mgo.Save("nmpa_company_dealer_err", map[string]interface{}{
+						"dealer_name":    k,
+						"business_model": v,
+					})
+				}
+			}
+		}(tmp)
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("经销商处理~~~", len(dataArr))
+	time.Sleep(time.Second * 2)
+}
+
+//构建更新数据
+func CreateDealerInfo(tmp map[string]interface{}, business_model string) map[string]interface{} {
+	info := map[string]interface{}{}
+	//查询主题库
+	dealer_name := qu.ObjToString(tmp["company_name"])
+	company_id := qu.ObjToString(tmp["_id"])
+	name_id := ""
+	ent := ul.MysqlGlobalTool.FindOne("dws_f_ent_baseinfo", map[string]interface{}{
+		"name": dealer_name,
+	}, "name_id", "-id")
+	if ent != nil {
+		name_id = qu.ObjToString((*ent)["name_id"])
+		info["exists_id"] = 1
+	} else {
+		name_id = uuid.New().String()
+		name_id = strings.ReplaceAll(name_id, "-", "")
+		info["exists_id"] = 0
+	}
+	info["dealer_name"] = dealer_name
+	info["company_id"] = company_id
+	info["name_id"] = name_id
+	area_code, city_code, district_code := ul.DealWithRegionCode(qu.ObjToString(tmp["company_area"]), qu.ObjToString(tmp["company_city"]), qu.ObjToString(tmp["company_district"]))
+	info["area_code"] = area_code
+	info["city_code"] = city_code
+	info["district_code"] = district_code
+	info["business_model"] = qu.IntAll(business_model)
+	info["company_address"] = qu.ObjToString(tmp["company_address"])
+	//data := Spi_Mgo.FindOne("company_base", bson.M{"company_id": company_id})
+	//new_capital := qu.ObjToString(data["capital"])
+	capital, capital_code := qu.Float64All(tmp["capital"]), 1
+	if capital >= float64(0) && capital < float64(100) {
+		capital_code = 1
+	} else if capital >= float64(100) && capital < float64(500) {
+		capital_code = 2
+	} else if capital >= float64(500) && capital < float64(1000) {
+		capital_code = 3
+	} else {
+		capital_code = 4
+	}
+	info["capital"] = capital
+	info["capital_code"] = capital_code
+	return info
+}
+
+//重复企业-过滤
+func RepeatNameQyxyInfo() []map[string]string {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_new").Find(&q).Select(map[string]interface{}{
+		"company":  1,
+		"classify": 1,
+	}).Iter()
+	temp := map[string]string{}
+	qyArr := []string{}
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%10000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		company := qu.ObjToString(tmp["company"])
+		classify := qu.ObjToString(tmp["classify"])
+		model := ""
+		if strings.Contains(classify, "生产") {
+			model = "生产"
+		} else if strings.Contains(classify, "经营") {
+			model = "经营"
+		} else {
+			log.Debug("类型异常~~~~~~")
+		}
+		if company != "" {
+			if temp[company] == "" {
+				temp[company] = model
+				qyArr = append(qyArr, company)
+			} else {
+				pre_model := temp[company]
+				if pre_model != model && model != "" && !strings.Contains(pre_model, "&&") {
+					temp[company] = pre_model + "&&" + model
+				}
+			}
+		}
+		tmp = make(map[string]interface{})
+	}
+	newArr := []map[string]string{}
+	for _, v := range qyArr {
+		tag := ""
+		if temp[v] == "生产" {
+			tag = "1"
+		} else if temp[v] == "经营" {
+			tag = "2"
+		} else if temp[v] == "" {
+			tag = "4"
+		} else {
+			tag = "3"
+		}
+		newArr = append(newArr, map[string]string{
+			v: tag,
+		})
+	}
+
+	log.Debug("企业去重~", total, len(newArr))
+	return newArr
+}
+
+func TestDealerTag() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
+		"company_id": 1,
+	}).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%10000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			tmpid := ul.BsonTOStringId(tmp["_id"])
+			company_id := qu.ObjToString(tmp["company_id"])
+			update := map[string]interface{}{}
+			info := ul.MysqlSubjectTool.FindOne("dwd_f_yl_dealer_baseinfo", map[string]interface{}{
+				"company_id": company_id,
+			}, "", "")
+			update["isAdd"] = 1
+			if info != nil {
+				update["isAdd"] = 0
+				update["name_id"] = (*info)["name_id"]
+			}
+			ul.Save_Mgo.UpdateById("nmpa_company_dealer", tmpid, map[string]interface{}{
+				"$set": update,
+			})
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ... ")
+	time.Sleep(time.Second * 2)
+}
+
+//导入tidb数据
+func ImportDealerBaseInfoTidb() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%1000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		if qu.IntAll(tmp["isAdd"]) == 1 {
+			ul.Pool_Mgo <- true
+			ul.Wg_Mgo.Add(1)
+			go func(tmp map[string]interface{}) {
+				defer func() {
+					<-ul.Pool_Mgo
+					ul.Wg_Mgo.Done()
+				}()
+				tmpid := ul.BsonTOStringId(tmp["_id"])
+				ul.DeleteField(&tmp, "_id", "isAdd")
+				ul.InsertMysqlSubjectData("dwd_f_yl_dealer_baseinfo", tmp, tmpid)
+			}(tmp)
+		}
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ... ")
+	time.Sleep(time.Second * 2)
+}

+ 48 - 42
data_ylqx/src/product.go → data_ylqx/src/dealer/dealer_product.go

@@ -1,4 +1,4 @@
-package main
+package dealer
 
 import (
 	log "github.com/donnie4w/go-logger/logger"
@@ -6,15 +6,16 @@ import (
 	qu "qfw/util"
 	"strings"
 	"time"
+	ul "util"
 )
 
 //导出产品信息相关
-func exportProductBaseInfo() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+func exportDealerProductBaseInfo() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
 	isok := 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
 		"dealer_name": 1,
 		"company_id":  1,
 		"name_id":     1,
@@ -23,7 +24,7 @@ func exportProductBaseInfo() {
 		if total%10000 == 0 {
 			log.Debug("curent index ", total, "~", isok)
 		}
-		num := createProductBaseInfo(tmp)
+		num := createDealerProductBaseInfo(tmp)
 		isok += num
 		tmp = make(map[string]interface{})
 	}
@@ -31,20 +32,20 @@ func exportProductBaseInfo() {
 	time.Sleep(time.Second * 2)
 }
 
-func createProductBaseInfo(dealerInfo map[string]interface{}) int {
+func createDealerProductBaseInfo(dealerInfo map[string]interface{}) int {
 	num := 0
 	dealer_name := qu.ObjToString(dealerInfo["dealer_name"])
-	infoArr, _ := Save_Mgo.Find("nmpa_product_new", bson.M{"reg_company": dealer_name}, nil, nil)
+	infoArr, _ := ul.Save_Mgo.Find("nmpa_product_new", bson.M{"reg_company": dealer_name}, nil, nil)
 	for _, v := range infoArr {
 		num++
-		info := dealWithProductInfo(v, dealerInfo)
-		Save_Mgo.Save("nmpa_product_baseinfo", info)
+		info := dealWithDealerProductInfo(v, dealerInfo)
+		ul.Save_Mgo.Save("nmpa_product_baseinfo", info)
 	}
 	return num
 }
 
 //根据新经销商信息~暂时补充的数量
-func dealWithProductInfo(tmp map[string]interface{}, dealerInfo map[string]interface{}) map[string]interface{} {
+func dealWithDealerProductInfo(tmp map[string]interface{}, dealerInfo map[string]interface{}) map[string]interface{} {
 	info := map[string]interface{}{}
 	info["dealer_id"] = qu.ObjToString(dealerInfo["name_id"])
 	info["company_id"] = qu.ObjToString(dealerInfo["company_id"])
@@ -75,8 +76,8 @@ func dealWithProductInfo(tmp map[string]interface{}, dealerInfo map[string]inter
 	info["use_scope "] = qu.ObjToString(tmp["application"])
 	info["storage_conditions"] = qu.ObjToString(tmp["conditions_use"])
 	info["remark "] = qu.ObjToString(tmp["remark"])
-	info["approve_depart"] = pickfirst(qu.ObjToString(tmp["spbm"]), qu.ObjToString(tmp["badw"]))
-	info["approve_date"] = pickfirst(qu.ObjToString(tmp["pzrq"]), qu.ObjToString(tmp["barq"]))
+	info["approve_depart"] = ul.Pickfirst(qu.ObjToString(tmp["spbm"]), qu.ObjToString(tmp["badw"]))
+	info["approve_date"] = ul.Pickfirst(qu.ObjToString(tmp["pzrq"]), qu.ObjToString(tmp["barq"]))
 	info["validity_date"] = qu.ObjToString(tmp["yxqz"])
 	info["changes"] = qu.ObjToString(tmp["changes"])
 	info["source_channel"] = classify
@@ -103,7 +104,7 @@ func dealWithProductInfo(tmp map[string]interface{}, dealerInfo map[string]inter
 //根据剩余产品信息-是否属于历史经销商的产品数据
 func exportHistoryProductBaseInfo() {
 	temp := map[string]string{}
-	infosArr, _ := Save_Mgo.Find("nmpa_product_baseinfo", nil, nil, map[string]interface{}{
+	infosArr, _ := ul.Save_Mgo.Find("nmpa_product_baseinfo", nil, nil, map[string]interface{}{
 		"regno": 1,
 	})
 	for _, v := range infosArr {
@@ -112,11 +113,11 @@ func exportHistoryProductBaseInfo() {
 	}
 	log.Debug("当前产品信息数量~", len(temp))
 
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
 	isok := 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_product_new").Find(&q).Iter()
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_product_new").Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%1000 == 0 {
 			log.Debug("curent index ", total, "~", isok)
@@ -126,7 +127,7 @@ func exportHistoryProductBaseInfo() {
 		if temp[reg_no] == "" {
 			isok++
 			//计算历史数据是否有相关的经销商企业信息:
-			data := MysqlSubjectTool.FindOne("dwd_f_yl_dealer_baseinfo", map[string]interface{}{
+			data := ul.MysqlSubjectTool.FindOne("dwd_f_yl_dealer_baseinfo", map[string]interface{}{
 				"dealer_name": reg_company,
 			}, "", "")
 			if data != nil {
@@ -134,8 +135,8 @@ func exportHistoryProductBaseInfo() {
 				dealerInfo["name_id"] = qu.ObjToString((*data)["name_id"])
 				dealerInfo["company_id"] = qu.ObjToString((*data)["company_id"])
 				dealerInfo["dealer_name"] = qu.ObjToString((*data)["dealer_name"])
-				info := dealWithProductInfo(tmp, dealerInfo)
-				Save_Mgo.Save("nmpa_product_baseinfo", info)
+				info := dealWithDealerProductInfo(tmp, dealerInfo)
+				ul.Save_Mgo.Save("nmpa_product_baseinfo", info)
 			}
 		}
 		tmp = make(map[string]interface{})
@@ -146,69 +147,74 @@ func exportHistoryProductBaseInfo() {
 
 //
 func testProductBaseInfoTag() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_product_baseinfo").Find(&q).Sort("_id").Select(map[string]interface{}{
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_product_baseinfo").Find(&q).Sort("_id").Select(map[string]interface{}{
 		"regno": 1,
 	}).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%10000 == 0 {
 			log.Debug("curent index ", total)
 		}
-		pool_mgo <- true
-		wg_mgo.Add(1)
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
 		go func(tmp map[string]interface{}) {
 			defer func() {
-				<-pool_mgo
-				wg_mgo.Done()
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
 			}()
-			tmpid := BsonTOStringId(tmp["_id"])
+			tmpid := ul.BsonTOStringId(tmp["_id"])
 			regno := qu.ObjToString(tmp["regno"])
-			info := MysqlSubjectTool.FindOne("dwd_f_yl_dealer_pro_baseinfo", map[string]interface{}{
+			info := ul.MysqlSubjectTool.FindOne("dwd_f_yl_dealer_pro_baseinfo", map[string]interface{}{
 				"regno": regno,
 			}, "", "")
 			isAdd := 1
 			if info != nil {
 				isAdd = 0
 			}
-			Save_Mgo.UpdateById("nmpa_product_baseinfo", tmpid, map[string]interface{}{
+			ul.Save_Mgo.UpdateById("nmpa_product_baseinfo", tmpid, map[string]interface{}{
 				"$set": map[string]interface{}{"isAdd": isAdd},
 			})
 		}(tmp)
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }
 
 //导入tidb数据
 func importProductBaseInfoTidb() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	//tmp := Save_Mgo.FindById("nmpa_product_baseinfo", "646d9fa659e55dc0c6a5ff03")
+	//tmpid := BsonTOStringId(tmp["_id"])
+	//deleteField(&tmp, "_id", "isAdd")
+	//InsertMysqlSubjectData("dwd_f_yl_dealer_pro_baseinfo", tmp, tmpid)
+	//return
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_product_baseinfo").Find(&q).Iter()
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_product_baseinfo").Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%1000 == 0 {
 			log.Debug("curent index ", total)
 		}
 		if qu.IntAll(tmp["isAdd"]) == 1 {
-			pool_mgo <- true
-			wg_mgo.Add(1)
+			ul.Pool_Mgo <- true
+			ul.Wg_Mgo.Add(1)
 			go func(tmp map[string]interface{}) {
 				defer func() {
-					<-pool_mgo
-					wg_mgo.Done()
+					<-ul.Pool_Mgo
+					ul.Wg_Mgo.Done()
 				}()
-				tmpid := BsonTOStringId(tmp["_id"])
-				deleteField(&tmp, "_id", "isAdd")
-				InsertMysqlSubjectData("zktest_dwd_f_yl_dealer_pro_baseinfo", tmp, tmpid)
+				tmpid := ul.BsonTOStringId(tmp["_id"])
+				ul.DeleteField(&tmp, "_id", "isAdd")
+				ul.InsertMysqlSubjectData("dwd_f_yl_dealer_pro_baseinfo", tmp, tmpid)
 			}(tmp)
 		}
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }

+ 34 - 40
data_ylqx/src/dealer_register.go → data_ylqx/src/dealer/dealer_register.go

@@ -1,20 +1,21 @@
-package main
+package dealer
 
 import (
-	"github.com/go-xweb/log"
+	log "github.com/donnie4w/go-logger/logger"
 	"go.mongodb.org/mongo-driver/bson"
 	qu "qfw/util"
 	"strings"
 	"time"
+	ul "util"
 )
 
 //导出经销商注册备案信息
 func exportDealerRegisterInfo() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
 	isok := 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Select(map[string]interface{}{
 		"name_id":        1,
 		"dealer_name":    1,
 		"business_model": 1,
@@ -36,7 +37,7 @@ func createDealerRegisterInfo(tmp map[string]interface{}) int {
 	company_name := qu.ObjToString(tmp["dealer_name"])
 	dealer_id := qu.ObjToString(tmp["name_id"])
 	business_model := qu.IntAll(tmp["business_model"])
-	infoArr, _ := Save_Mgo.Find("nmpa_company_new", bson.M{"company": company_name}, bson.M{"_id": 1}, nil)
+	infoArr, _ := ul.Save_Mgo.Find("nmpa_company_new", bson.M{"company": company_name}, bson.M{"_id": 1}, nil)
 	num := 0
 	for _, v := range infoArr {
 		if qu.ObjToString(v["reg_no"]) == "" {
@@ -58,88 +59,81 @@ func createDealerRegisterInfo(tmp map[string]interface{}) int {
 		info["business_type"] = business_model
 		info["validity_date"] = qu.ObjToString(v["yxqx"])
 
-		info["scope"] = pickfirst(qu.ObjToString(v["product_range"]), qu.ObjToString(v["business_range"]))
-		info["approve_depart"] = pickfirst(qu.ObjToString(v["fzbm"]), qu.ObjToString(v["badw"]))
-		info["approve_date"] = pickfirst(qu.ObjToString(v["fzrq"]), qu.ObjToString(v["barq"]))
-		info["type_address"] = pickfirst(qu.ObjToString(v["product_address"]), qu.ObjToString(v["business_address"]))
+		info["scope"] = ul.Pickfirst(qu.ObjToString(v["product_range"]), qu.ObjToString(v["business_range"]))
+		info["approve_depart"] = ul.Pickfirst(qu.ObjToString(v["fzbm"]), qu.ObjToString(v["badw"]))
+		info["approve_date"] = ul.Pickfirst(qu.ObjToString(v["fzrq"]), qu.ObjToString(v["barq"]))
+		info["type_address"] = ul.Pickfirst(qu.ObjToString(v["product_address"]), qu.ObjToString(v["business_address"]))
 		info["responsible_person"] = qu.ObjToString(v["responsible_persons"])
 		info["legal_person"] = qu.ObjToString(v["legal_person"])
-		Save_Mgo.Save("nmpa_company_register", info)
+		ul.Save_Mgo.Save("nmpa_company_register", info)
 	}
 	return num
 }
 
-func pickfirst(s1 string, s2 string) string {
-	if s1 != "" {
-		return s1
-	}
-	return s2
-}
-
 func testDealerRegisterTag() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_register").Find(&q).Sort("_id").Select(map[string]interface{}{
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_register").Find(&q).Sort("_id").Select(map[string]interface{}{
 		"regnum": 1,
 	}).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%10000 == 0 {
 			log.Debug("curent index ", total)
 		}
-		pool_mgo <- true
-		wg_mgo.Add(1)
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
 		go func(tmp map[string]interface{}) {
 			defer func() {
-				<-pool_mgo
-				wg_mgo.Done()
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
 			}()
-			tmpid := BsonTOStringId(tmp["_id"])
+			tmpid := ul.BsonTOStringId(tmp["_id"])
 			regnum := qu.ObjToString(tmp["regnum"])
-			info := MysqlSubjectTool.FindOne("dwd_f_yl_dealer_register", map[string]interface{}{
+			info := ul.MysqlSubjectTool.FindOne("dwd_f_yl_dealer_register", map[string]interface{}{
 				"regnum": regnum,
 			}, "", "")
 			isAdd := 1
 			if info != nil {
 				isAdd = 0
 			}
-			Save_Mgo.UpdateById("nmpa_company_register", tmpid, map[string]interface{}{
+			ul.Save_Mgo.UpdateById("nmpa_company_register", tmpid, map[string]interface{}{
 				"$set": map[string]interface{}{"isAdd": isAdd},
 			})
 		}(tmp)
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }
 
 //导入tidb数据
 func importDealerRegisterInfoTidb() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_register").Find(&q).Iter()
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_register").Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%1000 == 0 {
 			log.Debug("curent index ", total)
 		}
 		if qu.IntAll(tmp["isAdd"]) == 1 {
-			pool_mgo <- true
-			wg_mgo.Add(1)
+			ul.Pool_Mgo <- true
+			ul.Wg_Mgo.Add(1)
 			go func(tmp map[string]interface{}) {
 				defer func() {
-					<-pool_mgo
-					wg_mgo.Done()
+					<-ul.Pool_Mgo
+					ul.Wg_Mgo.Done()
 				}()
-				tmpid := BsonTOStringId(tmp["_id"])
-				deleteField(&tmp, "_id", "isAdd")
-				InsertMysqlSubjectData("zktest_dwd_f_yl_dealer_register", tmp, tmpid)
+				tmpid := ul.BsonTOStringId(tmp["_id"])
+				ul.DeleteField(&tmp, "_id", "isAdd")
+				ul.InsertMysqlSubjectData("dwd_f_yl_dealer_register", tmp, tmpid)
 			}(tmp)
 		}
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }

+ 14 - 13
data_ylqx/src/dealer_scope.go → data_ylqx/src/dealer/dealer_scope.go

@@ -1,19 +1,20 @@
-package main
+package dealer
 
 import (
 	log "github.com/donnie4w/go-logger/logger"
 	qu "qfw/util"
 	"strings"
 	"time"
+	ul "util"
 )
 
 //经销商能力标签表
 func importDealerScopeInfoTidb() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
 	ScopeInfos, ScopeIndexs := map[string][]string{}, []string{}
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_register").Find(&q).Iter()
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_register").Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%10000 == 0 {
 			log.Debug("curent index ", total)
@@ -44,12 +45,12 @@ func importDealerScopeInfoTidb() {
 		if k%1000 == 0 {
 			log.Debug("cur index ", k)
 		}
-		pool_mgo <- true
-		wg_mgo.Add(1)
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
 		go func(v string) {
 			defer func() {
-				<-pool_mgo
-				wg_mgo.Done()
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
 			}()
 			scopeArr := ScopeInfos[v]
 			if len(scopeArr) > 0 {
@@ -57,7 +58,7 @@ func importDealerScopeInfoTidb() {
 			}
 		}(v)
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }
@@ -77,17 +78,17 @@ func createScopeTagInfo(dealer_id string, scopeArr []string) {
 	}
 	info := map[string]interface{}{}
 	info["dealer_id"] = dealer_id
-	info["createtime"] = time.Unix(time.Now().Unix(), 0).Format(TimeLayout)
+	info["createtime"] = time.Unix(time.Now().Unix(), 0).Format(ul.TimeLayout)
 	if a {
 		info["labelvalues"] = "01"
-		InsertMysqlSubjectData("zktesr_dwd_f_yl_dealer_busclass_tags", info, dealer_id)
+		ul.InsertMysqlSubjectData("dwd_f_yl_dealer_busclass_tags", info, dealer_id)
 	}
 	if b {
 		info["labelvalues"] = "02"
-		InsertMysqlSubjectData("zktesr_dwd_f_yl_dealer_busclass_tags", info, dealer_id)
+		ul.InsertMysqlSubjectData("dwd_f_yl_dealer_busclass_tags", info, dealer_id)
 	}
 	if c {
 		info["labelvalues"] = "03"
-		InsertMysqlSubjectData("zktesr_dwd_f_yl_dealer_busclass_tags", info, dealer_id)
+		ul.InsertMysqlSubjectData("dwd_f_yl_dealer_busclass_tags", info, dealer_id)
 	}
 }

+ 44 - 27
data_ylqx/src/legal.go → data_ylqx/src/legal/legal.go

@@ -1,33 +1,40 @@
-package main
+package legal
 
 import (
 	log "github.com/donnie4w/go-logger/logger"
 	"go.mongodb.org/mongo-driver/bson"
 	qu "qfw/util"
 	"time"
+	ul "util"
 )
 
+func StartDealWithLegalBaseInfo() {
+	//法人,基本信息
+	//exportLegalBaseInfo()
+	//importLegalBaseInfoTidb()
+}
+
 //法人基础信息表
 func exportLegalBaseInfo() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Sort("_id").Select(map[string]interface{}{
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_company_dealer").Find(&q).Sort("_id").Select(map[string]interface{}{
 		"company_id":  1,
 		"dealer_name": 1,
 		"isAdd":       1,
 	}).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
-		if total%1000 == 0 {
+		if total%10000 == 0 {
 			log.Debug("curent index ", total)
 		}
 		if qu.IntAll(tmp["isAdd"]) == 1 {
-			pool_mgo <- true
-			wg_mgo.Add(1)
+			ul.Pool_Mgo <- true
+			ul.Wg_Mgo.Add(1)
 			go func(tmp map[string]interface{}) {
 				defer func() {
-					<-pool_mgo
-					wg_mgo.Done()
+					<-ul.Pool_Mgo
+					ul.Wg_Mgo.Done()
 				}()
 				company_id := qu.ObjToString(tmp["company_id"])
 				dealer_name := qu.ObjToString(tmp["dealer_name"])
@@ -36,7 +43,7 @@ func exportLegalBaseInfo() {
 		}
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }
@@ -45,9 +52,9 @@ func createLegalBaseInfo(company_name string, company_id string) {
 	info := map[string]interface{}{}
 	info["company_name"] = company_name
 	info["company_id"] = company_id
-	infoArr, _ := Qyxy_Mgo.Find("qyxy_std", map[string]interface{}{"company_name": company_name}, nil, nil)
+	infoArr, _ := ul.Qyxy_Mgo.Find("qyxy_std", map[string]interface{}{"company_name": company_name}, nil, nil)
 	if len(infoArr) > 0 {
-		ind := getOneBaseCompany(infoArr)
+		ind := ul.GetOneBaseCompany(infoArr)
 		tmp := infoArr[ind]
 		info["company_code"] = qu.ObjToString(tmp["company_code"])
 		info["credit_no"] = qu.ObjToString(tmp["credit_no"])
@@ -63,7 +70,7 @@ func createLegalBaseInfo(company_name string, company_id string) {
 		info["operation_startdate"] = qu.ObjToString(tmp["operation_startdate"])
 		info["operation_enddate"] = qu.ObjToString(tmp["operation_enddate"])
 
-		data := Spi_Mgo.FindOne("company_base", bson.M{"company_id": company_id})
+		data := ul.Spi_Mgo.FindOne("company_base", bson.M{"company_id": company_id})
 		new_capital := qu.ObjToString(data["capital"])
 		info["capital"] = new_capital
 
@@ -84,40 +91,50 @@ func createLegalBaseInfo(company_name string, company_id string) {
 			info["insurance_amount"] = qu.IntAll(tmp["employee_num"])
 		}
 		//区域代码
-		area_code, _, _ := dealWithRegionCode(qu.ObjToString(tmp["company_area"]), qu.ObjToString(tmp["company_city"]), qu.ObjToString(tmp["company_district"]))
+		area_code, _, _ := ul.DealWithRegionCode(qu.ObjToString(tmp["company_area"]), qu.ObjToString(tmp["company_city"]), qu.ObjToString(tmp["company_district"]))
 		info["area_code"] = area_code
 		info["company_phone"] = qu.ObjToString(tmp["company_phone"])
 		info["company_email"] = qu.ObjToString(tmp["company_email"])
-		info["website"] = qu.ObjToString(tmp["website_url"])
+
+		website := qu.ObjToString(tmp["website_url"])
+		if len(website) > 200 {
+			website = ""
+		}
+		info["website"] = website
+
 		info["sourcetype"] = 1
-		Save_Mgo.Save("nmpa_legal_baseinfo", info)
+		ul.Save_Mgo.Save("nmpa_legal_baseinfo", info)
 	}
 }
 
 //导入tidb数据
 func importLegalBaseInfoTidb() {
-	sess := Save_Mgo.GetMgoConn()
-	defer Save_Mgo.DestoryMongoConn(sess)
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
 	q, total := map[string]interface{}{}, 0
-	it := sess.DB(Save_Mgo.DbName).C("nmpa_legal_baseinfo").Find(&q).Iter()
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_legal_baseinfo").Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
 		if total%1000 == 0 {
 			log.Debug("curent index ", total)
 		}
-		pool_mgo <- true
-		wg_mgo.Add(1)
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
 		go func(tmp map[string]interface{}) {
 			defer func() {
-				<-pool_mgo
-				wg_mgo.Done()
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
 			}()
-			tmpid := BsonTOStringId(tmp["_id"])
-			deleteField(&tmp, "_id")
-			InsertMysqlSubjectData("zktest_dwd_f_ent_pa_baseinfo", tmp, tmpid)
+			tmpid := ul.BsonTOStringId(tmp["_id"])
+			website := qu.ObjToString(tmp["website"])
+			if len(website) > 200 {
+				tmp["website"] = ""
+			}
+			ul.DeleteField(&tmp, "_id")
+			ul.InsertMysqlSubjectData("dwd_f_ent_pa_baseinfo", tmp, tmpid)
 		}(tmp)
 		tmp = make(map[string]interface{})
 	}
-	wg_mgo.Wait()
+	ul.Wg_Mgo.Wait()
 	log.Debug("is over ... ")
 	time.Sleep(time.Second * 2)
 }

+ 10 - 31
data_ylqx/src/main.go

@@ -1,40 +1,19 @@
 package main
 
+import (
+	"util"
+)
+
 func init() {
-	IsLocal = true
-	initClass()
+	util.IsLocal = true
+	util.InitClass()
 }
 
 func main() {
-	//拆分合并产品与企业表
-	//splitMergeMedicalInfo("nmpa_ylqx_2022")
-	//splitMergeMedicalInfo("nmpa_ylqx_2023")
-
-	//经销商基本信息
-	//exportDealerBaseInfo()
-	//testDealerTag()
-	//经销商注册备案信息
-	//exportDealerRegisterInfo()
-	//testDealerRegisterTag()
-	//产品基本信息
-	//exportProductBaseInfo()
-	//exportHistoryProductBaseInfo()
-	//testProductBaseInfoTag()
-	//法人基本信息
-	//exportLegalBaseInfo()
-
-	//确认分类
-	//confirmYlqxInfoClass()
-
-	//临时邮件
-	//testInvestInfo()
-
-	//导入mysql-tidb数据
-	//importDealerBaseInfoTidb()
-	//importDealerRegisterInfoTidb()
-	//importProductBaseInfoTidb()
-	//importLegalBaseInfoTidb()
-	//importDealerScopeInfoTidb()
+	//product.StartDealWithProductBaseInfo()
+	//class.StartDealWithProductClassInfo()
+	//dealer.StartDealWithDealerAllInfo()
+	//legal.StartDealWithLegalBaseInfo()
 
 	//保持活性
 	lock := make(chan bool)

+ 271 - 0
data_ylqx/src/product/product.go

@@ -0,0 +1,271 @@
+package product
+
+import (
+	log "github.com/donnie4w/go-logger/logger"
+	qu "qfw/util"
+	"strings"
+	"time"
+	ul "util"
+)
+
+func StartDealWithProductBaseInfo() {
+	//exportMedicalProductBaseInfo()
+	//importMedicalProductBaseInfo()
+
+	//医疗产品,基本信息
+	//exportMedicalProductBaseInfo()
+	//testMedicalProductBaseInfoTag()
+	//importMedicalProductBaseInfoTidb()
+}
+
+//导出产品信息相关
+func exportMedicalProductBaseInfo() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_product_new").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%10000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			info := dealWithMedicalProductInfo(tmp)
+			ul.Save_Mgo.Save("nmpa_product_medical", info)
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	log.Debug("is over ...", total)
+	time.Sleep(time.Second * 2)
+
+}
+
+//医疗产品信息处理
+func dealWithMedicalProductInfo(tmp map[string]interface{}) map[string]interface{} {
+	info := map[string]interface{}{}
+	reg_company := qu.ObjToString(tmp["reg_company"])
+	company_id := ""
+	qyxyArr, _ := ul.Qyxy_Mgo.Find("qyxy_std", map[string]interface{}{
+		"company_name": reg_company,
+	}, nil, map[string]interface{}{
+		"use_flag": 1,
+	})
+	if len(qyxyArr) > 0 { //选取最优-企业信息
+		ind := ul.GetOneBaseCompany(qyxyArr)
+		qyxy := qyxyArr[ind]
+		company_id = qu.ObjToString(qyxy["_id"])
+	}
+	info["company_id"] = company_id
+	classify, reg_no := qu.ObjToString(tmp["classify"]), qu.ObjToString(tmp["reg_no"])
+	info["regno"] = reg_no
+	info["company_address"] = qu.ObjToString(tmp["reg_address"])
+	info["make_adress"] = qu.ObjToString(tmp["product_address"])
+	if strings.Contains(classify, "进口") || strings.Contains(reg_no, "国") {
+		info["make_country"] = 2
+	} else {
+		info["make_country"] = 1
+	}
+	info["agent_name"] = qu.ObjToString(tmp["agent_name"])
+	info["agent_address"] = qu.ObjToString(tmp["agent_address"])
+	info["model"] = qu.ObjToString(tmp["model"])
+	if strings.Contains(classify, "注册") || strings.Contains(reg_no, "注") {
+		info["main_part"] = qu.ObjToString(tmp["product_depict"])
+		info["main_part"] = ""
+		info["regist_type"] = 1
+	} else {
+		info["main_part"] = ""
+		info["product_descrip"] = qu.ObjToString(tmp["product_depict"])
+		info["regist_type"] = 2
+	}
+	info["use_scope "] = qu.ObjToString(tmp["application"])
+	info["storage_conditions"] = qu.ObjToString(tmp["conditions_use"])
+	info["remark "] = qu.ObjToString(tmp["remark"])
+	info["approve_depart"] = ul.Pickfirst(qu.ObjToString(tmp["spbm"]), qu.ObjToString(tmp["badw"]))
+	info["approve_date"] = ul.Pickfirst(qu.ObjToString(tmp["pzrq"]), qu.ObjToString(tmp["barq"]))
+	info["validity_date"] = qu.ObjToString(tmp["yxqz"])
+	info["changes"] = qu.ObjToString(tmp["changes"])
+	info["source_channel"] = classify
+	info["changes"] = qu.ObjToString(tmp["changes"])
+	if qu.ObjToString(tmp["class"]) == "第一类" {
+		info["manage_type"] = "Ⅰ"
+	} else if qu.ObjToString(tmp["class"]) == "第二类" {
+		info["manage_type"] = "Ⅱ"
+	} else {
+		info["manage_type"] = "Ⅲ"
+	}
+	info["isvalid"] = 1
+	//产品相关信息
+	info["product_name"] = qu.ObjToString(tmp["product_name"])
+	info["medical_equipment_class1"] = qu.ObjToString(tmp["product_class_1"])
+	info["medical_equipment_class2"] = qu.ObjToString(tmp["product_class_2"])
+	info["medical_equipment_class3"] = qu.ObjToString(tmp["product_class_3"])
+	info["sdproduct_name"] = qu.ObjToString(tmp["product_class_4"])
+	info["sdequipment_code"] = qu.ObjToString(tmp["product_class_code"])
+	return info
+}
+
+func testMedicalProductBaseInfoTag() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_product_medical").Find(&q).Sort("_id").Select(map[string]interface{}{
+		"regno": 1,
+	}).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%10000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			tmpid := ul.BsonTOStringId(tmp["_id"])
+			regno := qu.ObjToString(tmp["regno"])
+			info := ul.MysqlSubjectTool.FindOne("dwd_f_yl_product_baseinfo", map[string]interface{}{
+				"regno": regno,
+			}, "", "")
+			isAdd := 1
+			if info != nil {
+				isAdd = 0
+			}
+			ul.Save_Mgo.UpdateById("nmpa_product_medical", tmpid, map[string]interface{}{
+				"$set": map[string]interface{}{"isAdd": isAdd},
+			})
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ... ")
+	time.Sleep(time.Second * 2)
+}
+
+//导入tidb数据
+func importMedicalProductBaseInfoTidb() {
+
+	tmp := ul.Save_Mgo.FindById("nmpa_product_medical", "646da6143b085697b1647602")
+	tmpid := ul.BsonTOStringId(tmp["_id"])
+	ul.DeleteField(&tmp, "_id", "isAdd")
+	ul.InsertMysqlSubjectData("dwd_f_yl_product_baseinfo", tmp, tmpid)
+	return
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q, total := map[string]interface{}{}, 0
+	it := sess.DB(ul.Save_Mgo.DbName).C("nmpa_product_medical").Find(&q).Iter()
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%1000 == 0 {
+			log.Debug("curent index ", total)
+		}
+		if qu.IntAll(tmp["isAdd"]) == 1 {
+			ul.Pool_Mgo <- true
+			ul.Wg_Mgo.Add(1)
+			go func(tmp map[string]interface{}) {
+				defer func() {
+					<-ul.Pool_Mgo
+					ul.Wg_Mgo.Done()
+				}()
+				tmpid := ul.BsonTOStringId(tmp["_id"])
+				ul.DeleteField(&tmp, "_id", "isAdd")
+				ul.InsertMysqlSubjectData("dwd_f_yl_product_baseinfo", tmp, tmpid)
+			}(tmp)
+		}
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ... ")
+	time.Sleep(time.Second * 2)
+}
+
+//临时导入医疗产品基本信息
+func importMedicalProductBaseInfo() {
+	sess := ul.Save_Mgo.GetMgoConn()
+	defer ul.Save_Mgo.DestoryMongoConn(sess)
+	q := map[string]interface{}{}
+	it := sess.DB(ul.Save_Mgo.DbName).C("zktest_mysql_product_info").Find(&q).Sort("_id").Iter()
+	total := 0
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%1000 == 0 {
+			log.Debug("cur index ", total)
+		}
+		ul.Pool_Mgo <- true
+		ul.Wg_Mgo.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ul.Pool_Mgo
+				ul.Wg_Mgo.Done()
+			}()
+			dict := treatProductInfo(tmp)
+			tmpid := ul.BsonTOStringId(tmp["_id"])
+			ul.InsertMysqlSubjectData("dwd_f_yl_product_baseinfo", dict, tmpid)
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	ul.Wg_Mgo.Wait()
+	log.Debug("is over ", total)
+	time.Sleep(time.Second * 2)
+}
+
+//构建产品信息数据~
+func treatProductInfo(tmp map[string]interface{}) map[string]interface{} {
+	data := map[string]interface{}{}
+	data["regno"] = qu.ObjToString(tmp["regno"])
+	data["company_id"] = qu.ObjToString(tmp["company_id"])
+	data["company_address"] = qu.ObjToString(tmp["company_address"])
+	data["make_adress"] = qu.ObjToString(tmp["make_adress"])
+	//国产进口
+	data["make_country"] = qu.IntAll(tmp["make_country"])
+	data["agent_name"] = qu.ObjToString(tmp["agent_name"])
+	data["agent_address"] = qu.ObjToString(tmp["agent_address"])
+	data["model"] = qu.ObjToString(tmp["model"])
+	data["main_part"] = qu.ObjToString(tmp["main_part"])
+	data["product_descrip"] = qu.ObjToString(tmp["product_descrip"])
+	data["use_scope"] = qu.ObjToString(tmp["use_scope"])
+	data["storage_conditions"] = qu.ObjToString(tmp["storage_conditions"])
+	data["remark"] = qu.ObjToString(tmp["remark"])
+	data["approve_depart"] = qu.ObjToString(tmp["approve_depart"])
+
+	//日期清洗
+	approve_date := qu.ObjToString(tmp["approve_date"])
+	validity_date := qu.ObjToString(tmp["validity_date"])
+	if !cleanErrDateTime(approve_date) {
+		data["approve_date"] = approve_date
+	}
+	if !cleanErrDateTime(validity_date) {
+		data["validity_date"] = validity_date
+	}
+
+	data["changes"] = qu.ObjToString(tmp["changes"])
+	data["regist_type"] = qu.IntAll(tmp["regist_type"])
+
+	data["source_channel"] = qu.ObjToString(tmp["source_channel"])
+	data["manage_type"] = qu.ObjToString(tmp["manage_type"])
+	data["product_name"] = qu.ObjToString(tmp["product_name"])
+	data["medical_equipment_class1"] = qu.ObjToString(tmp["product_class1"])
+	data["medical_equipment_class2"] = qu.ObjToString(tmp["product_class2"])
+	data["medical_equipment_class3"] = qu.ObjToString(tmp["product_class3"])
+	data["sdproduct_name"] = qu.ObjToString(tmp["product_class4"])
+	data["medical_equipment_code"] = qu.ObjToString(tmp["product_code"])
+	data["isvalid"] = qu.IntAll(1)
+	data["createtime"] = time.Unix(time.Now().Unix(), 0).Format(ul.TimeLayout)
+
+	return data
+}
+
+//清洗日期~
+func cleanErrDateTime(datetime string) bool {
+	arr := strings.Split(datetime, "-")
+	if len(arr) > 0 {
+		year := qu.IntAll(arr[0])
+		if year < 1900 || year > 2200 {
+			return true
+		}
+	}
+	return false
+}

+ 4 - 3
data_ylqx/src/test.go → data_ylqx/src/test/test.go

@@ -1,4 +1,4 @@
-package main
+package test
 
 import (
 	"fmt"
@@ -6,6 +6,7 @@ import (
 	"github.com/tealeg/xlsx"
 	"os"
 	qu "qfw/util"
+	ul "util"
 )
 
 var sheet1, sheet2, sheet3 *xlsx.Sheet
@@ -13,7 +14,7 @@ var row1, row2, row3 *xlsx.Row
 var index2, index3 = 1, 1
 
 //父子级结构写表格-超链接
-func testInvestInfo() {
+func TestInvestInfo() {
 	os.Remove("1.xlsx")
 	f := xlsx.NewFile()
 	sheet1, _ = f.AddSheet("Sheet1")
@@ -38,7 +39,7 @@ func testInvestInfo() {
 }
 func testGetInvests(tmpid string, pre_name string, level int) bool {
 	q := map[string]interface{}{"stock_name_id": tmpid}
-	info, _ := Spi_Mgo.Find("company_partner", q, nil, nil)
+	info, _ := ul.Spi_Mgo.Find("company_partner", q, nil, nil)
 	var infos []map[string]interface{}
 	temp := map[string]string{}
 	for _, v := range info {

+ 437 - 0
data_ylqx/src/util/global.go

@@ -0,0 +1,437 @@
+package util
+
+import (
+	qu "qfw/util"
+	"regexp"
+)
+
+//产品分类使用
+var (
+	CodeRelation = map[string]string{
+		"06": "医用成像器械",
+		"01": "有源手术器械",
+		"02": "无源手术器械",
+		"14": "注输、护理和防护器械",
+		"16": "眼科器械",
+		"03": "神经和心血管手术器械",
+		"12": "有源植入器械",
+		"40": "体外诊断试剂",
+		"13": "无源植入器械",
+		"18": "妇产科、辅助生殖和避孕器械",
+		"17": "口腔科器械",
+		"22": "临床检验器械",
+		"07": "医用诊察和监护器械",
+		"04": "骨科手术器械",
+		"20": "中医器械",
+		"09": "物理治疗器械",
+		"08": "呼吸、麻醉和急救器械",
+		"19": "医用康复器械",
+		"21": "医用软件",
+		"10": "输血、透析和体外循环器械",
+		"11": "医疗器械消毒灭菌器械",
+		"15": "患者承载器械",
+		"05": "放射治疗器械",
+		"57": "医疗器械消毒灭菌器械",
+		"68": "体外诊断试剂",
+		"27": "中医器械",
+		"26": "物理治疗器械",
+		"46": "骨科手术器械",
+	}
+	RangeRelation = map[string]string{
+		"6801": "无源手术器械",
+		"6831": "X射线附属及辅助设备",
+		"6812": "妇产科、辅助生殖和避孕器械",
+		"6813": "妇产科手术器械",
+		"6810": "骨科手术器械",
+		"6824": "光治疗设备",
+		"6854": "呼吸、麻醉和急救器械",
+		"6856": "呼吸、麻醉和急救器械",
+		"6806": "口腔科器械",
+		"6855": "口腔科器械",
+		"6863": "口腔科器械",
+		"6840": "临床检验器械",
+		"6841": "临床检验器械",
+		"6803": "神经和心血管手术器械",
+		"6807": "神经和心血管手术器械",
+		"6877": "神经和心血管手术器械-心血管介入器械",
+		"6845": "输血、透析和体外循环器械",
+		"6805": "无源手术器械",
+		"6809": "无源手术器械",
+		"6808": "无源手术器械",
+		"6816": "无源手术器械",
+		"6846": "无源植入器械",
+		"6826": "物理治疗器械",
+		"6804": "眼科器械",
+		"6857": "医疗器械消毒灭菌器械",
+		"6822": "医用成像器械",
+		"6828": "医用成像器械",
+		"6833": "医用成像器械",
+		"6870": "医用软件",
+		"6834": "医用射线防护设备",
+		"6820": "医用诊察和监护器械",
+		"6821": "医用诊察和监护器械",
+		"6827": "中医器械",
+		"6815": "注射、穿刺器械",
+		"6864": "注输、护理和防护器械",
+	}
+	ProductTemp     = map[string]string{}
+	CompanyTemp     = map[string]string{}
+	YlqxCodeName    = map[string]string{}
+	YlqxNameCode    = map[string]string{}
+	LastProductInfo = map[string]map[string]string{}
+	ScRangeReg1     = regexp.MustCompile("(\\d{2}|\\d{4})-(\\d{2}|\\d{1})([\\s -::]+)?([\u4e00-\u9fa5()、()/\\s ]+)")
+	ScRangeReg2     = regexp.MustCompile("\\d{2}([\\s -::]+)?([\u4e00-\u9fa5()、()/\\s ]+)")
+	ScRangeClean1   = regexp.MustCompile("[\\s ]+")
+	ScRangeClean2   = regexp.MustCompile("(生产范围).*")
+	SpecRangeReg    = regexp.MustCompile("(检测试剂|试剂盒|抗体试剂|保存试剂|提取试剂)")
+	CleanPN0        = regexp.MustCompile("[ \\s]+")
+	CleanPN1        = regexp.MustCompile("[\u30A0-\u30FF]+")
+	CleanPN2        = regexp.MustCompile("([A-Za-z]+)$")
+	CleanPN3        = regexp.MustCompile("[()()]+")
+	CleanPN4        = regexp.MustCompile("^([0-9]+)")
+)
+
+//经营能力使用
+var (
+	JyRangeReg1   = regexp.MustCompile("(6\\d{3})([\\s ]+)?[\u4e00-\u9fa5]+")
+	JyRangeReg2   = regexp.MustCompile("[0-2]\\d{1}([\u4e00-\u9fa5()()、]+)")
+	JyRangeReg3   = regexp.MustCompile("(6\\d{3})([((].*[))])?[,,、\\*::]")
+	JyRangeReg4   = regexp.MustCompile("[,,、\\*::]([0-2]\\d{1})[,,、\\*::]")
+	JyRangeReg5   = regexp.MustCompile("[0-2]\\d{1}[-]([\u4e00-\u9fa5()()、]+)")
+	JyRangeReg6   = regexp.MustCompile("([0-2]\\d{1}[-]\\d{2})")
+	JyRangeReg7   = regexp.MustCompile("分类目录[::](6\\d{3})")
+	JyRangeReg8   = regexp.MustCompile("分类目录[::][0-2]\\d{1}")
+	JyRangeReg9   = regexp.MustCompile("类[::]([0-2]\\d{1}[-]\\d{2})")
+	JySpecReg1    = regexp.MustCompile("6840([\u4e00-\u9fa5()()、-]+)")
+	JyExcludeReg1 = regexp.MustCompile("(除外|不含)")
+	JyCodeA       = map[string]string{
+		"6801": "02",
+		"6831": "0605",
+		"6812": "18",
+		"6813": "1801",
+		"6810": "04",
+		"6824": "0903",
+		"6854": "08",
+		"6856": "08",
+		"6806": "17",
+		"6855": "17",
+		"6863": "17",
+		"6841": "22",
+		"6803": "03",
+		"6807": "03",
+		"6877": "0313",
+		"6845": "10",
+		"6805": "02",
+		"6809": "02",
+		"6808": "02",
+		"6816": "02",
+		"6846": "13",
+		"6826": "09",
+		"6804": "16",
+		"6857": "11",
+		"6822": "06",
+		"6828": "06",
+		"6833": "06",
+		"6870": "21",
+		"6834": "0606",
+		"6820": "07",
+		"6821": "07",
+		"6827": "20",
+		"6815": "1401",
+		"6864": "14",
+	}
+	JyCodeB = map[string]string{
+		"01": "01",
+		"02": "02",
+		"03": "03",
+		"04": "04",
+		"05": "05",
+		"06": "06",
+		"07": "07",
+		"08": "08",
+		"09": "09",
+		"10": "10",
+		"11": "11",
+		"12": "12",
+		"13": "13",
+		"14": "14",
+		"15": "15",
+		"16": "16",
+		"17": "17",
+		"18": "18",
+		"19": "19",
+		"20": "20",
+		"21": "21",
+		"22": "22",
+	}
+	JyCodeC = map[string]string{
+		"01-01": "0101",
+		"01-02": "0102",
+		"01-03": "0103",
+		"01-04": "0104",
+		"01-05": "0105",
+		"01-06": "0106",
+		"01-07": "0107",
+		"01-08": "0108",
+		"01-09": "0109",
+		"01-10": "0110",
+		"02-01": "0201",
+		"02-02": "0202",
+		"02-03": "0203",
+		"02-04": "0204",
+		"02-05": "0205",
+		"02-06": "0206",
+		"02-07": "0207",
+		"02-08": "0208",
+		"02-09": "0209",
+		"02-10": "0210",
+		"02-11": "0211",
+		"02-12": "0212",
+		"02-13": "0213",
+		"02-14": "0214",
+		"02-15": "0215",
+		"03-01": "0301",
+		"03-02": "0302",
+		"03-03": "0303",
+		"03-04": "0304",
+		"03-05": "0305",
+		"03-06": "0306",
+		"03-07": "0307",
+		"03-08": "0308",
+		"03-09": "0309",
+		"03-10": "0310",
+		"03-11": "0311",
+		"03-12": "0312",
+		"03-13": "0313",
+		"03-14": "0314",
+		"04-01": "0401",
+		"04-02": "0402",
+		"04-03": "0403",
+		"04-04": "0404",
+		"04-05": "0405",
+		"04-06": "0406",
+		"04-07": "0407",
+		"04-08": "0408",
+		"04-09": "0409",
+		"04-10": "0410",
+		"04-11": "0411",
+		"04-12": "0412",
+		"04-13": "0413",
+		"04-14": "0414",
+		"04-15": "0415",
+		"04-16": "0416",
+		"04-17": "0417",
+		"04-18": "0418",
+		"05-01": "0501",
+		"05-02": "0502",
+		"05-03": "0503",
+		"05-04": "0504",
+		"06-01": "0601",
+		"06-02": "0602",
+		"06-03": "0603",
+		"06-04": "0604",
+		"06-05": "0605",
+		"06-06": "0606",
+		"06-07": "0607",
+		"06-08": "0608",
+		"06-09": "0609",
+		"06-10": "0610",
+		"06-11": "0611",
+		"06-12": "0612",
+		"06-13": "0613",
+		"06-14": "0614",
+		"06-15": "0615",
+		"06-16": "0616",
+		"06-17": "0617",
+		"06-18": "0618",
+		"07-01": "0701",
+		"07-02": "0702",
+		"07-03": "0703",
+		"07-04": "0704",
+		"07-05": "0705",
+		"07-06": "0706",
+		"07-07": "0707",
+		"07-08": "0708",
+		"07-09": "0709",
+		"07-10": "0710",
+		"08-01": "0801",
+		"08-02": "0802",
+		"08-03": "0803",
+		"08-04": "0804",
+		"08-05": "0805",
+		"08-06": "0806",
+		"08-07": "0807",
+		"09-01": "0901",
+		"09-02": "0902",
+		"09-03": "0903",
+		"09-04": "0904",
+		"09-05": "0905",
+		"09-06": "0906",
+		"09-07": "0907",
+		"09-08": "0908",
+		"10-01": "1001",
+		"10-02": "1002",
+		"10-03": "1003",
+		"10-04": "1004",
+		"10-05": "1005",
+		"10-06": "1006",
+		"10-07": "1007",
+		"11-01": "1101",
+		"11-02": "1102",
+		"11-03": "1103",
+		"11-04": "1104",
+		"11-05": "1105",
+		"12-01": "1201",
+		"12-02": "1202",
+		"12-03": "1203",
+		"12-04": "1204",
+		"13-01": "1301",
+		"13-02": "1302",
+		"13-03": "1303",
+		"13-04": "1304",
+		"13-05": "1305",
+		"13-06": "1306",
+		"13-07": "1307",
+		"13-08": "1308",
+		"13-09": "1309",
+		"13-10": "1310",
+		"13-11": "1311",
+		"14-01": "1401",
+		"14-02": "1402",
+		"14-03": "1403",
+		"14-04": "1404",
+		"14-05": "1405",
+		"14-06": "1406",
+		"14-07": "1407",
+		"14-08": "1408",
+		"14-09": "1409",
+		"14-10": "1410",
+		"14-11": "1411",
+		"14-12": "1412",
+		"14-13": "1413",
+		"14-14": "1414",
+		"14-15": "1415",
+		"14-16": "1416",
+		"15-01": "1501",
+		"15-02": "1502",
+		"15-03": "1503",
+		"15-04": "1504",
+		"15-05": "1505",
+		"15-06": "1506",
+		"16-01": "1601",
+		"16-02": "1602",
+		"16-03": "1603",
+		"16-04": "1604",
+		"16-05": "1605",
+		"16-06": "1606",
+		"16-07": "1607",
+		"17-01": "1701",
+		"17-02": "1702",
+		"17-03": "1703",
+		"17-04": "1704",
+		"17-05": "1705",
+		"17-06": "1706",
+		"17-07": "1707",
+		"17-08": "1708",
+		"17-09": "1709",
+		"17-10": "1710",
+		"18-01": "1801",
+		"18-02": "1802",
+		"18-03": "1803",
+		"18-04": "1804",
+		"18-05": "1805",
+		"18-06": "1806",
+		"18-07": "1807",
+		"19-01": "1901",
+		"19-02": "1902",
+		"19-03": "1903",
+		"19-04": "1904",
+		"20-01": "2001",
+		"20-02": "2002",
+		"20-03": "2003",
+		"21-01": "2101",
+		"21-02": "2102",
+		"21-03": "2103",
+		"21-04": "2104",
+		"21-05": "2105",
+		"21-06": "2106",
+		"22-01": "2201",
+		"22-02": "2202",
+		"22-03": "2203",
+		"22-04": "2204",
+		"22-05": "2205",
+		"22-06": "2206",
+		"22-07": "2207",
+		"22-08": "2208",
+		"22-09": "2209",
+		"22-10": "2210",
+		"22-11": "2211",
+		"22-12": "2212",
+		"22-13": "2213",
+		"22-14": "2214",
+		"22-15": "2215",
+		"22-16": "2216",
+	}
+)
+
+//获取最优企业
+func GetOneBaseCompany(arr []map[string]interface{}) int {
+	index := 0
+	flag := 100
+	if len(arr) > 1 {
+		for k, tmp := range arr {
+			use_flag := qu.IntAll(tmp["use_flag"])
+			if use_flag == 0 {
+				index = k
+				break
+			} else {
+				if use_flag < flag {
+					flag = use_flag
+					index = k
+				}
+			}
+		}
+	}
+	return index
+}
+
+//处理地域代码
+func DealWithRegionCode(area string, city string, district string) (area_code string, city_code string, district_code string) {
+	area_code, city_code, district_code = "000000", "", ""
+	if district != "" {
+		key := area + "~" + city + "~" + district + "~"
+		code := RegionCodeData[key]
+		if code != "" {
+			district_code = code
+			city_code = code[:4] + "00"
+			area_code = code[:2] + "0000"
+			return
+		}
+	}
+	if city != "" {
+		key := area + "~" + city + "~" + "" + "~"
+		code := RegionCodeData[key]
+		if code != "" {
+			city_code = code
+			area_code = city_code[:2] + "0000"
+			return
+		}
+	}
+	if area != "" {
+		key := area + "~" + "" + "~" + "" + "~"
+		code := RegionCodeData[key]
+		if code != "" {
+			area_code = code
+			return
+		}
+	}
+	return
+}
+
+//选取有效数据
+func Pickfirst(s1 string, s2 string) string {
+	if s1 != "" {
+		return s1
+	}
+	return s2
+}

+ 24 - 7
data_ylqx/src/init.go → data_ylqx/src/util/init.go

@@ -1,4 +1,4 @@
-package main
+package util
 
 import (
 	log "github.com/donnie4w/go-logger/logger"
@@ -16,10 +16,10 @@ var (
 	TimeTmeplate                                        = "2006-01-02"
 	RegionCodeData                                      = map[string]string{}
 )
-var pool_mgo = make(chan bool, 10)
-var wg_mgo = &sync.WaitGroup{}
+var Pool_Mgo = make(chan bool, 10)
+var Wg_Mgo = &sync.WaitGroup{}
 
-func initClass() {
+func InitClass() {
 	initMgo()
 	initMysql()
 	initCode()
@@ -111,7 +111,6 @@ func initMgo() {
 		Qyxy_Mgo.InitPool()
 	}
 }
-
 func initMysql() {
 	username, password := "zhengkun", "Zk#20220824"
 	address := "127.0.0.1:15001"
@@ -143,8 +142,12 @@ func initMysql() {
 	MysqlSubjectTool.Init()
 
 }
-
 func initCode() {
+	loadRegionsInfo()
+	loadYlqxInfo()
+}
+
+func loadRegionsInfo() {
 	data_regions := MysqlGlobalTool.Find("code_area", nil, "", "", -1, -1)
 	//先构建所有一级数据
 	for _, v := range *data_regions {
@@ -158,6 +161,20 @@ func initCode() {
 	log.Debug("地域信息数量~", len(RegionCodeData))
 }
 
+//加载医疗器械代码
+func loadYlqxInfo() {
+	ylqxs := *MysqlMedicalTool.Find("code_productclass", nil, "", "", -1, -1)
+	for _, v := range ylqxs {
+		name := qu.ObjToString(v["name"])
+		code := qu.ObjToString(v["code"])
+		if name != "" && code != "" {
+			YlqxCodeName[code] = name
+			YlqxNameCode[name] = code
+		}
+	}
+	log.Debug("产品数量~", len(YlqxCodeName))
+}
+
 //插入数据
 func InsertMysqlGlobalData(name string, data map[string]interface{}, mark string) int64 {
 	inb := MysqlGlobalTool.Insert(name, data)
@@ -186,7 +203,7 @@ func InsertMysqlMedicalData(name string, data map[string]interface{}, mark strin
 }
 
 //删除字段
-func deleteField(data *map[string]interface{}, fieldArr ...string) {
+func DeleteField(data *map[string]interface{}, fieldArr ...string) {
 	//针对时间类进行清理
 	dateFields := []string{"validity_date", "approve_date", "establish_date", "issue_date", "cancel_date", "revoke_date"}
 	for _, v := range dateFields {

+ 1 - 1
data_ylqx/src/mgo.go → data_ylqx/src/util/mgo.go

@@ -1,4 +1,4 @@
-package main
+package util
 
 import (
 	"context"

+ 6 - 2
data_ylqx/src/mysql.go → data_ylqx/src/util/mysql.go

@@ -1,4 +1,4 @@
-package main
+package util
 
 import (
 	"bytes"
@@ -199,6 +199,10 @@ func (m *Mysql) Find(tableName string, query map[string]interface{}, fields, ord
 						}
 					}
 				}
+				if rv_k.String() == "gte" {
+					fs = append(fs, fmt.Sprintf("%s>=?", k))
+					vs = append(vs, rv.MapIndex(rv_k).Interface())
+				}
 				if rv_k.String() == "in" {
 					if len(rv.MapIndex(rv_k).Interface().([]interface{})) > 0 {
 						_fs := fmt.Sprintf("%s in (?", k)
@@ -367,7 +371,7 @@ func (m *Mysql) DeleteByTx(tx *sql.Tx, tableName string, query map[string]interf
 		values = append(values, v)
 	}
 	q := fmt.Sprintf("delete from %s where %s", tableName, strings.Join(fields, " and "))
-	log.Println(q, values)
+	//log.Println(q, values)
 	return m.UpdateOrDeleteBySqlByTx(tx, q, values...) > 0
 }