liuxiaolong
2019-06-26 ca0affbce745df4e071dc256c5f47b2a8165a443
pollconfig done
4个文件已修改
233 ■■■■■ 已修改文件
controllers/camera.go 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/fileController.go 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/pollConfig.go 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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,"更新失败")
    }
}
controllers/fileController.go
@@ -84,6 +84,23 @@
        util.ResponseFormat(c, code.Success, field)
    }
}
// @Description 人员照片上传并获取特征值
// @Router /data/api-v/dbperson/fileUploadTest [POST]
func (controller FileController) UploadPersonTest(c *gin.Context){
    file, header, err := c.Request.FormFile("file") //image这个是uplaodify参数定义中的   'fileObjName':'image'
    if err != nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    //文件的名称
    filename := header.Filename
    fmt.Println(file, err, filename)
    if err != nil {
        log.Fatal(err)
        filename = uuid.NewV4().String()
    }
}
/*// 对上面的编码结果进行base64解码
decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
controllers/pollConfig.go
@@ -1 +1,110 @@
package controllers
import (
    "basic.com/dbapi.git"
    "github.com/gin-gonic/gin"
    "strconv"
    "webserver/extend/code"
    "webserver/extend/util"
)
type PollConfigController struct {
}
type PollConfig struct {
    ServerId string `json:"server_id"`//服务器id
    PollPeriod int `json:"poll_period"`//轮询周期
    Delay int `json:"delay"`//延时时间
    Enable bool `json:"enable"`//是否启用轮询
}
// @Summary 保存轮询周期
// @Description 保存轮询周期
// @Produce json
// @Tags 轮询配置
// @Param period query int 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/pollConfig/savePollPeriod [post]
func (controller PollConfigController) SavePollPeriod(c *gin.Context){
    periodStr := c.PostForm("period")
    period, err := strconv.Atoi(periodStr)
    if periodStr =="" || err !=nil{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.SysSetApi
    b, data := api.SavePollDelay(period)
    if b {
        util.ResponseFormat(c,code.Success,data)
    } else {
        util.ResponseFormat(c,code.ComError,"保存失败")
    }
}
// @Summary 保存轮询延时
// @Description 保存轮询延时
// @Produce json
// @Tags 轮询配置
// @Param delay query int 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/pollConfig/savePollDelay [post]
func (controller PollConfigController) SavePollDelay(c *gin.Context){
    delayStr := c.PostForm("delay")
    delay, err := strconv.Atoi(delayStr)
    if delayStr =="" || err !=nil{
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.SysSetApi
    b, data := api.SavePollDelay(delay)
    if b {
        util.ResponseFormat(c,code.Success,data)
    } else {
        util.ResponseFormat(c,code.ComError,"保存失败")
    }
}
// @Summary 获取本机轮询配置
// @Description 获取本机轮询配置
// @Produce json
// @Tags 轮询配置
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/pollConfig/getPollConfig [get]
func (controller PollConfigController) GetPollConfig(c *gin.Context){
    var api dbapi.SysSetApi
    b, data := api.GetPollConfig()
    if b {
        util.ResponseFormat(c,code.Success,data)
    }else{
        util.ResponseFormat(c,code.ComError,"查询失败")
    }
}
type PollEnableVo struct {
    Enable bool `json:"enable"`
}
// @Summary 切换轮询开关
// @Description 切换轮询开关
// @Produce json
// @Tags 轮询配置
// @Param argBody body controllers.PollEnableVo 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/pollConfig/updateEnable [post]
func (controller PollConfigController) UpdateEnable(c *gin.Context){
    var argBody PollEnableVo
    if err := c.BindJSON(&argBody);err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.SysSetApi
    if api.UpdatePollEnable(argBody.Enable){
        util.ResponseFormat(c,code.Success,"修改成功")
    } else {
        util.ResponseFormat(c,code.ComError,"修改失败")
    }
}
router/router.go
@@ -35,6 +35,8 @@
    dicController :=new(controllers.DictionaryController)
    userController :=new(controllers.UserController)
    eventPushController :=new(controllers.EventPushController)
    pollConfigController :=new(controllers.PollConfigController)
    fileController := new(controllers.FileController)
    urlPrefix := "/data/api-v" // wp 添加 路径 前缀
    userApi :=r.Group(urlPrefix+"/user")
@@ -66,6 +68,9 @@
        camera.GET("/delTask/:cameraId/:taskId", cameraController.CameraDelTask)
        camera.POST("/saveTask", cameraController.CameraTaskSave)
        camera.GET("/getRulesByCameraAndTask",cameraTaskArgsController.FindByCameraAndTask)
        camera.GET("/getCamerasByRunType",cameraController.GetCamerasByRunType)
        camera.POST("/updateRunEnable",cameraController.UpdateRunEnable)
        camera.POST("/changeRunType",cameraController.ChangeRunType)
    }
    cameraTaskArgsApi :=r.Group(urlPrefix + "/cameraTaskArgs")
@@ -136,6 +141,8 @@
        vdbperson.POST("/deleteDbPersonById/:uuid", dbPersonCont.DeleteDbPerson)
        vdbperson.POST("/deleteMoreDbPerson", dbPersonCont.DeleteMoreDbPerson)
        vdbperson.PUT("/addDbPerson", dbPersonCont.AddDbPerson)
        vdbperson.POST("/fileUploadTest",fileController.UploadPersonTest)
    }
    // 系统设置 操作
@@ -180,12 +187,19 @@
        eventPushApi.POST("/changeStatus",eventPushController.ChangeStatus)
        eventPushApi.POST("/delete",eventPushController.Delete)
    }
    pollCApi :=r.Group(urlPrefix+"/pollConfig")
    {
        pollCApi.POST("/savePollPeriod",pollConfigController.SavePollPeriod)
        pollCApi.POST("/savePollDelay",pollConfigController.SavePollDelay)
        pollCApi.GET("/getPollConfig",pollConfigController.GetPollConfig)
        pollCApi.POST("/updateEnable",pollConfigController.UpdateEnable)
    }
    // 文件 上传
    r.Static("static", "./static") // 静态文件
    //外部访问swagger.json
    r.StaticFile("/swagger.json", "./docs/swagger.json")
    fileController := new(controllers.FileController)
    vdbperson.POST("/fileupload", fileController.Fileupload)
    vdbperson.POST("/moreFileUpload", fileController.MoreFileUpload)
    r.POST(urlPrefix+"/es/ImageUploadReturnPics", fileController.ImageUploadReturnPics)