sunty
2020-08-20 9d88c7c467f8d93af4aab9ba0b6d6c01c2ffc546
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
package controllers
 
import (
    "basic.com/dbapi.git"
    "basic.com/valib/logger.git"
    "github.com/gin-gonic/gin"
    "webserver/extend/code"
    "webserver/extend/util"
    "webserver/vo"
)
 
type CameraRuleController struct {
 
}
 
type PasteRuleArg struct {
    SourceId string `json:"sourceId" binding:"required"`
    TargetIds []string `json:"targetIds" binging:"required"`
}
 
// @Security ApiKeyAuth
// @Summary 显示摄像机场景规则
// @Description 显示摄像机场景规则
// @Accept json
// @Produce json
// @Tags 摄像机规则
// @Param cameraId query string true "摄像机id"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/rule/findByCameraId [get]
func (crc CameraRuleController) FindByCameraId(c *gin.Context) {
    cameraId := c.Query("cameraId")
    if cameraId == "" {
        util.ResponseFormat(c,code.RequestParamError,"")
        return
    }
    var api dbapi.CameraRuleApi
    b,d := api.FindByCameraId(cameraId)
    logger.Debug("b:", b, d)
    if b {
        util.ResponseFormat(c,code.Success,d)
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}
 
// @Security ApiKeyAuth
// @Summary 保存摄像机独立规则
// @Description 保存摄像机独立规则
// @Accept json
// @Produce json
// @Tags 摄像机规则
// @Param args body vo.GroupRuleVo true "独立规则参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/rule/save [post]
func (crc CameraRuleController) Save(c *gin.Context) {
    var reqBody vo.GroupRuleVo
    err := c.BindJSON(&reqBody)
    if err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"")
        return
    }
    param := util.Struct2Map(reqBody)
    var api dbapi.CameraRuleApi
    b,d := api.Save(param)
    if b {
        util.ResponseFormat(c,code.Success,"")
    } else {
        util.ResponseFormat(c,code.ComError,d)
    }
}
 
// @Security ApiKeyAuth
// @Summary 复制摄像机规则到选定的多个摄像机
// @Description 复制摄像机规则到选定的多个摄像机
// @Accept json
// @Produce json
// @Tags 摄像机规则
// @Param args body controllers.PasteRuleArg true "规则复制参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/pasteRules [post]
func (crc CameraRuleController) PasteRules(c *gin.Context) {
    var reqBody PasteRuleArg
    err := c.BindJSON(&reqBody)
    if err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"")
        return
    }
    param := util.Struct2Map(reqBody)
    var api dbapi.CameraRuleApi
    if api.PasteRules(param) {
        util.ResponseFormat(c,code.Success,"")
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}
 
// @Security ApiKeyAuth
// @Summary 保存联动任务规则参数
// @Description 保存联动任务规则参数
// @Accept json
// @Produce json
// @Tags 摄像机规则
// @Param saveBody body vo.GroupRuleVo true "联动任务规则保存参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/rule/saveLinkRulesByGroup [post]
func (crc CameraRuleController) SaveLinkRulesByGroup(c *gin.Context) {
    var saveBody vo.GroupRuleVo
    if err := c.BindJSON(&saveBody);err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    param := util.Struct2Map(saveBody)
    var api dbapi.CameraRuleApi
    b,d := api.SaveLinkRulesByGroup(param)
    if b {
        util.ResponseFormat(c,code.Success, d)
    } else {
        util.ResponseFormat(c,code.ComError, d)
    }
}
 
// @Security ApiKeyAuth
// @Summary 根据多个摄像机id查询联动任务规则设置
// @Description 根据多个摄像机id查询联动任务规则设置
// @Accept json
// @Produce json
// @Tags 摄像机规则
// @Param cameraIds body vo.MultiCamera true "摄像机ids"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/rule/getLinkRulesByCameraIds [post]
func (crc CameraRuleController) GetLinkRulesByCameraIds(c *gin.Context) {
    var idArrVo vo.MultiCamera
    if err := c.BindJSON(&idArrVo);err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    if idArrVo.CameraIds == nil || len(idArrVo.CameraIds) == 0 {
        util.ResponseFormat(c,code.RequestParamError,"摄像机id不能少于1")
        return
    }
    param := util.Struct2Map(idArrVo)
    var api dbapi.CameraRuleApi
    flag, ruleList := api.GetLinkRulesByCameraIds(param)
    if flag {
        util.ResponseFormat(c,code.Success, ruleList)
    } else {
        util.ResponseFormat(c,code.ComError,"查询失败")
    }
 
}
 
// @Security ApiKeyAuth
// @Summary 修改规则组报警等级
// @Description 修改规则组报警等级
// @Produce json
// @Tags 摄像机规则
// @Param reqBody body vo.GroupAlarmLevelVo true "参数"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/camera/rule/updateAlarmLevel [post]
func (crc CameraRuleController) UpdateAlarmLevel(c *gin.Context) {
    var reqBody vo.GroupAlarmLevelVo
    err := c.BindJSON(&reqBody)
    if err != nil {
        util.ResponseFormat(c,code.RequestParamError, "")
        return
    }
    param := util.Struct2Map(reqBody)
    var api dbapi.CameraRuleApi
    if api.UpdateAlarmLevel(param) {
        util.ResponseFormat(c, code.Success, "修改成功")//摄像机任务参数删除完了
    } else {
        util.ResponseFormat(c, code.ComError, "修改失败")
    }
}
 
// @Security ApiKeyAuth
// @Summary 根据分组id删除摄像机算法规则
// @Description 根据分组id删除摄像机算法规则
// @Produce json
// @Tags 摄像机规则
// @Param groupId path string true "任务算法参数分组id"
// @Success 200 {string} json "{"code":200, success:true, msg:"请求处理成功", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:"错误信息内容"}"
// @Router /data/api-v/camera/rule/deleteGroup/{groupId} [delete]
func (crc CameraRuleController) DeleteByGroup(c *gin.Context) {
    groupId := c.Param("groupId")
    if groupId == "" {
        util.ResponseFormat(c, code.RequestParamError, "id必填")
        return
    }
    var api dbapi.CameraRuleApi
    if api.DeleteByGroup(groupId) {
        util.ResponseFormat(c, code.Success, "删除成功")//摄像机任务参数删除完了
    } else {
        util.ResponseFormat(c, code.ComError, "删除失败")
    }
}