| | |
| | | ModelId: ModelIdDisappear, |
| | | Scope: "", |
| | | RuleArg: RuleArg{ |
| | | Alias: "age", |
| | | Alias: "lastDirection", |
| | | Name: "进出方向", |
| | | Type: "input", |
| | | Must: false, |
| | |
| | | DisappearTime int // 消失时间, 单位小时 |
| | | AlarmInterval int // 报警时间间隔, 单位天 |
| | | LastDirection string // 最后一次抓拍 |
| | | PersonAge int // 年龄 |
| | | MaxAge string // 年龄 |
| | | MinAge string // 年龄 |
| | | Task *db.ModelTask |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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 = ages[0] |
| | | m.MaxAge = ages[1] |
| | | } |
| | | } |
| | | |
| | |
| | | results := make([]*db.ModelTaskResults, 0) |
| | | var ageFilter, labelFilter, keyFilter, lastFilter []PersonInfo |
| | | |
| | | if m.PersonAge > 0 { |
| | | if m.MinAge != "" { |
| | | err := db.GetDB().Raw(` |
| | | SELECT |
| | | s.document_number, |
| | |
| | | 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)) |
| | |
| | | } |
| | | |
| | | // 合并一下条件 |
| | | if m.PersonAge > 0 && m.PersonLabel != "" { |
| | | if m.MinAge != "" && m.PersonLabel != "" { |
| | | lastFilter = intersectPersonInfo(ageFilter, labelFilter) |
| | | } else if m.PersonAge > 0 { |
| | | } else if m.MinAge != "" { |
| | | lastFilter = ageFilter |
| | | } else if m.PersonLabel != "" { |
| | | lastFilter = labelFilter |