gateway.go 2.5 KB

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