From e4fc307d58856a0b319c41f0930cd3b731cb0b24 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期二, 11 二月 2025 10:19:47 +0800
Subject: [PATCH] 修复规律分析bug

---
 models/accessRegularity.go |   37 ++++++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/models/accessRegularity.go b/models/accessRegularity.go
index 5d1b59b..286734c 100644
--- a/models/accessRegularity.go
+++ b/models/accessRegularity.go
@@ -114,10 +114,10 @@
 		FROM
 			snapshot_count_summary
 		WHERE
-			last_appearance_time > ? "" 
-			AND (p.community_id IN ?
-			OR p.org_id IN ?)
-			AND p.status IN ?
+			last_appearance_time > ?
+			AND (community_id IN ?
+			OR org_id IN ?)
+			AND status IN ?
 		`, startDate.Unix(), m.AreaIds, m.OrgIds, m.IdentityType).Scan(&baseFilter).Error
 	if err != nil {
 		logger.Warnf(err.Error())
@@ -174,10 +174,16 @@
 	return ""
 }
 
-func countValidDays(records []*service.ESRecordInfo, startHour, endHort int, direction string) int {
+func countValidDays(records []*service.ESRecordInfo, startHour, endHour int, direction string) int {
 	layout := "2006-01-02 15:04:05"             // 鏃堕棿鏍煎紡
 	lastDirectionMap := make(map[string]string) // 璁板綍鏈�鍚庝竴鏉� Direction
 	lastTimeMap := make(map[string]time.Time)   // 璁板綍鏈�鍚庝竴鏉℃椂闂�
+
+	// 鍒ゆ柇鏄惁璺ㄥぉ
+	var isCrossDay bool
+	if endHour < startHour {
+		isCrossDay = true
+	}
 
 	for _, record := range records {
 		// 瑙f瀽鏃堕棿
@@ -191,13 +197,22 @@
 		hour := t.Hour()
 		var key string
 
-		// 鍒ゆ柇鏃堕棿鑼冨洿锛屽苟褰掑睘鍒版煇涓�澶�
-		if hour >= startHour { // 21:00-23:59 褰掑睘褰撳ぉ
-			key = t.Format("2006-01-02")
-		} else if hour < endHort { // 00:00-02:59 褰掑睘鍓嶄竴澶�
-			key = t.AddDate(0, 0, -1).Format("2006-01-02")
+		if !isCrossDay {
+			// 鍒ゆ柇鏃堕棿鑼冨洿锛屽苟褰掑睘鍒版煇涓�澶�
+			if hour >= startHour && hour < endHour {
+				key = t.Format("2006-01-02")
+			} else {
+				continue // 涓嶅湪缁熻鑼冨洿鍐�
+			}
 		} else {
-			continue // 涓嶅湪缁熻鑼冨洿鍐�
+			// 鍒ゆ柇鏃堕棿鑼冨洿锛屽苟褰掑睘鍒版煇涓�澶�
+			if hour >= startHour { // 21:00-23:59 褰掑睘褰撳ぉ
+				key = t.Format("2006-01-02")
+			} else if hour < endHour { // 00:00-02:59 褰掑睘鍓嶄竴澶�
+				key = t.AddDate(0, 0, -1).Format("2006-01-02")
+			} else {
+				continue // 涓嶅湪缁熻鑼冨洿鍐�
+			}
 		}
 
 		// 璁板綍璇ユ椂闂存鍐呯殑鏈�鍚庝竴鏉℃暟鎹�

--
Gitblit v1.8.0