123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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 request.Ids
- 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)
- }
|