Quellcode durchsuchen

feat:覆盖查询字段

wangchuanjin vor 1 Jahr
Ursprung
Commit
598f751caa
1 geänderte Dateien mit 12 neuen und 7 gelöschten Zeilen
  1. 12 7
      p/public.go

+ 12 - 7
p/public.go

@@ -216,7 +216,7 @@ func GetInfoTitle(info map[string]interface{}) string {
 }
 
 //加载数据到内存中
-func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCache bool, query map[string]interface{}) (*[]map[string]interface{}, int64) {
+func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCache bool, query map[string]interface{}, fields map[string]interface{}) (*[]map[string]interface{}, int64) {
 	defer util.Catch()
 	endTime := time.Now().Unix()
 	if query == nil || len(query) == 0 {
@@ -228,10 +228,7 @@ func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCac
 		}
 	}
 	logger.Info("开始加载", coll, "数据", query)
-	var res []map[string]interface{}
-	sess := mgo.GetMgoConn()
-	defer mgo.DestoryMongoConn(sess)
-	it := sess.DB(dbName).C(coll).Find(query).Select(map[string]interface{}{
+	queryField := map[string]interface{}{
 		"title":           1,
 		"detail":          1,
 		"projectname":     1,
@@ -264,7 +261,16 @@ func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCac
 		"bidendtime":      1,
 		"entidlist":       1,
 		"autoid":          1,
-	}).Iter()
+	}
+	if fields == nil {
+		for k, v := range fields {
+			queryField[k] = v
+		}
+	}
+	var res []map[string]interface{}
+	sess := mgo.GetMgoConn()
+	defer mgo.DestoryMongoConn(sess)
+	it := sess.DB(dbName).C(coll).Find(query).Select(queryField).Iter()
 	index := 0
 	for temp := make(map[string]interface{}); it.Next(&temp); {
 		_id := BsonIdToSId(temp["_id"])
@@ -280,7 +286,6 @@ func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCac
 			temp["area"] = "全国"
 		}
 		temp["attachment_count"] = GetAttachmentCount(temp)
-		delete(temp, "projectinfo")
 		res = append(res, temp)
 		if redisCache {
 			//信息缓存3天