瀏覽代碼

数据准备~ 备份

zhengkun 3 年之前
父節點
當前提交
1a092b06ab

+ 222 - 0
filedproject_medical/data_preparation/src/bidinfo/bidinfo.go

@@ -0,0 +1,222 @@
+package bidinfo
+
+import (
+	"class"
+	"fmt"
+	log "github.com/donnie4w/go-logger/logger"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+	qu "qfw/util"
+	"strings"
+	"sync"
+	"unicode/utf8"
+)
+
+var bidlock sync.Mutex
+
+//标的物信息
+func RunBidBsaeInfoData() {
+	log.Debug("开始处理~~标讯信息~~")
+	dealWithBidInfo()
+}
+
+//处理标讯信息~
+func dealWithBidInfo() {
+	//来源mgo~181
+	sess := class.Save_Mgo.GetMgoConn()
+	defer class.Save_Mgo.DestoryMongoConn(sess)
+	q := map[string]interface{}{}
+	it := sess.DB(class.Save_Mgo.DbName).C("zktest_mysql_bidding").Find(&q).Sort("_id").Select(map[string]interface{}{
+		"toptype":           1,
+		"subtype":           1,
+		"subscopeclass":     1,
+		"repeat":            1,
+		"yl_purchasinglist": 1,
+	}).Iter()
+	pool := make(chan bool, 1)
+	wg := &sync.WaitGroup{}
+	total := 0
+	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
+		if total%1000 == 0 {
+			log.Debug("cur index ", total)
+		}
+		if qu.IntAll(tmp["repeat"]) == 1 {
+			tmp = make(map[string]interface{})
+			continue
+		}
+
+		pool <- true
+		wg.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-pool
+				wg.Done()
+			}()
+
+			createBaseInfo(tmp)
+
+		}(tmp)
+		tmp = make(map[string]interface{})
+	}
+	wg.Wait()
+
+	log.Debug("is over ", total)
+}
+
+//构建标的物基本信息
+func createBaseInfo(tmp map[string]interface{}) {
+	p_list := isMarkInterfaceMap(tmp["yl_purchasinglist"])
+	sub_list := isMarkInterfaceArr(tmp["subscopeclass"])
+	infoid := class.BsonTOStringId(tmp["_id"])
+	bid_topsubtype_code := confrimTopSubCode(qu.ObjToString(tmp["toptype"]), qu.ObjToString(tmp["subtype"]))
+	b, industry_code, new_plist := checkWhetherValidInfo(p_list, sub_list)
+	if b {
+		//标的物基本信息~记录标签
+		insertBaseInfo(new_plist, infoid, bid_topsubtype_code)
+		//招标信息领域标签
+		insertFiledTag(infoid)
+		//招标信息行业标签
+		insertIndustryTag(industry_code, infoid)
+	}
+
+}
+
+//return 是否有效~行业代码~新标的物信息
+func checkWhetherValidInfo(p_list []map[string]interface{}, sub_list []string) (bool, string, []map[string]interface{}) {
+	is_exists := false
+	industry_code, b := isIndustryInfo(sub_list)
+	new_plist := []map[string]interface{}{}
+	if len(p_list) > 0 && b {
+		is_exists, new_plist = createNewPurchasingInfo(p_list)
+	}
+	return is_exists, industry_code, new_plist
+}
+
+//返回新的~标的物信息(分类+整合)
+func createNewPurchasingInfo(p_list []map[string]interface{}) (bool, []map[string]interface{}) {
+	is_exists := false
+	new_plist := []map[string]interface{}{}
+	for _, v := range p_list {
+		data := map[string]interface{}{}
+		itemname := qu.ObjToString(v["itemname"])
+		if itemname == "" {
+			continue
+		}
+		//根据标的物名字~打上具体的分类数据~默认均有
+		is_yl, yl_code := confrimYlClassCode(v)
+		if !is_exists && is_yl {
+			is_exists = true //证明此条信息有效果
+		}
+		data["medical_equipment_code"] = yl_code
+		data["itemname"] = itemname
+		data["brand"] = qu.ObjToString(v["brandname"])
+		model := qu.ObjToString(v["model"])
+		if utf8.RuneCountInString(model) > 100 {
+			model = ""
+		}
+		data["model"] = model
+		data["specs"] = qu.ObjToString(v["specs"])
+
+		if v["unitname"] != nil {
+			data["unit"] = qu.ObjToString(v["unitname"])
+		}
+		if v["number"] != nil {
+			num := qu.IntAll(v["number"])
+			if num < 100000000 {
+				data["num"] = num
+			}
+		}
+		if v["unitprice"] != nil {
+			if qu.Float64All(v["unitprice"]) < 100000000.0 {
+				data["price"] = qu.Float64All(v["unitprice"])
+			}
+		}
+		if v["totalprice"] != nil {
+			if qu.Float64All(v["totalprice"]) < 1000000000.0 {
+				data["totalprice"] = qu.Float64All(v["totalprice"])
+			}
+		}
+		new_plist = append(new_plist, data)
+	}
+	return is_exists, new_plist
+}
+
+//是否为医疗行业数据
+func isIndustryInfo(sub_list []string) (string, bool) {
+	code := ""
+	b := false
+	for _, v := range sub_list {
+		arr := strings.Split(v, "_")
+		if len(arr) == 2 {
+			industry_1 := arr[0]
+			industry_2 := arr[1]
+			if industry_1 == "医疗卫生" && (industry_2 == "设备" || industry_2 == "耗材") {
+				b = true
+				code = class.Bid_Industry[industry_1][industry_2]
+				break
+			}
+		}
+	}
+	return code, b
+}
+
+//根据标的物名称~打医疗分类
+func confrimYlClassCode(v map[string]interface{}) (bool, string) {
+	is_b := false
+	yl_code := ""
+	//临时采用已分好的数据的
+	product_name := qu.ObjToString(v["product_name"])
+	product_class_1 := qu.ObjToString(v["product_class_1"])
+	product_class_2 := qu.ObjToString(v["product_class_2"])
+	product_class_3 := qu.ObjToString(v["product_class_3"])
+	key_4 := "四级_" + product_name
+	if class.Medical_Class_Name[key_4] != "" {
+		yl_code = class.Medical_Class_Name[key_4]
+		is_b = true
+	} else {
+		pro_key := fmt.Sprintf("%s_%s_%s", product_class_1, product_class_2, product_class_3)
+		if class.Medical_Class_Name[pro_key] != "" {
+			yl_code = class.Medical_Class_Name[pro_key]
+			is_b = true
+		}
+	}
+	return is_b, yl_code
+}
+
+//根据标的物名称~打医疗分类
+func confrimTopSubCode(toptype string, subtype string) string {
+	bid_topsubtype_code := ""
+	datas := class.Bid_TopSubtype[toptype]
+	if datas != nil {
+		bid_topsubtype_code = datas["code"]
+		if datas[subtype] != "" {
+			bid_topsubtype_code = datas[subtype]
+		}
+	}
+	return bid_topsubtype_code
+}
+
+//return
+func isMarkInterfaceMap(t interface{}) []map[string]interface{} {
+	p_list := []map[string]interface{}{}
+	if yl_list_1, ok_1 := t.(primitive.A); ok_1 {
+		p_list = qu.ObjArrToMapArr(yl_list_1)
+	} else {
+		if yl_list_2, ok_2 := t.([]interface{}); ok_2 {
+			p_list = qu.ObjArrToMapArr(yl_list_2)
+		}
+	}
+	return p_list
+}
+
+//return
+func isMarkInterfaceArr(t interface{}) []string {
+	sub_list := []string{}
+	if list_1, ok_1 := t.(primitive.A); ok_1 {
+		sub_list = qu.ObjArrToStringArr(list_1)
+	} else {
+		if list_2, ok_2 := t.([]interface{}); ok_2 {
+			sub_list = qu.ObjArrToStringArr(list_2)
+		}
+	}
+	return sub_list
+}

