zhangzengfei
2024-12-20 dfd68d7befce08863c33c20fb5d1e17f62d65e01
models/disappear.go
@@ -3,6 +3,7 @@
import (
   "errors"
   "fmt"
   "strconv"
   "strings"
   "time"
@@ -21,7 +22,8 @@
   DisappearTime int    // 消失时间, 单位小时
   AlarmInterval int    // 报警时间间隔, 单位天
   LastDirection string // 最后一次抓拍
   PersonAge     int    // 年龄
   MaxAge        int    // 年龄
   MinAge        int    // 年龄
   Task          *db.ModelTask
}
@@ -52,8 +54,10 @@
      }
      if v.Alias == "age" {
         if val, ok := v.Value.(float64); ok {
            m.PersonAge = int(val)
         if val, ok := v.Value.(string); ok {
            ages := strings.Split(val, ",")
            m.MinAge, _ = strconv.Atoi(ages[0])
            m.MaxAge, _ = strconv.Atoi(ages[1])
         }
      }
@@ -90,7 +94,7 @@
   results := make([]*db.ModelTaskResults, 0)
   var ageFilter, labelFilter, keyFilter, lastFilter []PersonInfo
   if m.PersonAge > 0 {
   if m.MinAge > 0 {
      err := db.GetDB().Raw(`
      SELECT
         s.document_number,
@@ -110,14 +114,18 @@
         AND TIMESTAMPDIFF(
            YEAR,
            STR_TO_DATE( CASE WHEN LENGTH( id_card ) = 18 THEN SUBSTRING( id_card, 7, 8 ) ELSE NULL END, '%Y%m%d' ),
         CURDATE( ) > ?
      `, m.PersonAge).Scan(&ageFilter).Error
         CURDATE( ) >= ?
          AND TIMESTAMPDIFF(
            YEAR,
            STR_TO_DATE( CASE WHEN LENGTH( id_card ) = 18 THEN SUBSTRING( id_card, 7, 8 ) ELSE NULL END, '%Y%m%d' ),
         CURDATE( ) <= ?
      `, m.MinAge, m.MaxAge).Scan(&ageFilter).Error
      if err != nil {
         logger.Warnf(err.Error())
      }
      if len(ageFilter) == 0 {
         return fmt.Errorf("no results found that match the age condition %d", m.PersonAge)
         return fmt.Errorf("no results found that match the age condition %s - %s", m.MinAge, m.MaxAge)
      }
      logger.Debugf("match age result %d", len(ageFilter))
@@ -154,9 +162,9 @@
   }
   // 合并一下条件
   if m.PersonAge > 0 && m.PersonLabel != "" {
   if m.MinAge > 0 && m.PersonLabel != "" {
      lastFilter = intersectPersonInfo(ageFilter, labelFilter)
   } else if m.PersonAge > 0 {
   } else if m.MinAge > 0 {
      lastFilter = ageFilter
   } else if m.PersonLabel != "" {
      lastFilter = labelFilter