zhangzengfei
2025-02-11 e4fc307d58856a0b319c41f0930cd3b731cb0b24
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 {
      // 解析时间
@@ -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 // 不在统计范围内
         }
      }
      // 记录该时间段内的最后一条数据