zhangzengfei
2024-09-06 6175e68385dad8242ae92511f15f8a44abb009ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package task
 
import (
    "basic.com/valib/logger.git"
    "ruleModelEngine/cache"
    "ruleModelEngine/db"
    "time"
)
 
func UnderageClimbingToRooftop(taskPerson db.TaskPerson) bool {
    if taskPerson.Floor == "" {
        return false
    }
    age, err := db.GetAgeById(taskPerson.DocumentNumber)
    if err != nil {
        logger.Error("GetAgeById: ", err)
        return false
    }
    floor, _ := extractFloorNumber(taskPerson.Floor)
    if age <= 16 && floor == cache.Device[taskPerson.CameraId].MaxBuildingFloor && taskPerson.TargetType == "body" {
        return true
    }
    return false
}
func UnderageEnteringCommercialBuilding(taskPerson db.TaskPerson) bool {
    age, err := db.GetAgeById(taskPerson.DocumentNumber)
    if err != nil {
        logger.Error("GetAgeById: ", err)
        return false
    }
    //floor, _ := extractFloorNumber(taskPerson.Floor)
    if age <= 16 && taskPerson.TargetType == "face" && cache.Device[taskPerson.CameraId].BuildingType == db.BuildingTypeMixedUse {
        return true
    }
    return false
}
func ClimbingFloorsIllegally(taskPerson db.TaskPerson, hours int, times int) bool {
    layout := "2006-01-02 15:04:05"
    picDate, err := time.Parse(layout, taskPerson.PicDate)
    startTime := picDate.Add(time.Duration(-hours) * time.Hour).Format(layout)
    floors, err := db.QueryCheckDataByDocumentNumber(taskPerson.DocumentNumber, startTime, taskPerson.PicDate)
    if err != nil {
        logger.Error("QueryCheckDataByDocumentNumber: ", err)
        return false
    }
    if floors >= times {
        return true
    }
    return false
}
 
func EnteringButNotLeaving(docNumber string, communityId string, cameraIds []string, days int) bool {
    total, err := db.QueryTimesByDocNumberDays(docNumber, communityId, cameraIds, days-1)
    if err != nil {
        logger.Error("QueryTimesByDocNumberDays err: ", err)
    }
    if total == 0 {
        return true
    }
 
    return false
}
 
func registeredAddressNotMatchActualResidence(taskPerson db.TaskPerson) bool {
    idCard := db.GetIdCardById(taskPerson.DocumentNumber)
    if idCard == "" {
        return false
    }
 
    if _, ok := cache.PublicHouse[taskPerson.CommunityId]; !ok {
        return false
    }
 
    // 有身份证号, 小区属于公租房, 公租房登记身份证号没有该条记录, 返回true
    personStatus := db.GetDBPersonStatus(taskPerson.DocumentNumber, taskPerson.CommunityId)
    logger.Debugf("Actual residence get person id:%s status: %s", taskPerson.DocumentNumber, personStatus)
    if personStatus == "resident" || personStatus == "permanent_resident" {
        if _, ok := cache.PublicHouse[taskPerson.CommunityId][idCard]; !ok {
            // 控制程序运行期间只输出一次报警
            if _, ok := cache.PublicHouseAlarmCache[idCard]; ok {
                return false
            } else {
                cache.PublicHouseAlarmCache[idCard] = struct{}{}
                return true
            }
        }
    }
 
    return false
}