+ 51 - 0
filedproject_medical/data_preparation/src/bidinfo/bidsql.go

@@ -0,0 +1,51 @@
+package bidinfo
+
+import (
+	"class"
+	qu "qfw/util"
+	"time"
+)
+
+//标的物基本信息  bid_purchasinginfo  bid_purchasing_field_record
+func insertBaseInfo(p_list []map[string]interface{}, infoid string, bid_topsubtype_code string) {
+	for _, info := range p_list {
+		medical_equipment_code := qu.ObjToString(info["medical_equipment_code"])
+		delete(info, "medical_equipment_code")
+		info["infoid"] = infoid
+		info["bid_topsubtype_code"] = bid_topsubtype_code
+		info["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
+		pur_id := class.InsertMysqlData("bid_purchasinginfo", info, infoid)
+		if pur_id != -1 { //构建有效
+			if medical_equipment_code != "" { //记录标签
+				info_tag := map[string]interface{}{}
+				info_tag["bid_purchasing_id"] = pur_id
+				info_tag["medical_equipment_code"] = medical_equipment_code
+				info_tag["product_field_code"] = "0101"
+				info_tag["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
+				class.InsertMysqlData("bid_purchasing_field_record", info_tag, infoid)
+			}
+		}
+
+	}
+}
+
+//招标信息~领域标签~现在唯一 bid_fieldtags
+func insertFiledTag(infoid string) {
+	data := map[string]interface{}{}
+	data["infoid"] = infoid
+	data["labelcode"] = "0101"
+	data["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
+	class.InsertMysqlData("bid_fieldtags", data, infoid)
+
+	//更新bidding~
+
+}
+
+//招标信息~行业标签~现在唯一 bid_industrytags
+func insertIndustryTag(industry_code string, infoid string) {
+	data := map[string]interface{}{}
+	data["infoid"] = infoid
+	data["labelcode"] = industry_code
+	data["comeintime"] = time.Unix(time.Now().Unix(), 0).Format(class.TimeLayout)
+	class.InsertMysqlData("bid_industrytags", data, infoid)
+}

+ 181 - 0
filedproject_medical/data_preparation/src/class/initcode.go

@@ -0,0 +1,181 @@
+package class
+
+import (
+	log "github.com/donnie4w/go-logger/logger"
+	qu "qfw/util"
+	"unicode/utf8"
+)
+
+//加载地域
+func initRegion() {
+	data_region := MysqlTool.Find("code_area", nil, "", "", -1, -1)
+	log.Debug(len(*data_region))
+	for _, v := range *data_region {
+		code := qu.ObjToString(v["code"])
+		area := qu.ObjToString(v["area"])
+		city := qu.ObjToString(v["city"])
+		district := qu.ObjToString(v["district"])
+		if district != "" {
+			key := area + "~" + city + "~" + district
+			DistrictCode[key] = code
+		} else {
+			if city != "" {
+				key := area + "~" + city
+				CityCode[key] = code
+			} else {
+				AreaCode[area] = code
+			}
+		}
+	}
+	log.Debug("地域加载完毕~", len(AreaCode), len(CityCode), len(DistrictCode))
+}
+
+//加载等级代码表~level
+func initLevel() {
+	data_level := MysqlTool.Find("code_medical_institution_level", nil, "name,code", "", -1, -1)
+	for _, v := range *data_level {
+		name := qu.ObjToString(v["name"])
+		code := qu.ObjToString(v["code"])
+		Medical_Level[name] = code
+	}
+	log.Debug("医疗等级表~", len(Medical_Level))
+}
+
+//加载类型代码表~type
+func initType() {
+	data_type := MysqlTool.Find("code_medical_institution_type", nil, "name,code", "", -1, -1)
+	for _, v := range *data_type {
+		name := qu.ObjToString(v["name"])
+		code := qu.ObjToString(v["code"])
+		Medical_Type[name] = code
+	}
+	log.Debug("医疗类型表~", len(Medical_Type))
+}
+
+//加载科室代码表
+func initDeparts() {
+	data_departs := MysqlTool.Find("code_medical_institution_department", nil, "", "", -1, -1)
+	//先构建所有一级数据
+	for _, v := range *data_departs {
+		name := qu.ObjToString(v["name"])
+		code := qu.ObjToString(v["code"])
+		if qu.IntAll(v["level"]) == 1 {
+			Medical_Departs[name] = map[string]string{
+				"departs_code": code,
+			}
+		}
+	}
+	for _, v := range *data_departs {
+		code := qu.ObjToString(v["code"])
+		pcode := qu.ObjToString(v["pcode"])
+		name := qu.ObjToString(v["name"])
+		if qu.IntAll(v["level"]) == 2 {
+			match_name := ""
+			for k, v := range Medical_Departs {
+				if v["departs_code"] == pcode {
+					match_name = k
+					break
+				}
+			}
+			data := Medical_Departs[match_name]
+			data[name] = code
+			Medical_Departs[match_name] = data
+		}
+	}
+	log.Debug("医疗科室表~", len(Medical_Departs))
+}
+
+//加载招标信息分类
+func initBidInfoClass() {
+	data_types := MysqlTool.Find("code_bidtopsubtype", nil, "", "", -1, -1)
+	//先构建所有一级数据
+	for _, v := range *data_types {
+		name := qu.ObjToString(v["name"])
+		code := qu.ObjToString(v["code"])
+		pcode := qu.ObjToString(v["pcode"])
+		level := qu.IntAll(v["level"])
+		if level == 1 {
+			Bid_TopSubtype[name] = map[string]string{
+				"code": code,
+			}
+		} else if level == 2 {
+			match_name := ""
+			for k1, v1 := range Bid_TopSubtype {
+				if v1["code"] == pcode {
+					match_name = k1
+					break
+				}
+			}
+			data := Bid_TopSubtype[match_name]
+			data[name] = code
+			Bid_TopSubtype[match_name] = data
+		} else {
+
+		}
+	}
+	log.Debug("招标信息分类表~", len(Bid_TopSubtype))
+}
+
+//加载招标行业分类
+func initBidIndustryClass() {
+	data_types := MysqlTool.Find("code_bidindustry", nil, "", "", -1, -1)
+	//先构建所有一级数据
+	for _, v := range *data_types {
+		name := qu.ObjToString(v["name"])
+		code := qu.ObjToString(v["code"])
+		pcode := qu.ObjToString(v["pcode"])
+		level := qu.IntAll(v["level"])
+		if level == 1 {
+			Bid_Industry[name] = map[string]string{
+				"code": code,
+			}
+		} else if level == 2 {
+			match_name := ""
+			for k1, v1 := range Bid_Industry {
+				if v1["code"] == pcode {
+					match_name = k1
+					break
+				}
+			}
+			data := Bid_Industry[match_name]
+			data[name] = code
+			Bid_Industry[match_name] = data
+		} else {
+
+		}
+	}
+	log.Debug("招标行业分类表~", len(Bid_Industry))
+}
+
+func initMedicalClass() {
+	data_class := MysqlTool.Find("code_medical_equipment_product", nil, "", "", -1, -1)
+	for _, v := range *data_class {
+		name := qu.ObjToString(v["name"])
+		code := qu.ObjToString(v["code"])
+		Medical_Class_Code[code] = name
+	}
+	for k, v := range Medical_Class_Code {
+		key := ""
+		if utf8.RuneCountInString(k) == 2 {
+			key = v + "_" + "_"
+		} else if utf8.RuneCountInString(k) == 4 {
+			code_1 := k[:2]
+			name_1 := Medical_Class_Code[code_1]
+			key = name_1 + "_" + v + "_"
+		} else if utf8.RuneCountInString(k) == 7 {
+			code_1 := k[:2]
+			name_1 := Medical_Class_Code[code_1]
+			code_2 := k[:4]
+			name_2 := Medical_Class_Code[code_2]
+			key = name_1 + "_" + name_2 + "_" + v
+		} else if utf8.RuneCountInString(k) == 11 {
+			key = "四级" + "_" + v
+		}
+		if key != "" {
+			if Medical_Class_Name[key] == "" {
+				Medical_Class_Name[key] = k
+			}
+		}
+	}
+	log.Debug("医疗分类~加载~完毕~", len(Medical_Class_Name), len(Medical_Class_Code))
+}

+ 33 - 84
filedproject_medical/data_preparation/src/class/initdata.go

@@ -17,34 +17,34 @@ var (
 	AreaCode          = map[string]string{}
 	CityCode          = map[string]string{}
 	DistrictCode      = map[string]string{}
-	isLocal           bool
-	YXBK_DATA         = map[string]map[string]interface{}{} //医学百科相关数据
-	select_field      = map[string]interface{}{"area": 1, "city": 1, "district": 1, "name": 1, "website": 1}
+	//标讯相关
+	Bid_TopSubtype = map[string]map[string]string{}
+	Bid_Industry   = map[string]map[string]string{}
+
+	//医疗分类
+	Medical_Class_Name = map[string]string{} //v表-医疗分类-名称对应-代码
+	Medical_Class_Code = map[string]string{} //v表-医疗分类-代码对应-名称
+
+	isLocal      bool
+	YXBK_DATA    = map[string]map[string]interface{}{} //医学百科相关数据
+	select_field = map[string]interface{}{"area": 1, "city": 1, "district": 1, "name": 1, "website": 1}
 )
 
 func InitClass() {
 	isLocal = true //本地
 	initMgo()
-	//清洗医院需要以下配置
 	initMysql()
 	initVCode()
+
+	//医学百科数据
 	//initLocalData()
 }
 
 //初始化mgo
 func initMgo() {
 	if isLocal {
-		Save_Mgo = &MongodbSim{
-			MongodbAddr: "127.0.0.1:27017",
-			DbName:      "zhengkun",
-			Size:        10,
-			UserName:    "",
-			Password:    "",
-		}
-		Save_Mgo.InitPool()
-
 		//Save_Mgo = &MongodbSim{
-		//	MongodbAddr: "192.168.3.207:27092",
+		//	MongodbAddr: "127.0.0.1:27017",
 		//	DbName:      "zhengkun",
 		//	Size:        10,
 		//	UserName:    "",
@@ -52,6 +52,15 @@ func initMgo() {
 		//}
 		//Save_Mgo.InitPool()
 
+		Save_Mgo = &MongodbSim{
+			MongodbAddr: "192.168.3.207:27092",
+			DbName:      "zhengkun",
+			Size:        10,
+			UserName:    "",
+			Password:    "",
+		}
+		Save_Mgo.InitPool()
+
 		Spi_Mgo = &MongodbSim{
 			MongodbAddr: "127.0.0.1:27017",
 			DbName:      "zhengkun",
@@ -89,79 +98,18 @@ func initMysql() {
 		DBName:   "field_medical_data",
 	}
 	MysqlTool.Init()
-
 }
 
+//加载代码表~
 func initVCode() {
-	//加载地域代码~
-	data_region := MysqlTool.Find("code_area", nil, "", "", -1, -1)
-	log.Debug(len(*data_region))
-	for _, v := range *data_region {
-		code := qu.ObjToString(v["code"])
-		area := qu.ObjToString(v["area"])
-		city := qu.ObjToString(v["city"])
-		district := qu.ObjToString(v["district"])
-		if district != "" {
-			key := area + "~" + city + "~" + district
-			DistrictCode[key] = code
-		} else {
-			if city != "" {
-				key := area + "~" + city
-				CityCode[key] = code
-			} else {
-				AreaCode[area] = code
-			}
-		}
-	}
-	log.Debug("地域加载完毕~", len(AreaCode), len(CityCode), len(DistrictCode))
+	//initRegion()
+	//initLevel()
+	//initType()
+	//initDeparts()
 
-	//加载等级代码表~level
-	data_level := MysqlTool.Find("code_medical_institution_level", nil, "name,code", "", -1, -1)
-	for _, v := range *data_level {
-		name := qu.ObjToString(v["name"])
-		code := qu.ObjToString(v["code"])
-		Medical_Level[name] = code
-	}
-	log.Debug("医疗等级表~", len(Medical_Level))
-	//加载类型代码表~type
-	data_type := MysqlTool.Find("code_medical_institution_type", nil, "name,code", "", -1, -1)
-	for _, v := range *data_type {
-		name := qu.ObjToString(v["name"])
-		code := qu.ObjToString(v["code"])
-		Medical_Type[name] = code
-	}
-	log.Debug("医疗类型表~", len(Medical_Type))
-
-	//加载科室代码表~
-	data_departs := MysqlTool.Find("code_medical_institution_department", nil, "", "", -1, -1)
-	//先构建所有一级数据
-	for _, v := range *data_departs {
-		name := qu.ObjToString(v["name"])
-		code := qu.ObjToString(v["code"])
-		if qu.IntAll(v["level"]) == 1 {
-			Medical_Departs[name] = map[string]string{
-				"departs_code": code,
-			}
-		}
-	}
-	for _, v := range *data_departs {
-		code := qu.ObjToString(v["code"])
-		pcode := qu.ObjToString(v["pcode"])
-		name := qu.ObjToString(v["name"])
-		if qu.IntAll(v["level"]) == 2 {
-			match_name := ""
-			for k, v := range Medical_Departs {
-				if v["departs_code"] == pcode {
-					match_name = k
-					break
-				}
-			}
-			data := Medical_Departs[match_name]
-			data[name] = code
-			Medical_Departs[match_name] = data
-		}
-	}
-	log.Debug("医疗科室表~", len(Medical_Departs))
+	initBidInfoClass()
+	initBidIndustryClass()
+	initMedicalClass()
 }
 
 //准备医学百科数据~
@@ -180,9 +128,10 @@ func initLocalData() {
 }
 
 //插入数据
-func InsertMysqlData(name string, data map[string]interface{}, mark string) {
+func InsertMysqlData(name string, data map[string]interface{}, mark string) int64 {
 	inb := MysqlTool.Insert(name, data)
 	if inb == -1 {
 		log.Debug("插入数据异常...", name, "~", mark)
 	}
+	return inb
 }

+ 4 - 0
filedproject_medical/data_preparation/src/main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"bidinfo"
 	"class"
 	"flag"
 	log "github.com/donnie4w/go-logger/logger"
@@ -30,6 +31,9 @@ func main() {
 	//导入信息~医疗六张表
 	//hospital.ExportHospitalInfoToMysql()
 
+	//标的物信息
+	bidinfo.RunBidBsaeInfoData()
+
 	time.Sleep(999 * time.Hour)
 }
 

+ 16 - 0
filedproject_medical/data_service/src/main.go

@@ -0,0 +1,16 @@
+package main
+
+import (
+	"net/http"
+	"service"
+	"time"
+)
+
+func init() {
+	service.InitService()
+}
+
+func main() {
+	http.ListenAndServe(":9991", nil)
+	time.Sleep(999 * time.Hour)
+}

+ 20 - 0
filedproject_medical/data_service/src/service/service.go

@@ -0,0 +1,20 @@
+package service
+
+import (
+	"encoding/json"
+	log "github.com/donnie4w/go-logger/logger"
+	"net/http"
+	"sync"
+)
+
+var datalock sync.Mutex
+
+func InitService() {
+	http.HandleFunc("/getbid/tags", func(w http.ResponseWriter, r *http.Request) {
+		gtid := r.FormValue("gtid")
+		lteid := r.FormValue("lteid")
+		log.Debug(gtid, lteid)
+		res, _ := json.Marshal("ok")
+		w.Write(res)
+	})
+}