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, "删除失败")
|
}
|
}
|