فهرست منبع

标讯数据-标的物数据准备

zhengkun 3 سال پیش
والد
کامیت
3c1acc5ae4
3فایلهای تغییر یافته به همراه154 افزوده شده و 12 حذف شده
  1. 9 6
      process_ medical/src/main.go
  2. 143 4
      process_ medical/src/medical_bidding.go
  3. 2 2
      process_ medical/src/medical_prepare.go

+ 9 - 6
process_ medical/src/main.go

@@ -15,10 +15,10 @@ 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{}
 var buyerclass_dict = map[string]string{}
-var industryclass_dict = map[string]string{}
+var industry_dict = map[string]string{}
 var area_dict = map[string]string{}
 var proclass_dict = map[string]string{}
-
+var timeLayout = "2006-01-02 15:04:05"
 
 func init()  {
 	//qy_mgo = &MongodbSim{
@@ -102,8 +102,12 @@ func init()  {
 
 func main()  {
 	//exportSource() //导出源数据
-
 	dealWithSource()  //处理源数据
+
+
+
+
+
 }
 
 
@@ -118,15 +122,14 @@ func dealWithSource() {
 	MysqlTool.Init()
 
 	save_mgo = &MongodbSim{
-		MongodbAddr: "127.0.0.1:27017",
-		DbName:      "mixdata",
+		MongodbAddr: "192.168.3.207:27092",
+		DbName:      "zhengkun",
 		Size:        10,
 		UserName: "",
 		Password: "",
 	}
 	save_mgo.InitPool()
 
-
 	initMySqlMgoData() //加载数据-本地
 
 	dealWithBiddingSource()

+ 143 - 4
process_ medical/src/medical_bidding.go

@@ -6,8 +6,10 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 	qu "qfw/util"
 	"strings"
+	"time"
 )
 
+
 //生成两个 mysql 表
 func dealWithBiddingSource() {
    	//f_bidding    f_bidproduct
@@ -17,20 +19,157 @@ func dealWithBiddingSource() {
 	q,total:=map[string]interface{}{},0
 	it := sess.DB(save_mgo.DbName).C("zktest_mysql_source").Find(&q).Iter()
 	for tmp := make(map[string]interface{}); it.Next(&tmp);total++{
-		if total%10000==0 {
+		if total%100==0 {
 			log.Debug("curent index ",total)
 		}
-
-		
-
+		saveBidMysqlData(tmp)
+		savePurMysqlData(tmp)
 		tmp = make(map[string]interface{})
 	}
+
 	log.Debug("is over ",total)
 
 
 }
 
 
+//导出招标-mysql
+func saveBidMysqlData(tmp map[string]interface{}){
+	data := map[string]interface{}{}
+	data["info_id"] = tmp["info_id"]
+	data["projectname"] = tmp["projectname"]
+	publishtime := qu.Int64All(tmp["publishtime"])
+	new_publishtime := ""//转日期
+	if publishtime>0 {
+		new_publishtime = time.Unix(publishtime, 0).Format(timeLayout)
+		data["publishtime"] = new_publishtime
+	}
+	data["buyer_name"] = qu.ObjToString(tmp["buyer"])
+	data["buyer_depart"] = ""
+	if tmp["budget"]!=nil {
+		data["budget"] = qu.Float64All(tmp["budget"])
+	}
+	if tmp["bidamount"]!=nil {
+		data["bidamount"] = qu.Float64All(tmp["bidamount"])
+	}
+	data["agency_name"] = qu.ObjToString(tmp["agency"])
+	data["winner_name"] = qu.ObjToString(tmp["s_winner"])
+	data["jy_href"] = qu.ObjToString(tmp["jyhref"])
+	updatetime := time.Unix(time.Now().Unix(), 0).Format(timeLayout)
+	data["updatetime"] = updatetime
+
+	// info_type buyer_classcode area_code industry_code
+	info_type_key :=qu.ObjToString(tmp["toptype"])+"_"+qu.ObjToString(tmp["subtype"])
+	data["info_type"] = bidclass_dict[info_type_key]
+
+	buyerclass := qu.ObjToString(tmp["buyerclass"])
+	data["buyer_classcode"] =buyerclass_dict[buyerclass]
+
+	area_key := qu.ObjToString(tmp["area"])+"_"+qu.ObjToString(tmp["city"])+"_"+qu.ObjToString(tmp["district"])
+	data["area_code"] =area_dict[area_key]
+
+
+
+	subscopeclass := []string{}
+	if res, ok := tmp["subscopeclass"].(primitive.A); ok {
+		subscopeclass = qu.ObjArrToStringArr(res)
+	}else {
+		if res, ok := tmp["subscopeclass"].([]interface{}); ok {
+			subscopeclass = qu.ObjArrToStringArr(res)
+		}
+	}
+
+
+	industry_code,industry_code_other:="",""
+	for _,v := range subscopeclass{
+		if strings.Contains(v,"医疗卫生") {
+			industry_code = industry_dict[v]
+		}else {
+			if industry_code_other!="" {
+				industry_code_other = industry_code_other+","+industry_dict[v]
+			}else {
+				industry_code_other = industry_dict[v]
+			}
+		}
+	}
+	data["industry_code"] = industry_code
+	data["industry_code_other"] = industry_code_other
+
+	//保存mysql
+	MysqlTool.Insert("f_bidding",data)
+}
+
+//导出标的物-mysql
+func savePurMysqlData(tmp map[string]interface{}){
+	p_list := []map[string]interface{}{}
+	if yl_purchasinglist, ok := tmp["yl_purchasinglist"].(primitive.A); ok {
+		p_list = qu.ObjArrToMapArr(yl_purchasinglist)
+	}else {
+		if yl_purchasinglist, ok := tmp["yl_purchasinglist"].([]interface{}); ok {
+			p_list = qu.ObjArrToMapArr(yl_purchasinglist)
+		}
+	}
+
+
+	info_id := qu.ObjToString(tmp["info_id"])
+	s_winner := qu.ObjToString(tmp["s_winner"])
+	for _,v:=range p_list{
+		data := map[string]interface{}{}
+
+		product_name := qu.ObjToString(v["product_name"])
+		data["info_id"] = info_id
+		data["bid_name"] = qu.ObjToString(v["itemname"])
+		data["product_name"] = product_name
+		data["product_brand"] = qu.ObjToString(v["brandname"])
+		data["product_model"] = qu.ObjToString(v["model"])
+		data["product_specs"] = ""
+
+		if v["unitprice"]!=nil {
+			data["product_price"] = qu.Float64All(v["unitprice"])
+		}
+		if v["number"]!=nil {
+			data["product_num"] = qu.Float64All(v["number"])
+		}
+		if v["totalprice"]!=nil {
+			data["product_totalprice"] = qu.Float64All(v["totalprice"])
+		}
+
+		if v["unitname"]!=nil {
+			data["product_unit"] = qu.ObjToString(v["unitname"])
+		}
+
+		if !strings.Contains(s_winner,",") {
+			data["bid_company_id"] = qu.ObjToString(tmp["company_id"])
+			data["bid_company_name"] = s_winner
+		}else {
+			data["bid_company_id"] = ""
+			data["bid_company_name"] = ""
+		}
+		data["bid_company_ysname"] = ""
+		data["make_company_id"] = ""
+		data["make_company_name"] = ""
+		data["make_company_ysname"] = ""
+
+		//product_code分类
+		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 proclass_dict[key_4]!="" {
+			data["product_code"] = proclass_dict[key_4]
+		}else {
+			pro_key := fmt.Sprintf("%s_%s_%s",product_class_1,product_class_2,product_class_3)
+			data["product_code"] = proclass_dict[pro_key]
+		}
+
+
+		//保存mysql
+		MysqlTool.Insert("f_bidproduct",data)
+	}
+
+
+}
 
 
 

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

@@ -15,7 +15,7 @@ func initMySqlMgoData() {
 	init_area()
 	init_proclass()
 
-	log.Debug("init mysql 完毕",len(bidclass_dict),len(buyerclass_dict),len(industryclass_dict))
+	log.Debug("init mysql 完毕",len(bidclass_dict),len(buyerclass_dict),len(industry_dict))
 	log.Debug("init mgo 完毕",len(area_dict),len(proclass_dict))
 
 }
@@ -62,7 +62,7 @@ func init_industryclass() {
 			pre_str = name
 		}else {
 			key := pre_str+"_"+name
-			industryclass_dict[key] = code
+			industry_dict[key] = code
 		}
 	}
 }