Explorar o código

Merge branch 'dev3.2' of http://192.168.3.207:10080/qmx/jy-data-extract into dev3.2

fengweiqiang %!s(int64=5) %!d(string=hai) anos
pai
achega
bc96f301a5

+ 4 - 3
fullproject/src_dev5/project.go

@@ -489,12 +489,13 @@ var INFOFIELDS = []string{
 	"topscopeclass",
 	"subscopclass",
 	"infoformat",
+	"buyerperson",
+	"buyertel",
 }
 
 //项目中list的信息
 func (p *ProjectTask) PushListInfo(tmp map[string]interface{}) bson.M {
 	res := bson.M{
-
 		"infoid": qu.BsonIdToSId(tmp["_id"]),
 	}
 	for _, k := range INFOFIELDS {
@@ -614,12 +615,12 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 	}
 	//9--采购单位联系人
 	if thisinfo.Buyerperson != "" && strings.Index(pInfo.Buyerperson, thisinfo.Buyerperson) < 0 {
-		pInfo.Buyerperson += thisinfo.Buyerperson
+		pInfo.Buyerperson = thisinfo.Buyerperson
 		set["buyerperson"] = pInfo.Buyerperson
 	}
 	//10--采购单位電話
 	if thisinfo.Buyertel != "" && strings.Index(pInfo.Buyertel, thisinfo.Buyertel) < 0 {
-		pInfo.Buyertel += thisinfo.Buyertel
+		pInfo.Buyertel = thisinfo.Buyertel
 		set["buyertel"] = pInfo.Buyertel
 	}
 

+ 9 - 8
fullproject/src_dev5/task.go

@@ -189,18 +189,19 @@ func (p *ProjectTask) taskQl(udpInfo map[string]interface{}) {
 	if coll == "" {
 		coll = ExtractColl
 	}
-	sess := MongoTool.GetMgoConn()
-	bcon := false
-	if sess.DB(db).C(coll).EnsureIndexKey("publishtime_1", "publishtime_-1") == nil {
-		bcon = true
-	} else {
-		log.Println("publishtime_1索引不存在")
-	}
-	MongoTool.DestoryMongoConn(sess)
+	//	sess := MongoTool.GetMgoConn()
+	//	bcon := false
+	//	if sess.DB(db).C(coll).EnsureIndexKey("publishtime_1", "publishtime_-1") == nil {
+	//		bcon = true
+	//	} else {
+	//		log.Println("publishtime_1索引不存在")
+	//	}
+	//	MongoTool.DestoryMongoConn(sess)
 	thread := util.IntAllDef(udpInfo["thread"], 3)
 	if thread > 0 {
 		p.thread = thread
 	}
+	bcon := true
 	if bcon {
 		//生成查询语句执行
 		p.enter(db, coll, map[string]interface{}{})

+ 8 - 3
udpcreateindex/src/biddingall.go

@@ -13,10 +13,11 @@ import (
 
 //对字段处理 bidamount  budget
 //招标数据表和抽取表一一对应开始更新
-var mpool = make(chan bool, 10)
 
 func biddingAllTask(data []byte, mapInfo map[string]interface{}) {
 	defer qutil.Catch()
+	thread := 40
+	var mpool = make(chan bool, thread)
 	q, _ := mapInfo["query"].(map[string]interface{})
 	if q == nil {
 		q = map[string]interface{}{
@@ -241,11 +242,11 @@ func biddingAllTask(data []byte, mapInfo map[string]interface{}) {
 					},
 				})
 			}
-			if len(arr) >= BulkSize-1 {
+			if len(arr) >= BulkSize {
 				mgo.UpdateBulkAll(db, c, arr...)
 				arr = [][]map[string]interface{}{}
 			}
-			if len(arrEs) >= BulkSize-1 {
+			if len(arrEs) >= BulkSize {
 				tmps := arrEs
 				elastic.BulkSave(index, itype, &tmps, true)
 				if len(multiIndex) == 2 {
@@ -260,7 +261,11 @@ func biddingAllTask(data []byte, mapInfo map[string]interface{}) {
 		}
 		tmp = make(map[string]interface{})
 	}
+	for i := 0; i < thread; i++ {
+		mpool <- true
+	}
 	UpdatesLock.Lock()
+	//log.Println(db, c, index, itype, arr, arrEs)
 	if len(arr) > 0 {
 		mgo.UpdateBulkAll(db, c, arr...)
 	}

+ 12 - 19
udpcreateindex/src/biddingdata.go

@@ -53,6 +53,8 @@ var indexfield = []string{
 //招标数据表和抽取表一一对应开始更新
 func biddingDataTask(data []byte, mapInfo map[string]interface{}) {
 	defer qutil.Catch()
+	thread := 40
+	var mpool = make(chan bool, thread)
 	q, _ := mapInfo["query"].(map[string]interface{})
 	if q == nil {
 		q = map[string]interface{}{
@@ -205,10 +207,6 @@ func biddingDataTask(data []byte, mapInfo map[string]interface{}) {
 			}
 			//------------------对比结束
 
-			//处理key descript
-			//		if bkey == "" {
-			//			DealInfo(&tmp, &update)
-			//		}
 			//同时保存到elastic
 			for tk, tv := range update {
 				tmp[tk] = tv
@@ -231,13 +229,7 @@ func biddingDataTask(data []byte, mapInfo map[string]interface{}) {
 			} else if sbd, ok := tmp["bidamount"].(string); ok {
 				tmp["bidamount"] = ObjToMoney([]interface{}{sbd, sbd})[0]
 			}
-			//		for k1, _ := range tmp {
-			//			if strings.HasSuffix(k1, "_b") || k1 == "contenthtml" {
-			//				delete(tmp, k1)
-			//			}
-			//		}
-			//go IS.Add("bidding")
-			UpdatesLock.Lock()
+
 			if qutil.IntAll(update["extracttype"]) != -1 {
 				newTmp := map[string]interface{}{}
 				for _, v := range indexfield {
@@ -265,14 +257,14 @@ func biddingDataTask(data []byte, mapInfo map[string]interface{}) {
 						newTmp[v] = nil
 					}
 				}
+				UpdatesLock.Lock()
 				arrEs = append(arrEs, newTmp)
+				UpdatesLock.Unlock()
 			}
+			UpdatesLock.Lock()
 			if len(arrEs) >= BulkSize-1 {
 				tmps := arrEs
-				elastic.BulkSave(index, itype, &tmps, true)
-				if len(multiIndex) == 2 {
-					elastic.BulkSave(multiIndex[0], multiIndex[1], &tmps, true)
-				}
+				elastic.BulkSave(index, itype, &tmps, false)
 				arrEs = []map[string]interface{}{}
 			}
 			UpdatesLock.Unlock()
@@ -282,13 +274,14 @@ func biddingDataTask(data []byte, mapInfo map[string]interface{}) {
 		}
 		tmp = make(map[string]interface{})
 	}
+	for i := 0; i < thread; i++ {
+		mpool <- true
+	}
 	UpdatesLock.Lock()
 	if len(arrEs) > 0 {
 		tmps := arrEs
-		elastic.BulkSave(index, itype, &tmps, true)
-		if len(multiIndex) == 2 {
-			elastic.BulkSave(multiIndex[0], multiIndex[1], &tmps, true)
-		}
+		log.Println(tmps[0])
+		elastic.BulkSave(index, itype, &tmps, false)
 	}
 	UpdatesLock.Unlock()
 	log.Println(mapInfo, "create bidding index...over", n)

+ 0 - 2
udpcreateindex/src/biddingindex.go

@@ -16,8 +16,6 @@ import (
 	"gopkg.in/mgo.v2/bson"
 )
 
-var BulkSize = 200
-
 //对字段处理 bidamount  budget
 //招标数据表和抽取表一一对应开始更新
 

+ 233 - 0
udpcreateindex/src/biddingmerge.go

@@ -0,0 +1,233 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	qutil "qfw/util"
+	"strings"
+	"sync"
+
+	"gopkg.in/mgo.v2/bson"
+)
+
+//对字段处理 bidamount  budget
+//招标数据表和抽取表一一对应开始更新
+
+func biddingMergeTask(data []byte, mapInfo map[string]interface{}) {
+	defer qutil.Catch()
+	thread := 40
+	var mpool = make(chan bool, thread)
+	q, _ := mapInfo["query"].(map[string]interface{})
+	if q == nil {
+		q = map[string]interface{}{
+			"_id": bson.M{
+				"$gt":  qutil.StringTOBsonId(mapInfo["gtid"].(string)),
+				"$lte": qutil.StringTOBsonId(mapInfo["lteid"].(string)),
+			},
+		}
+	}
+	//bidding库
+	session := mgo.GetMgoConn()
+	defer mgo.DestoryMongoConn(session)
+	//extract库
+	extractsession := extractmgo.GetMgoConn()
+	defer extractmgo.DestoryMongoConn(extractsession)
+	//连接信息
+	c, _ := mapInfo["coll"].(string)
+	if c == "" {
+		c, _ = bidding["collect"].(string)
+	}
+
+	extractc, _ := bidding["extractcollect"].(string)
+	db, _ := bidding["db"].(string)
+	extractdb, _ := bidding["extractdb"].(string)
+	count, _ := session.DB(db).C(c).Find(&q).Count()
+	fields := strings.Split(bidding["fields"].(string), ",")
+	//线程池
+	UpdatesLock := sync.Mutex{}
+
+	log.Println("查询语句:", q, "同步总数:", count)
+	//查询招标数据
+	query := session.DB(db).C(c).Find(q).Select(bson.M{
+		"projectinfo.attachment": 0,
+		"contenthtml":            0,
+	}).Sort("_id").Iter()
+	//查询抽取结果
+	extractquery := extractsession.DB(extractdb).C(extractc).Find(q).Sort("_id").Iter()
+
+	n := 0
+
+	//更新数组
+	arr := [][]map[string]interface{}{}
+	//对比两张表数据,减少查询次数
+	var compare bson.M
+	bnil := false
+	for tmp := make(map[string]interface{}); query.Next(tmp); n++ {
+		update := map[string]interface{}{}
+		//对比方法----------------
+		for {
+			if compare == nil {
+				compare = make(bson.M)
+				if !extractquery.Next(compare) {
+					break
+				}
+			}
+			if compare != nil {
+				//对比
+				cid := qutil.BsonIdToSId(compare["_id"])
+				tid := qutil.BsonIdToSId(tmp["_id"])
+				if cid == tid {
+					bnil = false
+					//更新bidding表,生成索引
+					for _, k := range fields {
+						v1 := compare[k]
+						v2 := tmp[k]
+						if v2 == nil && v1 != nil {
+							update[k] = v1
+						} else if v2 != nil && v1 != nil {
+							//update[k+"_b"] = v2
+							update[k] = v1
+						} else if v2 != nil && v1 == nil {
+							//update[k+"_b"] = v2
+						}
+					}
+					if qutil.IntAll(compare["repeat"]) == 1 {
+						update["extracttype"] = -1
+					} else if qutil.IntAll(tmp["extracttype"]) == -1 {
+						update["extracttype"] = 1
+					}
+					break
+				} else {
+					if cid < tid {
+						bnil = false
+						compare = nil
+						continue
+					} else {
+						bnil = true
+						break
+					}
+				}
+			} else {
+				bnil = false
+				break
+			}
+		}
+		//下面可以多线程跑的--->
+		//处理分类
+		mpool <- true
+		go func(tmp, update, compare map[string]interface{}, bnil bool) {
+			defer func() {
+				<-mpool
+			}()
+			if !bnil && compare != nil {
+				subscopeclass, _ := compare["subscopeclass"].([]interface{})
+				if subscopeclass != nil {
+					//str := ","
+					m1 := map[string]bool{}
+					newclass := []string{}
+					for _, sc := range subscopeclass {
+						sclass, _ := sc.(string)
+						if !m1[sclass] {
+							m1[sclass] = true
+							//str += sclass + ","
+							newclass = append(newclass, sclass)
+						}
+					}
+					update["s_subscopeclass"] = strings.Join(newclass, ",")
+					update["subscopeclass"] = newclass
+				}
+				//处理中标企业
+				winner, _ := compare["winner"].(string)
+				m1 := map[string]bool{}
+				if winner != "" {
+					m1[winner] = true
+				}
+				package1 := compare["package"]
+				if package1 != nil {
+					packageM, _ := package1.(map[string]interface{})
+					for _, p := range packageM {
+						pm, _ := p.(map[string]interface{})
+						pw, _ := pm["winner"].(string)
+						if pw != "" {
+							m1[pw] = true
+						}
+					}
+				}
+				compare = nil
+				if len(m1) > 0 {
+					//str := ","
+					winnerarr := []string{}
+					for k, _ := range m1 {
+						//str += k + ","
+						winnerarr = append(winnerarr, k)
+					}
+					update["s_winner"] = strings.Join(winnerarr, ",")
+				}
+			}
+			//------------------对比结束
+
+			//处理key descript
+			//		if bkey == "" {
+			//			DealInfo(&tmp, &update)
+			//		}
+			//同时保存到elastic
+			for tk, tv := range update {
+				tmp[tk] = tv
+			}
+			//对projectscope字段的索引处理
+			ps, _ := tmp["projectscope"].(string)
+			if ps == "" {
+				tmp["projectscope"] = "" //= tmp["detail"]
+			}
+			if len(ps) > ESLEN {
+				tmp["projectscope"] = string(([]rune(ps))[:4000])
+			}
+			if s_budget := fmt.Sprint(tmp["budget"]); s_budget == "" || s_budget == "<nil>" || s_budget == "null" {
+				tmp["budget"] = nil
+			} else if sbd, ok := tmp["budget"].(string); ok {
+				tmp["budget"] = ObjToMoney([]interface{}{sbd, sbd})[0]
+			}
+			if s_bidamount := fmt.Sprint(tmp["bidamount"]); s_bidamount == "" || s_bidamount == "<nil>" || s_bidamount == "null" {
+				tmp["bidamount"] = nil
+			} else if sbd, ok := tmp["bidamount"].(string); ok {
+				tmp["bidamount"] = ObjToMoney([]interface{}{sbd, sbd})[0]
+			}
+			//		for k1, _ := range tmp {
+			//			if strings.HasSuffix(k1, "_b") || k1 == "contenthtml" {
+			//				delete(tmp, k1)
+			//			}
+			//		}
+			//go IS.Add("bidding")
+			UpdatesLock.Lock()
+			if len(update) > 0 {
+				arr = append(arr, []map[string]interface{}{
+					map[string]interface{}{
+						"_id": tmp["_id"],
+					},
+					map[string]interface{}{
+						"$set": update,
+					},
+				})
+			}
+			if len(arr) >= BulkSize-1 {
+				mgo.UpdateBulkAll(db, c, arr...)
+				arr = [][]map[string]interface{}{}
+			}
+
+			UpdatesLock.Unlock()
+		}(tmp, update, compare, bnil)
+		if n%100 == 0 {
+			log.Println("current:", n)
+		}
+		tmp = make(map[string]interface{})
+	}
+	for i := 0; i < thread; i++ {
+		mpool <- true
+	}
+	UpdatesLock.Lock()
+	if len(arr) > 0 {
+		mgo.UpdateBulkAll(db, c, arr...)
+	}
+	UpdatesLock.Unlock()
+	log.Println(mapInfo, "merge bidding...over", n)
+}

+ 12 - 3
udpcreateindex/src/main.go

@@ -23,6 +23,7 @@ var (
 	biddingIndexFields                           = []string{"_id", "buyerclass", "s_winner", "title", "detail", "detail_bak", "area", "areaval", "site", "type", "amount", "bidopendate", "bidopentime", "buyer", "channel", "city", "comeintime", "contenthtml", "descript", "description", "extracttype", "href", "infoformat", "keywords", "projectcode", "projectname", "publishtime", "s_sha", "spidercode", "subtype", "summary", "toptype", "urltop", "winner", "agency", "budget", "bidamount", "s_subscopeclass", "projectscope", "bidstatus"}
 	projectinfoFields                            []string
 	multiIndex                                   []string
+	BulkSize                                     = 400
 )
 
 func init() {
@@ -131,7 +132,7 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 					}()
 					projectTask(data, mapInfo)
 				}()
-			case "biddingback": //不合并,直接调用mongo库生成索引
+			case "biddingback": //不联表,使用bidding表直接调用mongo库生成索引
 				pool <- true
 				go func() {
 					defer func() {
@@ -139,7 +140,7 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 					}()
 					biddingBackTask(data, mapInfo)
 				}()
-			case "biddingall": //重新合并,但不生成关键词
+			case "biddingall": //合并并重新生成索引,不生成关键词
 				pool <- true
 				go func() {
 					defer func() {
@@ -147,7 +148,7 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 					}()
 					biddingAllTask(data, mapInfo)
 				}()
-			case "biddingdata": //重新合并,但不生成关键词
+			case "biddingdata": //联表生成索引不合并,不生成关键词
 				pool <- true
 				go func() {
 					defer func() {
@@ -155,6 +156,14 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 					}()
 					biddingDataTask(data, mapInfo)
 				}()
+			case "biddingmerge": //重新合并但不生成索引,不生成关键词
+				pool <- true
+				go func() {
+					defer func() {
+						<-pool
+					}()
+					biddingMergeTask(data, mapInfo)
+				}()
 			case "buyer":
 				pool <- true
 				go func() {