Browse Source

备份 文件

zhengkun 3 years ago
parent
commit
f85408944c

+ 2 - 1
process_ medical/src/config.json

@@ -23,7 +23,8 @@
     "password": "top@123"
   },
   "data_source": {
-    "s_xlsx_name": "table.xlsx",
+    "s_class_xlsx_name": "table.xlsx",
+    "s_area_xlsx_name": "xzqh.xlsx",
     "s_area_coll": "address_jy_2021",
     "s_product_coll": "nmpa_product",
     "s_company_coll": "nmpa_company",

+ 2 - 2
process_ medical/src/init_config.go

@@ -4,9 +4,9 @@ import qu "qfw/util"
 
 func initConfig()  {
 	initMgo()
-
 	souceconf:= sysconfig["data_source"].(map[string]interface{})
-	s_xlsx_name = qu.ObjToString(souceconf["s_xlsx_name"])
+	s_class_xlsx_name = qu.ObjToString(souceconf["s_class_xlsx_name"])
+	s_area_xlsx_name = qu.ObjToString(souceconf["s_area_xlsx_name"])
 	s_area_coll = qu.ObjToString(souceconf["s_area_coll"])
 	s_product_coll = qu.ObjToString(souceconf["s_product_coll"])
 	s_company_coll = qu.ObjToString(souceconf["s_company_coll"])

+ 12 - 4
process_ medical/src/main.go

@@ -9,11 +9,13 @@ var (
 	sysconfig    		map[string]interface{} //配置文件
 	save_mgo,qy_mgo,spi_mgo     *MongodbSim            //mongodb操作对象
     MysqlTool			*Mysql
-	s_xlsx_name,s_area_coll,s_product_coll,s_company_coll,s_qybase_coll			string
+	s_area_coll,s_product_coll,s_company_coll,s_qybase_coll			string
 	o_area_coll,o_class_coll	string
+	s_class_xlsx_name,s_area_xlsx_name	string
+
 )
 
-var timeReg = regexp.MustCompile(`^(\d{4}-\d{2}-\d{2})$`)
+var timeReg = regexp.MustCompile(`^(\d{4}-[0-1][0-9]-[0-3][0-9])$`)
 var timeReg1 = regexp.MustCompile(`^(\d{4}-\d{1,2}-\d{1,2})$`)
 var Url = "https://www.jianyu360.com/article/content/%s.html"
 var bidclass_dict = map[string]string{}
@@ -30,12 +32,18 @@ func init()  {
 
 
 func main()  {
+	//生产-经营企业信息
+	exportCompanyMysql()
+
+
 
 
+	//备案信息
+	//exportForReferenceMysql()
 
 	//v-表
-	//exportAreaCitysMgo()
-	//exportMedicalClassMgo()
+	//exportAreaCitysMysql()
+	//exportMedicalClassMysql()
 }
 
 

+ 55 - 44
process_ medical/src/medical_company.go

@@ -39,7 +39,7 @@ var fieldArr = []string{
 	"list_code",
 }
 
-func companySaveMysql()  {
+func saveCompanyMysql()  {
 	sess := save_mgo.GetMgoConn()
 	defer save_mgo.DestoryMongoConn(sess)
 	q,total:=map[string]interface{}{},0
@@ -58,36 +58,39 @@ func companySaveMysql()  {
 
 
 //关联企业信息-升数据
-func dealWithCompanyData()  {
-	sess := save_mgo.GetMgoConn()
-	defer save_mgo.DestoryMongoConn(sess)
-	q,total:=map[string]interface{}{},0
-	isok:=0
-	it := sess.DB(save_mgo.DbName).C("zktest_nmpa_cpmpany").Find(&q).Iter()
-	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
-		if total%10000==0 {
-			log.Debug("curent index ",total,isok)
+func exportCompanyMysql()  {
+	dataArr := repeatCompanyNamedata()
+	for index,tmp := range dataArr{
+		if index%10000==0 {
+			log.Debug("curent index ",index)
 		}
-		company:= qu.ObjToString(tmp["name"])
-		type_str := qu.ObjToString(tmp["type"])
-		dataArr,_ :=spi_mgo.Find("company_base", map[string]interface{}{
-			"company_name":company,
-		},nil,nil)
-
-		for _,v := range dataArr {
-			isok++
-			data := updateData(v,type_str)
-			if len(data)>2 && data!=nil {
-				save_mgo.Save("zktest_mysql_company_info",data)
+		for company,_ := range tmp{
+			arr,_ :=spi_mgo.Find(s_qybase_coll, map[string]interface{}{
+				"company_name":company,
+			},nil,nil)
+			//选取最优-企业信息
+			if len(dataArr)>0 {
+				getOneBaseCompany(arr)
+			}else {
+				//记录企业---
 			}
 		}
-		tmp = make(map[string]interface{})
+	}
+}
+
+
+
+func getOneBaseCompany(arr []map[string]interface{}) map[string]interface{} {
+	data := map[string]interface{}{}
+	if len(arr)==1 {
+		return arr[0]
 	}
 
-	log.Debug("is over ",total,isok)
+	return data
 }
 
 
+
 func updateData(tmp map[string]interface{},type_str string) map[string]interface{} {
 	update := map[string]interface{}{}
 	for _,v := range fieldArr{
@@ -95,7 +98,6 @@ func updateData(tmp map[string]interface{},type_str string) map[string]interface
 			update[v] = tmp[v]
 		}
 	}
-
 	company_id := qu.ObjToString(update["company_id"])
 	if company_id=="" {
 		return map[string]interface{}{}
@@ -126,24 +128,19 @@ func updateData(tmp map[string]interface{},type_str string) map[string]interface
 	return update
 }
 
-
-
-
-
-
-
-
-
 //已结束
-func exportCompany()  {
-	dict := map[string]string{}
+func repeatCompanyNamedata() []map[string]string {
 	sess := save_mgo.GetMgoConn()
 	defer save_mgo.DestoryMongoConn(sess)
-	q,total:=map[string]interface{}{},0
-	isok:=0
-	it := sess.DB(save_mgo.DbName).C("nmpa_company").Find(&q).Iter()
+	q,total,isok:=map[string]interface{}{},0,0
+	dict := map[string]string{}
+	company_arr := []string{}
+	it := sess.DB(save_mgo.DbName).C(s_company_coll).Find(&q).Select(map[string]interface{}{
+		"company":1,
+		"class":1,
+	}).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
-		if total%10000==0 {
+		if total%100000==0 {
 			log.Debug("curent index ",total,isok)
 		}
 		company:= qu.ObjToString(tmp["company"])
@@ -152,6 +149,7 @@ func exportCompany()  {
 			if dict[company]=="" {
 				isok++
 				dict[company] = class
+				company_arr = append(company_arr,company)
 			}else {
 				pre_class := dict[company]
 				if pre_class!=class && !strings.Contains(pre_class,"&") {
@@ -161,14 +159,27 @@ func exportCompany()  {
 		}
 		tmp = make(map[string]interface{})
 	}
-	log.Debug("is over ",total,isok)
-
-	for k,v := range dict {
-		save_mgo.Save("zktest_nmpa_cpmpany", map[string]interface{}{
-			"name":k,
-			"type":v,
+	new_arr := []map[string]string{}
+	for _,v := range company_arr{
+		type_str :=""
+		str := dict[v]
+		if strings.Contains(str,"&") {
+			type_str = "3"
+		}else {
+			if strings.Contains(str,"生产") {
+				type_str= "1"
+			}else if strings.Contains(str,"经营") {
+				type_str = "2"
+			}else {
+				type_str = "4"
+			}
+		}
+		new_arr = append(new_arr, map[string]string{
+			v:type_str,
 		})
 	}
+	log.Debug("is repeat company over ",total,isok,len(new_arr))
+	return new_arr
 }
 
 

+ 0 - 4
process_ medical/src/medical_prepare.go

@@ -31,10 +31,6 @@ func init_bidclass() {
 		code := qu.ObjToString(v["code"])
 		if level=="1" {
 			pre_str = name
-			if name=="采购意向" {
-				key := pre_str+"_"
-				bidclass_dict[key] = code
-			}
 		}else {
 			key := pre_str+"_"+name
 			bidclass_dict[key] = code

+ 28 - 14
process_ medical/src/medical_for_reference.go → process_ medical/src/medical_reference.go

@@ -9,32 +9,34 @@ import (
 
 
 //企业许可备案信息
-func forReference()  {
+func exportForReferenceMysql()  {
 	sess := save_mgo.GetMgoConn()
 	defer save_mgo.DestoryMongoConn(sess)
 	q,total:=map[string]interface{}{},0
 	ok1,ok2:=0,0
-	it := sess.DB(save_mgo.DbName).C("nmpa_company").Find(&q).Iter()
+	it := sess.DB(save_mgo.DbName).C(s_company_coll).Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
 		if total%10000==0 {
 			log.Debug("curent index ",total,ok1,ok2)
 		}
 		class := qu.ObjToString(tmp["class"])
-		if class=="生产型"{
-			ok1++
-			data := dealWithSCX(tmp)
-			MysqlTool.Insert("f_production_register",data)
-		}else if class=="经营型" {
-			ok2++
-			data := dealWithJYX(tmp)
-			MysqlTool.Insert("f_business_register",data)
-		}else {
+		company := qu.ObjToString(tmp["company"])
+		if company!="" {
+			if class=="生产型"{
+				ok1++
+				data := dealWithSCX(tmp)
+				MysqlTool.Insert("f_production_register",data)
+			}else if class=="经营型" {
+				ok2++
+				data := dealWithJYX(tmp)
+				MysqlTool.Insert("f_business_register",data)
+			}else {
 
+			}
 		}
-
 		tmp = make(map[string]interface{})
 	}
-	log.Debug("is over ",total,ok1,ok2)
+	log.Debug("is reference over ",total,ok1,ok2)
 }
 
 //处理生产型
@@ -79,7 +81,19 @@ func dealWithJYX (tmp map[string]interface{}) map[string]interface{}{
 	data["type"] = type_str
 	data["address"] = qu.ObjToString(tmp["business_address"])
 	data["scope"] = qu.ObjToString(tmp["business_range"])
-	data["business_type"] = qu.ObjToString(tmp["business_mode"])
+
+	business_mode := qu.ObjToString(tmp["business_mode"])
+	if strings.Contains(business_mode,"批零") ||
+		(strings.Contains(business_mode,"批发") && strings.Contains(business_mode,"零售") ){
+		data["business_type"] = "3"
+	}else if strings.Contains(business_mode,"批发") {
+		data["business_type"] = "1"
+	}else if strings.Contains(business_mode,"零售") {
+		data["business_type"] = "2"
+	}else {
+		data["business_type"] = "4"
+	}
+
 	data["approve_depart"] = qu.ObjToString(tmp["badw"])
 	data["website_name"] = ""
 	data["website"] = ""

+ 66 - 9
process_ medical/src/medical_vdata.go

@@ -53,8 +53,36 @@ func saveAreaMysql() {
 
 
 //城市划分-mgo
-func exportAreaCitysMgo() {
+func exportAreaCitysMysql() {
 	log.Debug("开始处理-区域划分")
+
+	xzqh_data := map[string]map[string]string{}
+	//准备数据
+	ff,_ := xlsx.OpenFile(s_area_xlsx_name)
+	for _, sheet := range ff.Sheets {
+		for k, row := range sheet.Rows {
+			if k==0 {
+				continue
+			}
+			var arr []string
+			for k1, cell := range row.Cells {
+				if k1==3||k1==4 {
+					num ,_:= cell.Float()
+					arr = append(arr, fmt.Sprintf("%.6f",num))
+				}else {
+					arr = append(arr, cell.String())
+				}
+			}
+			code := arr[0]
+			xzqh_data[code] = map[string]string{
+				"region":arr[1],
+				"longitude":arr[3],
+				"latitude":arr[4],
+			}
+		}
+		log.Debug(len(xzqh_data))
+	}
+
 	sess := qy_mgo.GetMgoConn()
 	defer qy_mgo.DestoryMongoConn(sess)
 	q,total:=map[string]interface{}{
@@ -62,49 +90,78 @@ func exportAreaCitysMgo() {
 			"$exists":0,
 		},
 	},0
+	iserr :=0
 	it := sess.DB(qy_mgo.DbName).C(s_area_coll).Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
 		province:=qu.ObjToString(tmp["province"])
 		city:=qu.ObjToString(tmp["city"])
 		district:=qu.ObjToString(tmp["district"])
-		province_code := fmt.Sprintf("%d",tmp["province_code"])
-		city_code:= fmt.Sprintf("%d",tmp["city_code"])
+		province_code := fmt.Sprintf("%d0000",tmp["province_code"])
+		city_code:= fmt.Sprintf("%d00",tmp["city_code"])
 		district_code:=fmt.Sprintf("%d",tmp["district_code"])
+		info := map[string]string{}
 		data := map[string]interface{}{}
 		if district =="" {
 			if city=="" {
+				info = xzqh_data[province_code]
 				data = map[string]interface{}{
 					"name":province,
 					"code":province_code,
-					"pcode":"",
 					"level":"1",
+					"region":qu.ObjToString(info["region"]),
+					"longitude":qu.ObjToString(info["longitude"]),
+					"latitude":qu.ObjToString(info["latitude"]),
 				}
 			}else {
+				info = xzqh_data[city_code]
 				data = map[string]interface{}{
 					"name":city,
 					"code":city_code,
-					"pcode":province_code,
 					"level":"2",
+					"p_name":province,
+					"p_code":province_code,
+					"region":qu.ObjToString(info["region"]),
+					"longitude":qu.ObjToString(info["longitude"]),
+					"latitude":qu.ObjToString(info["latitude"]),
 				}
 			}
 		}else {
+			info = xzqh_data[district_code]
 			data = map[string]interface{}{
 				"name":district,
 				"code":district_code,
-				"pcode":city_code,
 				"level":"3",
+				"p_name":province,
+				"p_code":province_code,
+				"c_name":city,
+				"c_code":city_code,
+				"region":qu.ObjToString(info["region"]),
+				"longitude":qu.ObjToString(info["longitude"]),
+				"latitude":qu.ObjToString(info["latitude"]),
 			}
 		}
 		save_mgo.Save(o_area_coll,data)
+
+		if len(info)==0 {
+			iserr++
+		}
 		tmp = make(map[string]interface{})
 	}
-	log.Debug("is area over ",total)
+	log.Debug("is area over ",total,iserr)
+
+
 }
 
+
+
+
+
+
+
 //医疗分类-mgo
-func exportMedicalClassMgo() {
+func exportMedicalClassMysql() {
 	log.Debug("开始处理-医疗分类")
-	ff,_ := xlsx.OpenFile(s_xlsx_name)
+	ff,_ := xlsx.OpenFile(s_class_xlsx_name)
 	spaceReg := regexp.MustCompile(`([ \n]+)`)
 	proReg := regexp.MustCompile(`(^[0-9][0-9])`)
 	for index, sheet := range ff.Sheets {

BIN
process_ medical/src/xzqh.xlsx