liuxiaolong
2019-06-26 ca0affbce745df4e071dc256c5f47b2a8165a443
controllers/camera.go
@@ -3,6 +3,7 @@
import (
   "encoding/json"
   "fmt"
   "strconv"
   "github.com/gin-gonic/gin"
@@ -28,6 +29,11 @@
   Password  string       `json:"password"`
   Brand     string       `json:"brand"`
   Reserved  string       `json:"reserved"`
   IsRunning bool          `json:"is_running"`//是否正在解码
   RunEnable bool          `json:"run_enable"`//控制实时处理或轮询处理的开关
   RunType   int          `json:"run_type"`//处理类型:0:轮询,1:实时
   RunServerId string       `json:"run_server_id"`//当前正在处理的分析服务器id
}
// @Summary 添加摄像机
@@ -187,3 +193,88 @@
   fmt.Println(cameraId)
   fmt.Println(areaId)
}
// @Summary 获取运行类型获取摄像机列表
// @Description 获取运行类型获取摄像机列表
// @Produce json
// @Tags camera
// @Param runType query int true "0:查轮询,1:查实时"
// @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/getCamerasByRunType [get]
func (cc CameraController) GetCamerasByRunType(c *gin.Context) {
   runTypeStr := c.Query("runType")
   cameraName := c.Query("cameraName")
   fmt.Println("runType:",runTypeStr)
   fmt.Println("cameraName:",cameraName)
   runType, err := strconv.Atoi(runTypeStr)
   if err !=nil || (runType !=0 && runType !=1) {
      util.ResponseFormat(c,code.RequestParamError,"参数有误")
      return
   }
   var api dbapi.CameraApi
   b,list := api.GetCamerasByRunType(runType)
   if b {
      dataBytes, _ := json.Marshal(list)
      var cams []CameraVo
      json.Unmarshal(dataBytes, &cams)
      util.ResponseFormat(c,code.Success,cams)
   } else {
      util.ResponseFormat(c,code.ComError,err)
   }
}
// @Summary 切换摄像机运行实时或轮询的开关
// @Description 切换摄像机运行实时或轮询的开关
// @Produce json
// @Tags camera
// @Param cameraId query string true "摄像机id"
// @Param runEnable query 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]
func (cc CameraController) UpdateRunEnable(c *gin.Context){
   cameraId := c.PostForm("cameraId")
   enableStr := c.PostForm("runEnable")
   runEnable, err := strconv.ParseBool(enableStr)
   if cameraId == "" || err !=nil {
      util.ResponseFormat(c,code.RequestParamError,"参数有误")
      return
   }
   var api dbapi.CameraApi
   b, data := api.UpdateRunEnable(cameraId, runEnable)
   if b {
      util.ResponseFormat(c,code.Success,data)
   } else {
      util.ResponseFormat(c,code.ComError,"更新失败")
   }
}
// @Summary 摄像机轮询和实时状态切换
// @Description 摄像机轮询和实时状态切换
// @Produce json
// @Tags camera
// @Param cameraId query string true "摄像机id"
// @Param runType query int true "0:实时切轮询,1:轮询切实时"
// @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/changeRunType [post]
func (cc CameraController) ChangeRunType(c *gin.Context){
   cameraId := c.PostForm("cameraId")
   runTypeStr := c.PostForm("runType")
   runType,err := strconv.Atoi(runTypeStr)
   if cameraId == "" || err!=nil || (runType !=0 && runType !=1){
      util.ResponseFormat(c,code.RequestParamError,"参数有误")
      return
   }
   var api dbapi.CameraApi
   b, data := api.ChangeRunType(cameraId, runType)
   if b {
      util.ResponseFormat(c,code.Success,data)
   } else {
      util.ResponseFormat(c,code.ComError,"更新失败")
   }
}