qixiaoning
2025-07-25 94f3085afd10d76fa6e0640b5eed1d615b11ecea
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package util
 
import (
    "basic.com/pubsub/protomsg.git"
)
 
type BaseCompareInfo struct {
    TableId      string  `json:"tableId"`
    TableName    string  `json:"tableName"`
    BwType       string  `json:"bwType"`
    CompareScore float64 `json:"compareScore"`
    TargetId     string  `json:"targetId"`
    TargetName   string  `json:"targetName"`
    TargetPicUrl string  `json:"targetPicUrl"`
    MonitorLevel string  `json:"monitorLevel"`
    Content      string  `json:"content"`
    DbLabel      string  `json:"labels"`
}
 
type AlarmRule struct {
    GroupId      string `json:"groupId"`
    AlarmLevel   string `json:"alarmLevel"`
    RuleText     string `json:"ruleText"`
    DefenceState bool   `json:"defenceState"`
    LinkInfo     string `json:"linkInfo"`
}
 
type Point struct {
    X float64 `json:"x"`
    Y float64 `json:"y"`
}
 
type Points struct {
    TopLeft     Point `json:"topLeft"`
    BottomRight Point `json:"bottomRight"`
}
 
type TargetInfo struct {
    TargetId        string  `json:"targetId"`
    AreaId          string  `json:"areaId"`
    AreaName        string  `json:"areaName"`
    TargetScore     float64 `json:"targetScore"`
    TargetType      string  `json:"targetType"`
    Feature         string  `json:"feature"`
    PicSmUrl        string  `json:"picSmUrl"`
    TargetLocation  Points  `json:"targetLocation"`
    BelongsTargetID string  `json:"belongsTargetId"`
    Attribute       string  `json:"attribute"`
}
 
//type Target struct {
//    TargetInfo
//    AttachTarget TargetInfo `json:"attachTarget"`
//}
 
//type GroupRuleResult struct {
//    AlarmRules AlarmRule `json:"alarmRules"`
//    PicDate    string    `json:"picDate"`
//    PicMaxUrl  string    `json:"picMaxUrl"`
//}
 
type PicWidHei struct {
    PicW int `json:"picW"`
    PicH int `json:"picH"`
}
 
type TaskResultInfo struct {
    Id              string             `json:"id"`
    CameraId        string             `json:"cameraId"`
    CameraAddr      string             `json:"cameraAddr"`
    CameraName      string             `json:"cameraName"`
    PicDate         string             `json:"picDate"`
    PicId           int64              `json:"picId"`
    PicMaxUrl       []string           `json:"picMaxUrl"`
    PicWH           PicWidHei          `json:"picWH"`
    TaskId          string             `json:"taskId"`
    TaskName        string             `json:"taskName"`
    SdkName         string             `json:"sdkName"`
    Content         string             `json:"content"`
    AlarmRules      []AlarmRule        `json:"alarmRules"`
    LikeDate        string             `json:"likeDate"`
    ShowLabels      string             `json:"showLabels"`
    OtherLabels     string             `json:"otherLabels"`
    VideoUrl        string             `json:"videoUrl"`
    AnalyServerId   string             `json:"analyServerId"`
    AnalyServerName string             `json:"analyServerName"`
    AnalyServerIp   string             `json:"analyServerIp"`
    ClusterId       string             `json:"clusterId"`
    IsAlarm         bool               `json:"isAlarm"`
    IsAckAlarm      bool               `json:"isAckAlarm"`
    IsCollect       bool               `json:"isCollect"`
    IsDelete        bool               `json:"isDelete"`
    BaseInfo        []*BaseCompareInfo `json:"baseInfo"`
    TargetInfo      []TargetInfo       `json:"targetInfo"`
    FileId          string             `json:"fileId"`     // 数据栈文件id
    DataSource      string             `json:"dataSource"` // 数据来源:摄像机, 数据栈
}
 
//  统一的数据结构
type ESInfo struct {
    TaskResultInfo
    Version     string            `json:"version"`
    UpdateTime  string            `json:"updateTime"`
    LinkTag     string            `json:"linkTag"`
    LinkTagInfo []*TaskResultInfo `json:"linkTagInfo"`
}
 
////so处理后的target
//type SoTarget struct {
//    SrcTarget protomsg.Target
//    BelongsTargetID string
//}
 
type TaskBasicInfo struct {
    CamId       string
    CamName     string
    TaskID      string
    TaskName    string
    HandleTime  string
    ImageId     int64
    ImageTime   string
    IsEndRecord bool
    FileId      string // 数据栈中的文件id
}
 
//缓存数据信息
type CacheInfo struct {
    TBI TaskBasicInfo
 
    RuleGroup   *protomsg.GroupRule
    IsAlarm     bool
    AlarmResult *SOResult
    Image       *protomsg.Image
}
 
//SO处理后的结果
//做目标检测的(如人脸检测)IsEvent==false,且需要和底库比对,需要分成多个SOResult,每个SOResult包含一个AlarmTargets,可能多个CompDbinfo
//做目标检测的(如人脸检测)IsEvent==false,但不需要和底库比对,也需要分成多个SOResult,每个SOResult包含一个AlarmTargets,只是没有CompDbinfo
//不是目标检测IsEvent==true,不需要和底库比对,就只返回一个SOResult,可能包含多个AlarmTargets,但是没有CompDbinfo
type SOResult struct {
    IsEvent     bool
    IsEndRecord bool
    Targets     []SoTarget
    FirstImage  *protomsg.Image
    CacheImage  *protomsg.Image
    SoRule      *SoRule
    GroupRule   *protomsg.GroupRule
    SoType      string
}
 
type SoTarget struct {
    SrcTarget       protomsg.Target
    AreaId          string
    AreaName        string
    BelongsTargetID string
    CompDbInfo      []*BaseCompareInfo
    ImageId         int64
}
 
type EventCache struct {
    Targets    map[uint64]*SoTarget
    RuleGroups map[string]*protomsg.GroupRule
    Images     map[int64]*protomsg.Image
}
 
type TargetCache struct {
    Target     *SoTarget
    RuleGroups map[string]*protomsg.GroupRule
    Image      *protomsg.Image
}
 
type RuleMessage struct {
    BaseInfo TaskBasicInfo
    Events   map[string]EventCache
    Targets  map[string]TargetCache
}
 
type RuleParams struct {
    SdkArgAlias  string
    Operator     string
    OperatorType string
    SdkArgValue  string
}
 
type SoRule struct {
    Id           string
    CameraId     string
    PolygonId    string
    SdkId        string
    Sort         int32
    RuleWithPre  string
    IsSaveAnyhow bool
    GroupId      string
    Params       []RuleParams
}
 
var AlarmLevelMap = map[int32]string{
    0: "撤防",
    1: "一级",
    2: "二级",
    3: "三级",
    4: "四级",
    5: "五级",
    6: "撤防",
}
 
func ParamRestrict(src, min, max, def int32) int32 {
    if min <= src && src <= max {
        return src
    }
    return def
}