Browse Source

feat:数据导出 关键词匹配

wangshan 1 year ago
parent
commit
8fb2a5dd1b
1 changed files with 54 additions and 39 deletions
  1. 54 39
      common/src/qfw/util/dataexport/dataexport.go

+ 54 - 39
common/src/qfw/util/dataexport/dataexport.go

@@ -640,15 +640,17 @@ func GetDataExportSelectReallyCount(bid mg.MongodbSim, biddingName string, ids [
 }
 
 func GetDataExportSelectResult(bidding mg.MongodbSim, biddingName string, scd *SieveCondition, dataType string, checkCount int) (*[]map[string]interface{}, error) {
-	sess := bidding.GetMgoConn()
-	defer bidding.DestoryMongoConn(sess)
-	selectMap := map[string]interface{}{
-		"_id": 1, "title": 1, "detail": 1, "area": 1, "city": 1, "publishtime": 1, "projectname": 1, "buyer": 1, "s_winner": 1, "bidamount": 1, "subtype": 1, "toptype": 1, "filetext": 1, "purchasing": 1,
-	}
+	//sess := bidding.GetMgoConn()
+	//defer bidding.DestoryMongoConn(sess)
+	bidField := `"_id", "title", "detail", "area", "city", "publishtime", "projectname", "buyer", "s_winner", "bidamount", "subtype", "toptype", "filetext", "purchasing"`
+	//selectMap := map[string]interface{}{
+	//	"_id": 1, "title": 1, "detail": 1, "area": 1, "city": 1, "publishtime": 1, "projectname": 1, "buyer": 1, "s_winner": 1, "bidamount": 1, "subtype": 1, "toptype": 1, "filetext": 1, "purchasing": 1,
+	//}
 	if dataType == "2" {
-		for _, key := range []string{"href", "projectcode", "buyerperson", "buyertel", "budget", "bidopentime", "agency", "projectscope", "winnerperson", "winnertel", "bidendtime", "district", "signendtime", "buyeraddr", "filetext"} {
-			selectMap[key] = 1
-		}
+		bidField = bidField + `", href", "projectcode", "buyerperson", "buyertel", "budget", "bidopentime", "agency", "projectscope", "winnerperson", "winnertel", "bidendtime", "district", "signendtime", "buyeraddr"`
+		//for _, key := range []string{"href", "projectcode", "buyerperson", "buyertel", "budget", "bidopentime", "agency", "projectscope", "winnerperson", "winnertel", "bidendtime", "district", "signendtime", "buyeraddr", "filetext"} {
+		//	selectMap[key] = 1
+		//}
 	}
 	if checkCount == -1 && len(scd.SelectIds) > 500 {
 		scd.SelectIds = scd.SelectIds[:500]
@@ -665,41 +667,54 @@ func GetDataExportSelectResult(bidding mg.MongodbSim, biddingName string, scd *S
 				wait.Done()
 				<-pool
 			}()
-			var queryIds []interface{}
-			for _, idStr := range arr {
-				queryIds = append(queryIds, mg.StringTOBsonId(idStr))
-			}
-			iter := sess.DB(biddingName).C("bidding").Select(selectMap).Find(map[string]interface{}{"_id": map[string]interface{}{
-				"$in": queryIds,
-			}}).Iter()
-			for m := make(map[string]interface{}); iter.Next(&m); {
-				m["_id"] = mg.BsonIdToSId(m["_id"])
-				detail, _ := m["detail"].(string)
-				if detail != "" {
-					m["detail"] = contentfilterReg.ReplaceAllString(detail, "")
-				}
-				lock.Lock()
-				returnLsit = append(returnLsit, m)
-				lock.Unlock()
-				m = make(map[string]interface{})
-			}
-			iter_back := sess.DB(biddingName).C("bidding_back").Select(selectMap).Find(map[string]interface{}{"_id": map[string]interface{}{
-				"$in": queryIds,
-			}}).Iter()
-			for m := make(map[string]interface{}); iter_back.Next(&m); {
-				m["_id"] = mg.BsonIdToSId(m["_id"])
-				detail, _ := m["detail"].(string)
-				if detail != "" {
-					m["detail"] = contentfilterReg.ReplaceAllString(detail, "")
+			//var queryIds []interface{}
+			//for _, idStr := range arr {
+			//	queryIds = append(queryIds, mg.StringTOBsonId(idStr))
+			//}
+			query := fmt.Sprintf(`{"query":{"bool":{"must":[{"terms":{"id":["%s"]}}]}},"_source": [%s],"size":%d}`, strings.Join(arr, "\",\""), bidField, len(arr))
+			data := *elastic.Get(INDEX, TYPE, query)
+			if data != nil && len(data) > 0 {
+				for _, bv := range data {
+					bv["_id"] = mg.BsonIdToSId(bv["_id"])
+					detail, _ := bv["detail"].(string)
+					if detail != "" {
+						bv["detail"] = contentfilterReg.ReplaceAllString(detail, "")
+					}
+					lock.Lock()
+					returnLsit = append(returnLsit, bv)
+					lock.Unlock()
 				}
-				lock.Lock()
-				returnLsit = append(returnLsit, m)
-				lock.Unlock()
-				m = make(map[string]interface{})
 			}
+			//iter := sess.DB(biddingName).C("bidding").Select(selectMap).Find(map[string]interface{}{"_id": map[string]interface{}{
+			//	"$in": queryIds,
+			//}}).Iter()
+			//for m := make(map[string]interface{}); iter.Next(&m); {
+			//	m["_id"] = mg.BsonIdToSId(m["_id"])
+			//	detail, _ := m["detail"].(string)
+			//	if detail != "" {
+			//		m["detail"] = contentfilterReg.ReplaceAllString(detail, "")
+			//	}
+			//	lock.Lock()
+			//	returnLsit = append(returnLsit, m)
+			//	lock.Unlock()
+			//	m = make(map[string]interface{})
+			//}
+			//iter_back := sess.DB(biddingName).C("bidding_back").Select(selectMap).Find(map[string]interface{}{"_id": map[string]interface{}{
+			//	"$in": queryIds,
+			//}}).Iter()
+			//for m := make(map[string]interface{}); iter_back.Next(&m); {
+			//	m["_id"] = mg.BsonIdToSId(m["_id"])
+			//	detail, _ := m["detail"].(string)
+			//	if detail != "" {
+			//		m["detail"] = contentfilterReg.ReplaceAllString(detail, "")
+			//	}
+			//	lock.Lock()
+			//	returnLsit = append(returnLsit, m)
+			//	lock.Unlock()
+			//	m = make(map[string]interface{})
+			//}
 			return nil
 		}(v)
-
 	}
 	wait.Wait()
 	if len(returnLsit) == checkCount || checkCount == -1 {