123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package app
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "lc-fangdaosha/model/app"
- "lc-fangdaosha/model/app/request"
- "lc-fangdaosha/model/common/response"
- "lc-fangdaosha/service"
- "lc-fangdaosha/utils"
- "strconv"
- )
- type GatewayApi struct {
- }
- var gs = service.ServiceGroupApp.AppServiceGroup.GatewayService
- // List 获取网关列表
- func (api *GatewayApi) List(c *gin.Context) {
- var req request.GatewayRequest
- id := utils.GetUserID(c)
- req.Uid = int(id)
- req.Name = c.Query("gatewayName")
- req.Osn = c.Query("osn")
- req.CameraSn = c.Query("cameraSn")
- v2 := c.Query("pageSize")
- req.PageSize, _ = strconv.Atoi(v2)
- v3 := c.Query("page")
- req.Page, _ = strconv.Atoi(v3)
- fmt.Printf("参数:%+v\n", req)
- list, err := gs.List(req)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: int64(len(list)),
- 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)
- }
|