| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "encoding/json" |
| | | "fmt" |
| | | "strconv" |
| | | "basic.com/valib/logger.git" |
| | | "strings" |
| | | "webserver/cache" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | |
| | | |
| | | err := c.BindJSON(&cam) |
| | | if err != nil { |
| | | logger.Debug("err:",err) |
| | | util.ResponseFormat(c, code.RequestParamError, "参数错误") |
| | | return |
| | | } |
| | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 将摄像机挂到指定的目录树下 |
| | | // @Description 将摄像机挂到指定的目录树下 |
| | | // @Accept x-www-form-urlencoded |
| | | // @Produce json |
| | | // @Tags camera |
| | | // @Param cameraId path string true "摄像机id" |
| | | // @Param areaId path string true "目录区域id" |
| | | // @Param cameraId formData string true "摄像机id" |
| | | // @Param areaId formData 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/cameraAreaAdd [get] |
| | | func (ac CameraController) CameraAreaAdd(c *gin.Context) { |
| | | cameraId := c.Param("cameraId") |
| | | areaId := c.Param("areaId") |
| | | fmt.Println(cameraId) |
| | | fmt.Println(areaId) |
| | | // @Router /data/api-v/camera/updateCameraArea [post] |
| | | func (ac CameraController) UpdateCameraArea(c *gin.Context) { |
| | | cameraId := c.PostForm("cameraId") |
| | | areaId := c.PostForm("areaId") |
| | | if cameraId == "" || areaId == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | var api dbapi.CameraApi |
| | | if api.UpdateCameraArea(cameraId, areaId) { |
| | | util.ResponseFormat(c,code.Success,"更新成功") |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"") |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 切换摄像机运行实时或轮询的开关 |
| | | // @Description 切换摄像机运行实时或轮询的开关 |
| | | // @Accept x-www-form-urlencoded |
| | | // @Produce json |
| | | // @Tags camera |
| | | // @Param cameraId formData string true "摄像机id" |
| | |
| | | func(cc CameraController) UpdateSnapshotUrl(c *gin.Context){ |
| | | cid := c.Param("cid") |
| | | //filename, err := service.UpdateSnapshotUrl(cid) |
| | | if cid == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | if strings.HasPrefix(cid, File_Video_Id_Pre) || strings.HasPrefix(cid, File_Img_Id_Pre) || strings.HasPrefix(cid, File_Audio_Id_Pre) { |
| | | var fileApi dbapi.FileAnalysisApi |
| | | b, d := fileApi.Show(cid) |
| | | if b { |
| | | var file protomsg.FileAnalysis |
| | | bytes, _ := json.Marshal(d) |
| | | err := json.Unmarshal(bytes, &file) |
| | | if err == nil { |
| | | util.ResponseFormat(c, code.Success, map[string]string{ |
| | | "cameraId": cid, |
| | | "snapshotUrl": file.SnapshotUrl, |
| | | }) |
| | | return |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "更新失败") |
| | | return |
| | | } |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "更新失败") |
| | | return |
| | | } |
| | | } |
| | | filename, err := service.UpdateCapture(cid) |
| | | if err != nil { |
| | | logger.Debug("UpdateSnapshotUrl.err:",err) |
| | | util.ResponseFormat(c, code.ComError, "更新失败") |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, filename) |
| | | util.ResponseFormat(c, code.Success, map[string]string{ |
| | | "cameraId": cid, |
| | | "snapshotUrl": filename, |
| | | }) |
| | | } |
| | | |
| | | type CameraChangeRunVo struct { |