package controllers import ( "basic.com/dbapi.git" "webserver/extend/code" "webserver/extend/util" "github.com/gin-gonic/gin" ) type AreaController struct { } type AreaVo struct { Id string `json:"id"` ParentId string `json:"parentId"` Name string `json:"name"` } // @Summary 显示树形结构 // @Description 显示左侧所有区域和摄像机 // @Produce json // @Tags menu // @Param parentid query int true "区域的id" // @Success 200 {string} json "{"code":200, msg:"目录结构数据"}" // @Failure 500 {string} json "{"code":500, msg:"返回错误信息"}" // @Router /data/api-v/area/localmenu [get] func (ac AreaController) CameraTree(c *gin.Context) { parentIdStr := c.Query("parentid") searchTypeStr := c.Query("searchType") cameraName := c.Query("cameraName") var api dbapi.AreaApi arr := api.GetLocalCameraTree(parentIdStr, searchTypeStr, cameraName) util.ResponseFormat(c, code.Success, arr) } // @Summary 显示Gb28181树形结构 // @Description 显示Gb28181树形结构 // @Produce json // @Tags menu // @Param parentid query int true "区域的id" // @Success 200 {string} json "{"code":200, msg:"目录结构数据"}" // @Failure 500 {string} json "{"code":500, msg:"返回错误信息"}" // @Router /data/api-v/area/localmenu [get] func (ac AreaController) CameraGb28181Tree(c *gin.Context) { parentIdStr := c.Query("parentid") searchTypeStr := c.Query("searchType") cameraName := c.Query("cameraName") var api dbapi.AreaApi arr := api.GetGb28181CameraTree(parentIdStr, searchTypeStr, cameraName) util.ResponseFormat(c, code.Success, arr) } // @Summary 添加menu的区域 // @Description 添加目录上区域 // @Produce json // @Tags menu // @Param name query string true "区域名字" // @Param parentId query int true "上一级父id" // @Success 200 {string} json "{"code":200, data:"添加的区域信息",msg:"请求成功", success:true}" // @Failure 200 {string} json "{"code":"错误码", data:"出错信息",msg:"请求失败", success:false}" // @Router /data/api-v/area/add [post] func (ac AreaController) AreaAdd(c *gin.Context) { var api dbapi.AreaApi name := c.PostForm("name") parentId := c.PostForm("parentId") var model = AreaVo{ Name:name, ParentId:parentId, } paramBody := util.Struct2Map(model) if api.AreaAdd(paramBody) { util.ResponseFormat(c,code.AddSuccess,"添加成功") } else { util.ResponseFormat(c,code.ComError,"添加失败") } } // @Summary 修改名字 // @Description 修改区域名字 // @Accept json // @Produce json // @Tags menu // @Param id query int true "区域id" // @Param name query string true "区域名字" // @Param parentId query int true "上一级父id" // @Success 200 {string} json "{"code":200, data:"",msg:"请求成功", success:true}" // @Failure 200 {string} json "{"code":"错误码", data:"出错信息",msg:"请求失败", success:false}" // @Router /data/api-v/area/update [post] func (ac AreaController) AreaUpdate(c *gin.Context) { id := c.PostForm("id") if id == ""{ util.ResponseFormat(c, code.RequestParamError, "参数错误") return } name := c.PostForm("name") parentId := c.PostForm("parentId") if parentId == "" { util.ResponseFormat(c, code.RequestParamError, "parentId参数错误") return } var model = AreaVo{ Id:id, ParentId:parentId, Name:name, } paramBody := util.Struct2Map(model) var api dbapi.AreaApi if api.AreaUpdate(paramBody) { util.ResponseFormat(c,code.UpdateSuccess,"更新成功") }else { util.ResponseFormat(c,code.ComError,"更新失败") } } // @Summary 删除一个区域 // @Description 点击删除按钮时删除一个区域 // @Produce json // @Tags menu // @Param id query int true "当前id" // @Success 200 {string} json "{"code":200, data:"删除的区域信息",msg:"请求成功", success:true}" // @Failure 200 {string} json "{"code":"错误码", data:"出错信息",msg:"请求失败", success:false}" // @Router /data/api-v/area/del [post] func (ac AreaController) AreaDelete(c *gin.Context) { var api dbapi.AreaApi id := c.PostForm("id") if id == "" { util.ResponseFormat(c, code.ComError, "参数有误") return } if api.AreaDelete(id) { util.ResponseFormat(c, code.DelSuccess, "删除成功") } else { util.ResponseFormat(c, code.ComError,"删除失败") } }