|
@@ -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
|
|
|
+}
|