zhaoqingang
2025-02-19 12d094a193e190bedb1fcf35ac024eaec3c77e9f
merge
1个文件已删除
5个文件已修改
669 ■■■■ 已修改文件
db/db.go 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/accessRegularity.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/disappear.go 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/locationAnalysis.go 86 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/model.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/nightAnalysis.go 513 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/db.go
@@ -241,15 +241,15 @@
            Scope:   "",
            RuleArg: RuleArg{
                Alias:    "duration",
                Name:     "时间段",
                Name:     "监控时间",
                Type:     "input",
                Must:     false,
                Unit:     "天",
                Range:    "1,2400",
                Must:     true,
                Unit:     "天内",
                Range:    "1,60",
                Value:    "30",
                ValType:  "int",
                Operator: ">=",
                Sort:     2,
                Operator: "==",
                Sort:     1,
            },
        },
        {
@@ -257,16 +257,16 @@
            ModelId: ModelIdLocationAnalysis,
            Scope:   "",
            RuleArg: RuleArg{
                Alias:    "personCount",
                Name:     "出现人数",
                Type:     "input",
                Alias:    "timeRange",
                Name:     "出现时间",
                Type:     "range",
                Must:     true,
                Unit:     "个",
                Range:    "1,100",
                Value:    "1, 90",
                Unit:     "点",
                Range:    "0,23",
                Value:    "9,10",
                ValType:  "int",
                Operator: ">=",
                Sort:     0,
                Operator: "==",
                Sort:     2,
            },
        },
        {
@@ -278,12 +278,12 @@
                Name:     "出现次数",
                Type:     "input",
                Must:     true,
                Unit:     "",
                Unit:     "次",
                Range:    "",
                Value:    "",
                ValType:  "int",
                Operator: ">=",
                Sort:     1,
                Sort:     0,
            },
        },
