gateway.go 2.3 KB

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