gateway.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package app
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "lc-fangdaosha/model/app"
  6. "lc-fangdaosha/model/app/request"
  7. "lc-fangdaosha/model/common/response"
  8. "lc-fangdaosha/service"
  9. "lc-fangdaosha/utils"
  10. "strconv"
  11. )
  12. type GatewayApi struct {
  13. }
  14. var gs = service.ServiceGroupApp.AppServiceGroup.GatewayService
  15. // List 获取网关列表
  16. func (api *GatewayApi) List(c *gin.Context) {
  17. var req request.GatewayRequest
  18. id := utils.GetUserID(c)
  19. req.Uid = int(id)
  20. req.Name = c.Query("gatewayName")
  21. req.Osn = c.Query("osn")
  22. req.CameraSn = c.Query("cameraSn")
  23. v2 := c.Query("pageSize")
  24. req.PageSize, _ = strconv.Atoi(v2)
  25. v3 := c.Query("page")
  26. req.Page, _ = strconv.Atoi(v3)
  27. fmt.Printf("参数:%+v\n", req)
  28. list, err := gs.List(req)
  29. if err != nil {
  30. response.FailWithMessage(err.Error(), c)
  31. return
  32. }
  33. response.OkWithDetailed(response.PageResult{
  34. List: list,
  35. Total: int64(len(list)),
  36. Page: req.Page,
  37. PageSize: req.PageSize,
  38. }, "获取成功", c)
  39. }
  40. // AdminSet 管理员设置osn和给网关分配用户
  41. func (api *GatewayApi) AdminSet(c *gin.Context) {
  42. var data app.Gateway
  43. err := c.ShouldBindJSON(&data)
  44. if err != nil {
  45. response.FailWithMessage(err.Error(), c)
  46. return
  47. }
  48. err = gs.AdminSet(&data)
  49. if err != nil {
  50. response.FailWithDetailed(err.Error(), "设置失败", c)
  51. return
  52. }
  53. response.OkWithMessage("设置成功", c)
  54. }
  55. // UserSet 用户设置网关名和描述信息
  56. func (api *GatewayApi) UserSet(c *gin.Context) {
  57. var data app.Gateway
  58. err := c.ShouldBindJSON(&data)
  59. if err != nil {
  60. response.FailWithMessage(err.Error(), c)
  61. return
  62. }
  63. err = gs.Update(&data)
  64. if err != nil {
  65. response.FailWithDetailed(err.Error(), "设置失败", c)
  66. return
  67. }
  68. response.OkWithMessage("设置成功", c)
  69. }
  70. // DeleteGateways 删除网关及其关联设备
  71. func (api *GatewayApi) DeleteGateways(c *gin.Context) {
  72. var req app.Gateway
  73. err := c.ShouldBindJSON(&req)
  74. if err != nil {
  75. response.FailWithDetailed(err.Error(), "请求参数错误", c)
  76. return
  77. }
  78. err = gs.DeleteGateways(req)
  79. if err != nil {
  80. response.FailWithDetailed(err.Error(), "删除失败", c)
  81. return
  82. }
  83. response.OkWithMessage("删除成功", c)
  84. }
  85. // UnbindGateways 解绑网关下的设备
  86. func (api *GatewayApi) UnbindGateways(c *gin.Context) {
  87. var req app.Gateway
  88. err := c.ShouldBindJSON(&req)
  89. if err != nil {
  90. response.FailWithDetailed(err.Error(), "请求参数错误", c)
  91. return
  92. }
  93. err = gs.UnbindGateways(req)
  94. if err != nil {
  95. response.FailWithDetailed(err.Error(), "解绑失败", c)
  96. return
  97. }
  98. response.OkWithMessage("解绑成功", c)
  99. }