From e0ac037f3d30e5fe50c884789eef97746a9e990f Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期一, 10 二月 2025 10:37:15 +0800 Subject: [PATCH] 测试 场景分析 bug --- models/locationAnalysis.go | 57 ++++++++++++++++++++++++--------------------------------- 1 files changed, 24 insertions(+), 33 deletions(-) diff --git a/models/locationAnalysis.go b/models/locationAnalysis.go index 8ef8747..6e7fdc0 100644 --- a/models/locationAnalysis.go +++ b/models/locationAnalysis.go @@ -285,8 +285,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{} @@ -327,44 +327,34 @@ } filters = append(filters, addrParams) } - - //// 閲嶇偣浜哄憳杩囨护 - //if len(locationModel.KeyPersonType) > 0 { + //var queryTimes []map[string]interface{} + //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()) + // + // //queryTimes = append(queryTimes, map[string]interface{}{ + // // "range": map[string]interface{}{ + // // "picDate": map[string]interface{}{ + // // "gte": start.Format(time.DateTime), // "2006-01-02 15:04:05d" + // // "lte": end.Format(time.DateTime), + // // }, + // // }, + // //}) + // // filters = append(filters, map[string]interface{}{ - // "terms": map[string]interface{}{ - // "keyPersonType": strings.Split(locationModel.KeyPersonType, ","), + // "range": map[string]interface{}{ + // "picDate": map[string]interface{}{ + // "gte": start.Format(time.DateTime), + // "lte": end.Format(time.DateTime), + // }, // }, // }) //} - - // 鏃堕棿鑼冨洿 //filters = append(filters, map[string]interface{}{ - // "range": map[string]interface{}{ - // "picDate": map[string]interface{}{ - // "gte": start.Format(time.DateTime), - // "lt": now.Format(time.DateTime), - // }, + // "bool": map[string]interface{}{ + // "filter": queryTimes, // }, //}) - var queryTimes []map[string]interface{} - 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()) - - queryTimes = append(queryTimes, map[string]interface{}{ - "range": map[string]interface{}{ - "picDate": map[string]interface{}{ - "gte": start.Format(time.DateTime), // "2006-01-02 15:04:05d" - "lte": end.Format(time.DateTime), - }, - }, - }) - } - filters = append(filters, map[string]interface{}{ - "bool": map[string]interface{}{ - "should": queryTimes, - }, - }) logger.Debugf("filters--------------------------------------- %s", filters) query := map[string]interface{}{ "query": map[string]interface{}{ @@ -454,6 +444,7 @@ if err := json.NewDecoder(res.Body).Decode(&result); err != nil { return nil, fmt.Errorf("error parsing response body: %s", err) } + logger.Debugf("result--------------------------------------- %s", result) // 瑙f瀽鑱氬悎缁撴灉 var records []*LocationRecord if aggs, ok := result["aggregations"].(map[string]interface{}); ok { -- Gitblit v1.8.0