zhaoqingang
2025-02-08 def7497d1fb46430053f103ba9e1ea1a8a06e25c
models/locationAnalysis.go
@@ -28,6 +28,7 @@
   KeyPersonType  string       // 人员类型
   PersonLabel    string       // 人员标签
   PersonIdentity []string     // 人员身份
   KeyTypes       []string     // 人员身份
   Duration       int          // 时间范围
   Appearances    int          // 出现次数,
   StartTime      int          // 时间范围, 开始时间
@@ -54,10 +55,18 @@
   m.Building = task.Building
   m.AlarmType = task.AlarmType
   m.PersonIdentity = []string{"stranger", "visitor", "resident"} //task.IdentityType
   m.KeyTypes = []string{"1", "2", "3", "4", "5"}                 //task.IdentityType
   m.KeyPersonType = task.PersonType
   m.PersonLabel = task.PersonLabel
   if task.IdentityType != "" {
      m.PersonIdentity = strings.Split(task.IdentityType, ",")
   }
   if task.PersonType != "" {
      m.KeyTypes = strings.Split(task.PersonType, ",")
   }
   if len(m.AreaIds) == 0 {
      m.AreaIds = m.OrgIds
   }
   for _, v := range task.Rules {
      if v.Alias == "appearances" {
@@ -124,42 +133,37 @@
   // 根据配置的时间段天数, 每天的时间范围内, 重点人员类型或者特定标签人员出现的楼层次数超过阈值
   results := make([]*db.ModelTaskResults, 0)
   var baseFilter, labelFilter, keyFilter, lastFilter []LocationPersonInfo
   var document_number_map map[string]LocationPersonInfo
   var baseFilter, labelFilter, keyFilter []LocationPersonInfo
   var document_number_map = make(map[string]LocationPersonInfo)
   var document_number_list []string
   err := db.GetDB().Raw(`
      SELECT
          p.id,
         s.document_number,
--          s.community_id,
--          s.org_id,
--          p.person_name,
--          p.id_card,
         s.last_appearance_time,
--          s.last_direction,
--          s.last_location
         s.last_appearance_time
      FROM
         snapshot_count_summary AS s
         JOIN person AS p ON p.id = s.document_number
      WHERE
         p.id_card != "" 
         AND (p.community_id IN ?
         OR p.org_id IN ?)
         AND p.status IN ?
         AND (s.community_id IN ? OR s.org_id IN ?)
         AND s.status IN ?
      `, m.AreaIds, m.OrgIds, m.PersonIdentity).Scan(&baseFilter).Error
   if err != nil {
      logger.Warnf(err.Error())
   }
   if len(baseFilter) == 0 {
      return fmt.Errorf("no results found that match the age condition %s - %s ", m.AreaIds, m.OrgIds)
      return fmt.Errorf("no results found that match the age condition %s - %s - %s ", m.AreaIds, m.OrgIds, m.PersonIdentity)
   }
   logger.Debugf("task %s match age result %d", m.Task.Name, len(baseFilter))
   for _, i := range baseFilter {
      if _, ok := document_number_map[i.DocumentNumber]; !ok {
         document_number_list = append(document_number_list, i.DocumentNumber)
         tmp := i
         document_number_map[i.DocumentNumber] = tmp
      }
      document_number_map[i.DocumentNumber] = i
   }
   if m.PersonLabel != "" {
      labels := strings.Split(m.PersonLabel, ",")
@@ -182,17 +186,14 @@
      }
      logger.Debugf("task %s match label result %d", m.Task.Name, len(labelFilter))
      document_number_list = []string{}
      for _, i := range labelFilter {
         document_number_list = append(document_number_list, i.Id)
         document_number_list = append(document_number_list, i.Id)
      }
   }
   document_number_list = []string{}
   for _, i := range labelFilter {
      document_number_list = append(document_number_list, i.Id)
   }
   if m.KeyPersonType != "" {
      keyTypes := strings.Split(m.KeyPersonType, ",")
   if len(m.KeyTypes) > 0 {
      //keyTypes := strings.Split(m.KeyPersonType, ",")
      err := db.GetDB().Raw(`
      SELECT
         p.id,
@@ -203,18 +204,16 @@
      WHERE
         p.id IN ?
         AND k.person_type IN ?
      `, m.StartTime, keyTypes).Scan(&keyFilter).Error
      `, document_number_list, m.KeyTypes).Scan(&keyFilter).Error
      if err != nil {
         logger.Warnf(err.Error())
      }
      if len(keyFilter) == 0 {
         return fmt.Errorf("no results found that match the key condition %s", m.KeyPersonType)
         return fmt.Errorf("no results found that match the key condition%s------ %s", document_number_list, m.KeyTypes)
      }
      logger.Debugf("task %s match key person result %d", m.Task.Name, len(keyFilter))
   }
   logger.Debugf("task %s last result %d", m.Task.Name, len(lastFilter))
   //logger.Debugf("task %s last result %d", m.Task.Name, len(lastFilter))
   document_number_list = []string{}
   for _, i := range keyFilter {
      document_number_list = append(document_number_list, i.Id)
@@ -346,8 +345,8 @@
      filters = append(filters, map[string]interface{}{
         "range": map[string]interface{}{
            "picDate": map[string]interface{}{
               "gte": start.Format(time.RFC3339),
               "lte": end.Format(time.RFC3339),
               "gte": start.Format("2006-01-02 15:04:05"),
               "lte": end.Format("2006-01-02 15:04:05"),
            },
         },
      })