models/accessRegularity.go
@@ -208,7 +208,7 @@
        if !isCrossDay {
            // 判断时间范围,并归属到某一天
            if hour >= startHour && hour <= endHour {
            if hour >= startHour && hour < endHour {
                key = t.Format("2006-01-02")
            } else {
                continue // 不在统计范围内
@@ -217,7 +217,7 @@
            // 判断时间范围,并归属到某一天
            if hour >= startHour { // 21:00-23:59 归属当天
                key = t.Format("2006-01-02")
            } else if hour <= endHour { // 00:00-02:59 归属前一天
            } else if hour < endHour { // 00:00-02:59 归属前一天
                key = t.AddDate(0, 0, -1).Format("2006-01-02")
            } else {
                continue // 不在统计范围内
models/disappear.go
@@ -84,6 +84,34 @@
    results := make([]*db.ModelTaskResults, 0)
    var ageFilter, labelFilter, keyFilter, lastFilter []PersonInfo
    if m.MinAge == 0 && m.PersonLabel == "" && m.KeyPersonType == "" {
        err := db.GetDB().Raw(`
        SELECT
            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
        FROM
            snapshot_count_summary AS s
            JOIN person AS p ON p.id = s.document_number
        WHERE
            s.last_appearance_time > ?
        `, m.StartTime).Scan(&lastFilter).Error
        if err != nil {
            logger.Warnf(err.Error())
        }
        if len(lastFilter) == 0 {
            return fmt.Errorf("no results found that match the condition %+v", m.Task.Rules)
        }
        logger.Debugf("task %s match default result %d", m.Task.Name, len(lastFilter))
    }
    if m.MinAge > 0 {
        err := db.GetDB().Raw(`
        SELECT
@@ -204,8 +232,7 @@
    for _, p := range lastFilter {
        if len(m.AreaIds) > 0 {
            _, o1 := m.AreaIds[p.CommunityId]
            _, o2 := m.AreaIds[p.OrgId]
            if !o1 && !o2 {
            if !o1 {
                continue
            }
        }
models/locationAnalysis.go
@@ -54,13 +54,22 @@
    m.AreaIds = areaIds
    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.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, ",")
        for _, t := range strings.Split(task.IdentityType, ",") {
            if t == "all" {
                m.PersonIdentity = []string{"stranger", "visitor", "resident"}
                break
            } else {
                m.PersonIdentity = append(m.PersonIdentity, t)
            }
        }
    } else {
        m.PersonIdentity = []string{"stranger", "visitor", "resident"}
    }
    if task.PersonType != "" {
        m.KeyTypes = strings.Split(task.PersonType, ",")
    }
@@ -112,33 +121,22 @@
}
type LocationPersonInfo struct {
    Id             string `json:"id"`
    DocumentNumber string `json:"document_number"`
    PersonType     string `json:"person_type"`
    //CommunityId        string `json:"community_id"`
    //OrgId              string `json:"org_id"`
    //PersonName         string `json:"person_name"`
    //IdCard             string `json:"id_card"`
    LastAppearanceTime int64 `json:"last_appearance_time"`
    //LastDirection      string `json:"last_direction"`
    //LastLocation       string `json:"last_location"`
    Id                 string `json:"id"`
    DocumentNumber     string `json:"document_number"`
    PersonType         string `json:"person_type"`
    LastAppearanceTime int64  `json:"last_appearance_time"`
}
//var (
//    processed        sync.Map                           // 存储已处理记录
//    cleanupThreshold = time.Now().Add(-100 * time.Hour) // 定义一个时间窗口,假设只保存最近100小时的记录
//)
func (m *LocationModel) Run() error {
    // 根据配置的时间段天数, 每天的时间范围内, 重点人员类型或者特定标签人员出现的楼层次数超过阈值
    results := make([]*db.ModelTaskResults, 0)
    var baseFilter, labelFilter, keyFilter []LocationPersonInfo
    var document_number_map = make(map[string]LocationPersonInfo)
    var document_number_list []string
    community_ids := m.AreaIds
    if len(community_ids) == 0 {
        community_ids = m.OrgIds
    var documentNumberMap = make(map[string]LocationPersonInfo)
    var documentNumberList []string
    communityIds := m.AreaIds
    if len(communityIds) == 0 {
        communityIds = m.OrgIds
    }
    err := db.GetDB().Raw(`
        SELECT
@@ -149,24 +147,23 @@
            snapshot_count_summary AS s
            JOIN person AS p ON p.id = s.document_number
        WHERE
            p.id_card != ""
            AND (s.community_id IN ? OR s.org_id IN ?)
            (s.community_id IN ? OR s.org_id IN ?)
            AND s.status IN ?
        `, community_ids, m.OrgIds, m.PersonIdentity).Scan(&baseFilter).Error
        `, communityIds, 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 - %s ", m.AreaIds, m.OrgIds, m.PersonIdentity)
        return fmt.Errorf("no results found that match the identity condition %+v", m.Task.Rules)
    }
    logger.Debugf("task %s match age result %d", m.Task.Name, len(baseFilter))
    logger.Debugf("task %s match identity 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)
        if _, ok := documentNumberMap[i.DocumentNumber]; !ok {
            documentNumberList = append(documentNumberList, i.DocumentNumber)
            tmp := i
            document_number_map[i.DocumentNumber] = tmp
            documentNumberMap[i.DocumentNumber] = tmp
        }
    }
    if m.PersonLabel != "" {
@@ -180,7 +177,7 @@
        WHERE
            p.id IN ?
            AND    l.label_id IN ?
        `, document_number_list, labels).Scan(&labelFilter).Error
        `, documentNumberList, labels).Scan(&labelFilter).Error
        if err != nil {
            logger.Warnf(err.Error())
        }
@@ -190,11 +187,12 @@
        }
        logger.Debugf("task %s match label result %d", m.Task.Name, len(labelFilter))
        document_number_list = []string{}
        documentNumberList = []string{}
        for _, i := range labelFilter {
            document_number_list = append(document_number_list, i.Id)
            documentNumberList = append(documentNumberList, i.Id)
        }
    }
    if len(m.KeyTypes) > 0 {
        //keyTypes := strings.Split(m.KeyPersonType, ",")
        err := db.GetDB().Raw(`
@@ -207,30 +205,30 @@
        WHERE
            p.id IN ?
            AND k.person_type IN ?
        `, document_number_list, m.KeyTypes).Scan(&keyFilter).Error
        `, documentNumberList, 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------ %s", document_number_list, m.KeyTypes)
            return fmt.Errorf("no results found that match the key condition %v------ %s", documentNumberList, 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))
    document_number_list = []string{}
    documentNumberList = []string{}
    for _, i := range keyFilter {
        //logger.Debugf("keyFilter %s ------------- %s", i.Id, i.PersonType)
        document_number_list = append(document_number_list, i.Id)
        person := document_number_map[i.Id]
        documentNumberList = append(documentNumberList, i.Id)
        person := documentNumberMap[i.Id]
        person.PersonType = i.PersonType
        document_number_map[i.Id] = person
        documentNumberMap[i.Id] = person
    }
    //logger.Debugf("document_number_map %s last result %s", m.Task.Name, document_number_map)
    records, err := queryEsLocation(db.GetEsClient(), m, document_number_list)
    records, err := queryEsLocation(db.GetEsClient(), m, documentNumberList)
    if err != nil {
        return err
    }
    logger.Debugf("records %s last result %+v", m.Task.Name, records)
    logger.Debugf("records %s last result %d", m.Task.Name, len(records))
    domains, err := domainToLocation(records)
    if err != nil {
        return err
@@ -240,8 +238,8 @@
    for _, record := range records {
        tagTypes = []string{}
        for _, personId := range record.DocumentNumbers {
            logger.Debugf("document_number_map[personId] %s", document_number_map[personId])
            tagTypes = append(tagTypes, document_number_map[personId].PersonType)
            logger.Debugf("document_number_map[personId] %+v", documentNumberMap[personId])
            tagTypes = append(tagTypes, documentNumberMap[personId].PersonType)
            //lastAppearanceTime = document_number_map[personId].LastAppearanceTime
        }
        //logger.Debugf("tagTypes %s ---------------%s--------", record.PicDate, record.DocumentNumbers)
models/model.go
@@ -16,8 +16,7 @@
var modelRegistry = map[string]func() Model{
    "gather":           func() Model { return &GatherModel{} },
    "disappear":        func() Model { return &DisappearModel{} },
    "location":         func() Model { return &LocationModel{} },
    "night":            func() Model { return &nightModel{} },
    "locationAnalysis": func() Model { return &LocationModel{} },
    "accessRegularity": func() Model { return &RegularityModel{} },
    // 添加其他模型
}
models/nightAnalysis.go
File was deleted