From 6ca12f7771e4224464e73271dd47f040cbaf9d4b Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 13 十二月 2024 10:39:54 +0800
Subject: [PATCH] 查询任务只查有效期内的,开启的

---
 models/gather_model.go |   36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/models/gather_model.go b/models/gather_model.go
index 54e7626..5e13538 100644
--- a/models/gather_model.go
+++ b/models/gather_model.go
@@ -89,16 +89,19 @@
 		return err
 	}
 	event := strings.Join(typeNames, ",")
-	for location, persons := range aggregation {
+	for lt, persons := range aggregation {
 		result := &db.ModelTaskResults{
 			Title:       m.Task.Name,
 			Event:       fmt.Sprintf("%s/%d浜�", event, len(persons)),
 			ModelID:     m.Task.ModelID,
 			ModelTaskID: m.Task.ID,
-			CommunityId: location.CommunityId,
-			OrgID:       location.OrgId,
+			CommunityId: lt.CommunityId,
+			OrgID:       lt.OrgId,
 			ObjectIds:   strings.Join(persons.Elements(), ","),
-			Location:    location.Location,
+			Location:    lt.Location,
+			Building:    lt.Building,
+			Floor:       lt.Floor,
+			PicDate:     lt.Time,
 		}
 		results = append(results, result)
 	}
@@ -225,6 +228,19 @@
 															},
 														},
 													},
+													"frequency_filter": map[string]interface{}{ // 娣诲姞棰戠巼杩囨护
+														"bucket_selector": map[string]interface{}{
+															"buckets_path": map[string]interface{}{
+																"eventCount": "_count", // 鑱氬悎浜嬩欢娆℃暟
+															},
+															"script": map[string]interface{}{
+																"source": "params.eventCount >= params.threshold", // 绛涢�夐鐜囪揪鍒伴槇鍊肩殑浜嬩欢
+																"params": map[string]interface{}{
+																	"threshold": gatherModel.Threshold,
+																},
+															},
+														},
+													},
 												},
 											},
 										},
@@ -292,7 +308,7 @@
 										if gatherEvents, ok := floorBucket.(map[string]interface{})["gather_events"].(map[string]interface{})["buckets"].([]interface{}); ok {
 											for _, eventBucket := range gatherEvents {
 												key := int64(eventBucket.(map[string]interface{})["key"].(float64)) / 1000 // 灏嗘绉掕浆鎹负绉�
-												timestamp := time.Unix(key, 0).Format("2006-01-02T15:04:05")
+												timestamp := time.Unix(key, 0).UTC().Format("2006-01-02 15:04:05")
 
 												// 瑙f瀽浜哄憳
 												if peopleBuckets, ok := eventBucket.(map[string]interface{})["people"].(map[string]interface{})["buckets"].([]interface{}); ok {
@@ -329,16 +345,17 @@
 	return records, nil
 }
 
-type GatherLocation struct {
+type GatherLocationTime struct {
 	CommunityId string
 	OrgId       string
 	Building    string
 	Floor       string
 	Location    string
+	Time        string
 }
 
-func analyzeAndAggregate(records []GatherRecord) (map[GatherLocation]set.StringSet, error) {
-	aggregation := make(map[GatherLocation]set.StringSet)
+func analyzeAndAggregate(records []GatherRecord) (map[GatherLocationTime]set.StringSet, error) {
+	aggregation := make(map[GatherLocationTime]set.StringSet)
 	domainIds := set.NewStringSet()
 	for _, record := range records {
 		domainIds.Add(record.CommunityId)
@@ -354,12 +371,13 @@
 			continue
 		}
 
-		location := GatherLocation{
+		location := GatherLocationTime{
 			CommunityId: record.CommunityId,
 			OrgId:       record.OrgId,
 			Building:    record.Building,
 			Floor:       record.Floor,
 			Location:    fmt.Sprintf("%s%s%s", domains[record.CommunityId].Name, record.Building, record.Floor),
+			Time:        record.PicDate,
 		}
 		if aggregation[location] == nil {
 			aggregation[location] = set.NewStringSet()

--
Gitblit v1.8.0