package app import ( "github.com/gin-gonic/gin" "lcfns/model/app" "lcfns/model/app/request" "lcfns/model/common/response" "lcfns/service" "lcfns/utils" "strconv" ) type GatewayApi struct { } var gs = service.ServiceGroupApp.AppServiceGroup.GatewayService // List all devices func (api *GatewayApi) List(c *gin.Context) { var req request.GatewayRequest //v0 := c.Query("uid") id := utils.GetUserID(c) req.Uid = int(id) req.Name = c.Query("gatewayName") req.Osn = c.Query("osn") req.CameraSn = c.Query("cameraSn") v1 := c.Query("ipcastId") req.IpcastId, _ = strconv.Atoi(v1) v2 := c.Query("pageSize") req.PageSize, _ = strconv.Atoi(v2) v3 := c.Query("page") req.Page, _ = strconv.Atoi(v3) list, total, err := gs.List(req) if err != nil { response.FailWithMessage(err.Error(), c) return } response.OkWithDetailed(response.PageResult{ List: list, Total: total, Page: req.Page, PageSize: req.PageSize, }, "获取成功", c) } // AdminSet 管理员设置osn和给网关分配用户 func (api *GatewayApi) AdminSet(c *gin.Context) { var data app.Gateway err := c.ShouldBindJSON(&data) if err != nil { response.FailWithMessage(err.Error(), c) return } err = gs.AdminSet(&data) if err != nil { response.FailWithDetailed(err.Error(), "设置失败", c) return } response.OkWithMessage("设置成功", c) } // UserSet 用户设置网关名和描述信息 func (api *GatewayApi) UserSet(c *gin.Context) { var data app.Gateway err := c.ShouldBindJSON(&data) if err != nil { response.FailWithMessage(err.Error(), c) return } err = gs.Update(&data) if err != nil { response.FailWithDetailed(err.Error(), "设置失败", c) return } response.OkWithMessage("设置成功", c) } // DeleteGateways 删除网关及其关联设备 func (api *GatewayApi) DeleteGateways(c *gin.Context) { var req app.Gateway err := c.ShouldBindJSON(&req) if err != nil { response.FailWithDetailed(err.Error(), "请求参数错误", c) return } err = gs.DeleteGateways(req) if err != nil { response.FailWithDetailed(err.Error(), "删除失败", c) return } response.OkWithMessage("删除成功", c) } // UnbindGateways 解绑网关下的设备 func (api *GatewayApi) UnbindGateways(c *gin.Context) { var req app.Gateway err := c.ShouldBindJSON(&req) if err != nil { response.FailWithDetailed(err.Error(), "请求参数错误", c) return } err = gs.UnbindGateways(req) if err != nil { response.FailWithDetailed(err.Error(), "解绑失败", c) return } response.OkWithMessage("解绑成功", c) }