From 9f1b86b7f2732432aed2c13165c95812e57d4f49 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期一, 10 二月 2025 09:31:44 +0800
Subject: [PATCH] 测试 场景分析 bug

---
 models/locationAnalysis.go |  188 +++++++++++++++++++++++-----------------------
 1 files changed, 95 insertions(+), 93 deletions(-)

diff --git a/models/locationAnalysis.go b/models/locationAnalysis.go
index 347927f..3a81f6c 100644
--- a/models/locationAnalysis.go
+++ b/models/locationAnalysis.go
@@ -282,8 +282,8 @@
 
 func queryEsLocation(esClient *elasticsearch.Client, locationModel *LocationModel, documentNumbers []string) ([]*LocationRecord, error) {
 	var buf bytes.Buffer
-	nowTime := time.Now()
-	startTime := nowTime.Add(-time.Duration(locationModel.Duration) * 24 * time.Hour)
+	//nowTime := time.Now()
+	//startTime := nowTime.Add(-time.Duration(locationModel.Duration) * 24 * time.Hour)
 
 	// 鏋勫缓杩囨护鏉′欢
 	var filters []map[string]interface{}
@@ -343,19 +343,19 @@
 	//		},
 	//	},
 	//})
-	for date := startTime; date.Before(nowTime); date = date.Add(24 * time.Hour) {
-		start := time.Date(date.Year(), date.Month(), date.Day(), locationModel.StartTime, 0, 0, 0, date.Location())
-		end := time.Date(date.Year(), date.Month(), date.Day(), locationModel.EndTime, 0, 0, 0, date.Location())
-
-		filters = append(filters, map[string]interface{}{
-			"range": map[string]interface{}{
-				"picDate": map[string]interface{}{
-					"gte": start.Format("2006-01-02 15:04:05"),
-					"lte": end.Format("2006-01-02 15:04:05"),
-				},
-			},
-		})
-	}
+	//for date := startTime; date.Before(nowTime); date = date.Add(24 * time.Hour) {
+	//	start := time.Date(date.Year(), date.Month(), date.Day(), locationModel.StartTime, 0, 0, 0, date.Location())
+	//	end := time.Date(date.Year(), date.Month(), date.Day(), locationModel.EndTime, 0, 0, 0, date.Location())
+	//
+	//	filters = append(filters, map[string]interface{}{
+	//		"range": map[string]interface{}{
+	//			"picDate": map[string]interface{}{
+	//				"gte": start.Format("2006-01-02 15:04:05"),
+	//				"lte": end.Format("2006-01-02 15:04:05"),
+	//			},
+	//		},
+	//	})
+	//}
 	//logger.Debugf("filters--------------------------------------- %s", filters)
 	query := map[string]interface{}{
 		"query": map[string]interface{}{
@@ -419,14 +419,14 @@
 		"size": 0,
 	}
 
-	query = map[string]interface{}{
-		"query": map[string]interface{}{
-			"bool": map[string]interface{}{
-				"filter": filters,
-			},
-		},
-		"size": 10000,
-	}
+	//query = map[string]interface{}{
+	//	"query": map[string]interface{}{
+	//		"bool": map[string]interface{}{
+	//			"filter": filters,
+	//		},
+	//	},
+	//	"size": 10000,
+	//}
 	if err := json.NewEncoder(&buf).Encode(query); err != nil {
 		return nil, fmt.Errorf("error encoding query: %s", err)
 	}
@@ -458,79 +458,81 @@
 	var records []*LocationRecord
 	//dat, ok := result["hits"].(map[string]interface{})
 
-	dat := result["hits"].(map[string]interface{})
-
-	var data = make(map[string]interface{}, 2)
-
-	tmp, b := dat["total"].(map[string]interface{})
-	if b != true {
-		data["total"] = dat["total"].(float64)
-	} else {
-		data["total"] = tmp["value"].(float64)
-	}
-	sources := []interface{}{}
-	for _, value := range dat["hits"].([]interface{}) {
-		sourceData := value.(map[string]interface{})
-		source := sourceData["_source"].(map[string]interface{})
-		source["_id"] = sourceData["_id"]
-		/*sdkType := source["sdkType"]
-		if sdkType != nil {
-			sdk, _ := strconv.Atoi(sdkType.(string))
-			source["sdkType"] = sdkTypeToValue(sdk)
-		}*/
-		sources = append(sources, source)
-	}
-	data["datalist"] = sources
-	logger.Debugf("ressss--------------data------------------------- %s", data)
-	//if aggs, ok := result["aggregations"].(map[string]interface{}); ok {
-	//	if orgBuckets, ok := aggs["orgs"].(map[string]interface{})["buckets"].([]interface{}); ok {
-	//		for _, orgBucket := range orgBuckets {
-	//			orgId := orgBucket.(map[string]interface{})["key"].(string)
-	//			logger.Debugf("orgId--------------------------------------- %s", orgId)
-	//			// 瑙f瀽鎸塩ommunityId鐨勮仛鍚堢粨鏋�
-	//			if communityBuckets, ok := orgBucket.(map[string]interface{})["community"].(map[string]interface{})["buckets"].([]interface{}); ok {
-	//				for _, communityBucket := range communityBuckets {
-	//					communityId := communityBucket.(map[string]interface{})["key"].(string)
-	//					logger.Debugf("communityId--------------------------------------- %s", communityId)
-	//					// 瑙f瀽鎸塨uilding鐨勮仛鍚堢粨鏋�
-	//					if locationBuckets, ok := communityBucket.(map[string]interface{})["location"].(map[string]interface{})["buckets"].([]interface{}); ok {
-	//						for _, locationBucket := range locationBuckets {
-	//							building := locationBucket.(map[string]interface{})["key"].(string)
-	//							logger.Debugf("building--------------------------------------- %s", building)
-	//							// 瑙f瀽鎸塮loor鐨勮仛鍚堢粨鏋�
-	//							if floorBuckets, ok := locationBucket.(map[string]interface{})["floor"].(map[string]interface{})["buckets"].([]interface{}); ok {
-	//								for _, floorBucket := range floorBuckets {
-	//									floor := floorBucket.(map[string]interface{})["key"].(string)
-	//									appearCount := floorBucket.(map[string]interface{})["filter_floor"].(int)
-	//									// 鏋勫缓 LocationRecord 缁撴瀯浣�
-	//									var persons []string
-	//									if docNumBuckets, ok := floorBucket.(map[string]interface{})["document_numbers"].(map[string]interface{})["buckets"].([]interface{}); ok {
-	//										for _, docNumBucket := range docNumBuckets {
-	//											persons = append(persons, docNumBucket.(map[string]interface{})["key"].(string))
-	//										}
-	//									}
+	//dat := result["hits"].(map[string]interface{})
 	//
-	//									logger.Debugf("floor--------------------------------------- %s-- %s --", floor, appearCount)
-	//									record := &LocationRecord{
-	//										//PicDate:        timestamp,
-	//										DocumentNumbers: persons,
-	//										CommunityId:     communityId,
-	//										Building:        building,
-	//										Floor:           floor,
-	//										OrgId:           orgId,
-	//										AppearCount:     appearCount,
-	//									}
+	//var data = make(map[string]interface{}, 2)
 	//
-	//									records = append(records, record)
-	//								}
-	//							}
-	//						}
-	//					}
-	//				}
-	//			}
-	//		}
-	//	}
+	//tmp, b := dat["total"].(map[string]interface{})
+	//if b != true {
+	//	data["total"] = dat["total"].(float64)
+	//} else {
+	//	data["total"] = tmp["value"].(float64)
 	//}
+	//sources := []interface{}{}
+	//for _, value := range dat["hits"].([]interface{}) {
+	//	sourceData := value.(map[string]interface{})
+	//	source := sourceData["_source"].(map[string]interface{})
+	//	source["_id"] = sourceData["_id"]
+	//	/*sdkType := source["sdkType"]
+	//	if sdkType != nil {
+	//		sdk, _ := strconv.Atoi(sdkType.(string))
+	//		source["sdkType"] = sdkTypeToValue(sdk)
+	//	}*/
+	//	sources = append(sources, source)
+	//}
+	//data["datalist"] = sources
+	//logger.Debugf("ressss--------------data------------------------- %s", data)
+	if aggs, ok := result["aggregations"].(map[string]interface{}); ok {
+		if orgBuckets, ok := aggs["orgs"].(map[string]interface{})["buckets"].([]interface{}); ok {
+			for _, orgBucket := range orgBuckets {
+				orgId := orgBucket.(map[string]interface{})["key"].(string)
+				logger.Debugf("orgId--------------------------------------- %s", orgId)
+				// 瑙f瀽鎸塩ommunityId鐨勮仛鍚堢粨鏋�
+				if communityBuckets, ok := orgBucket.(map[string]interface{})["community"].(map[string]interface{})["buckets"].([]interface{}); ok {
+					for _, communityBucket := range communityBuckets {
+						communityId := communityBucket.(map[string]interface{})["key"].(string)
+						logger.Debugf("communityId--------------------------------------- %s", communityId)
+						// 瑙f瀽鎸塨uilding鐨勮仛鍚堢粨鏋�
+						if locationBuckets, ok := communityBucket.(map[string]interface{})["location"].(map[string]interface{})["buckets"].([]interface{}); ok {
+							for _, locationBucket := range locationBuckets {
+								building := locationBucket.(map[string]interface{})["key"].(string)
+								logger.Debugf("building--------------------------------------- %s", building)
+								// 瑙f瀽鎸塮loor鐨勮仛鍚堢粨鏋�
+								if floorBuckets, ok := locationBucket.(map[string]interface{})["floor"].(map[string]interface{})["buckets"].([]interface{}); ok {
+									for _, floorBucket := range floorBuckets {
+										floor := floorBucket.(map[string]interface{})["key"].(string)
+										logger.Debugf("floor--------------------------------------- %s -----%s ", floor, floorBucket)
+										appearCount := floorBucket.(map[string]interface{})["filter_floor"].(int)
+										logger.Debugf("appearCount--------------------------------------- %s- --", appearCount)
+										// 鏋勫缓 LocationRecord 缁撴瀯浣�
+										var persons []string
+										if docNumBuckets, ok := floorBucket.(map[string]interface{})["document_numbers"].(map[string]interface{})["buckets"].([]interface{}); ok {
+											for _, docNumBucket := range docNumBuckets {
+												persons = append(persons, docNumBucket.(map[string]interface{})["key"].(string))
+											}
+										}
+
+										//logger.Debugf("floor--------------------------------------- %s-- %s --", floor, appearCount)
+										record := &LocationRecord{
+											//PicDate:        timestamp,
+											DocumentNumbers: persons,
+											CommunityId:     communityId,
+											Building:        building,
+											Floor:           floor,
+											OrgId:           orgId,
+											AppearCount:     appearCount,
+										}
+
+										records = append(records, record)
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+	}
 
 	return records, nil
 }

--
Gitblit v1.8.0