liuxiaolong
2019-10-26 eb2c3a8890a0e9695c0cd2bc3b3dc310c6fbcfa9
controllers/camera.go
@@ -4,7 +4,8 @@
   "encoding/json"
   "fmt"
   "strconv"
   "webserver/extend/logger"
   "basic.com/valib/logger.git"
   "webserver/cache"
   "github.com/gin-gonic/gin"
@@ -19,11 +20,12 @@
type CameraVo struct {
   Id        string  `json:"id"`
   Name      string  `json:"name"`
   Alias     string  `json:"alias"` //摄像机的别名
   Type      int     `json:"type" `
   Addr      string  `json:"addr"`
   Areaid    uint    `json:"areaid"`
   Longitude float64 `json:"longitude"`
   Latitude  float64 `json:"latitude"`
   Areaid    string  `json:"areaid"`
   Longitude float32 `json:"longitude"`
   Latitude  float32 `json:"latitude"`
   Rtsp      string  `json:"rtsp"`
   Ip        string  `json:"ip"`
   Port      int     `json:"port"`
@@ -56,10 +58,10 @@
      util.ResponseFormat(c, code.RequestParamError, "参数错误")
      return
   }
   cam.Id = util.PseudoUuid()
   paramBody := util.Struct2Map(cam)
   if api.CameraAdd(paramBody) {
      util.ResponseFormat(c, code.Success, cam)
   b, data := api.CameraAdd(paramBody)
   if b {
      util.ResponseFormat(c, code.Success, data)
      return
   }
   util.ResponseFormat(c, code.ComError, err)
@@ -196,6 +198,32 @@
   fmt.Println(areaId)
}
// @Summary 根据server获取所有摄像机列表及信息
// @Description 根据server获取所有摄像机列表及信息
// @Security ApiKeyAuth
// @Produce json
// @Tags camera
// @Param cameraName query string false "摄像机名称"
// @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/getAllCamerasByServer [get]
func (cc CameraController) GetAllCamerasByServer(c *gin.Context) {
   localConf, err2 := cache.GetServerInfo()
   if err2 !=nil || localConf.ServerId == "" {
      logger.Debug("localConfig is wrong!!!")
      util.ResponseFormat(c,code.ComError,"服务器本机未配置serverId")
      return
   }
   var api dbapi.CameraApi
   cameraName := c.Query("cameraName")
   b,d := api.GetAllCamerasByServer(localConf.ServerId, cameraName)
   if b {
      util.ResponseFormat(c,code.Success, d)
   } else {
      util.ResponseFormat(c,code.ComError, "")
   }
}
// @Summary 获取运行类型获取摄像机列表
// @Description 获取运行类型获取摄像机列表
// @Produce json
@@ -232,8 +260,8 @@
// @Description 切换摄像机运行实时或轮询的开关
// @Produce json
// @Tags camera
// @Param cameraId query string true "摄像机id"
// @Param runEnable query bool true "开启:true,关闭:false"
// @Param cameraId formData string true "摄像机id"
// @Param runEnable formData bool true "开启:true,关闭:false"
// @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/updateRunEnable [post]
@@ -266,8 +294,10 @@
// @Router /data/api-v/camera/updateSnapshotUrl/{cid} [get]
func(cc CameraController) UpdateSnapshotUrl(c *gin.Context){
    cid := c.Param("cid")
    filename, err := service.UpdateSnapshotUrl(cid)
    //filename, err := service.UpdateSnapshotUrl(cid)
   filename, err := service.UpdateCapture(cid)
    if err != nil {
       logger.Debug("UpdateSnapshotUrl.err:",err)
      util.ResponseFormat(c, code.ComError, "更新失败")
        return 
    }