tunnel.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package admin
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "server/dao"
  5. "server/model/common/request"
  6. "server/model/common/response"
  7. "server/utils/logger"
  8. "strconv"
  9. )
  10. type TunnelApi struct{}
  11. func (ta *TunnelApi) QueryAllTunnels(c *gin.Context) {
  12. tunnels, err := tunnelService.QueryAllTunnels()
  13. if err != nil {
  14. logger.Get().Error("QueryAllTunnels ---- " + err.Error())
  15. response.FailWithMessage("获取隧道失败", c)
  16. return
  17. }
  18. response.OkWithData(tunnels, c)
  19. }
  20. func (ta *TunnelApi) QueryTunnelList(c *gin.Context) {
  21. var info request.TunnelSearch
  22. err := c.ShouldBindJSON(&info)
  23. if err != nil {
  24. logger.Get().Error("QueryTunnelList ---- " + err.Error())
  25. response.FailWithMessage("参数解析失败", c)
  26. return
  27. }
  28. list, total, err := tunnelService.QueryTunnelList(info)
  29. if err != nil {
  30. logger.Get().Error("QueryTunnelList ---- " + err.Error())
  31. response.FailWithMessage("设备获取列表错误", c)
  32. return
  33. }
  34. response.OkWithDetailed(response.PageResult{
  35. List: list,
  36. Total: total,
  37. Page: info.PageInfo.Page,
  38. PageSize: info.PageInfo.PageSize,
  39. }, "获取成功", c)
  40. }
  41. func (ta *TunnelApi) QueryNoRegionTunnels(c *gin.Context) {
  42. tunnels, err := tunnelService.QueryNoRegionTunnels()
  43. if err != nil {
  44. logger.Get().Error("QueryNoRegionTunnels ---- " + err.Error())
  45. response.FailWithMessage("获取未分配区域隧道失败", c)
  46. return
  47. }
  48. response.OkWithData(tunnels, c)
  49. }
  50. func (ta *TunnelApi) CreateTunnel(c *gin.Context) {
  51. var tunnel dao.Tunnel
  52. if err := c.ShouldBindJSON(&tunnel); err != nil {
  53. logger.Get().Error("CreateTunnel ---- " + err.Error())
  54. response.FailWithMessage("参数解析失败", c)
  55. return
  56. }
  57. err := tunnelService.CreateTunnel(tunnel)
  58. if err != nil {
  59. logger.Get().Error("CreateTunnel ---- " + err.Error())
  60. response.FailWithMessage("创建隧道失败", c)
  61. return
  62. }
  63. response.OkWithMessage("创建隧道成功", c)
  64. }
  65. func (ta *TunnelApi) UpdateTunnel(c *gin.Context) {
  66. var tunnel dao.Tunnel
  67. if err := c.ShouldBindJSON(&tunnel); err != nil {
  68. logger.Get().Error("UpdateTunnel ---- " + err.Error())
  69. response.FailWithMessage("参数解析失败", c)
  70. return
  71. }
  72. err := tunnelService.UpdateTunnel(tunnel)
  73. if err != nil {
  74. logger.Get().Error("UpdateTunnel ---- " + err.Error())
  75. response.FailWithMessage("更新隧道失败", c)
  76. return
  77. }
  78. response.OkWithMessage("更新隧道成功", c)
  79. }
  80. func (ta *TunnelApi) UpdateTunnelsRegion(c *gin.Context) {
  81. var info request.RegionTunnelsId
  82. if err := c.ShouldBindJSON(&info); err != nil {
  83. logger.Get().Error("UpdateTunnelsRegion ---- " + err.Error())
  84. response.FailWithMessage("参数解析失败", c)
  85. return
  86. }
  87. err := tunnelService.UpdateTunnelsRegion(info.TunnelIds, info.RegionId)
  88. if err != nil {
  89. logger.Get().Error("UpdateTunnelsRegion ---- " + err.Error())
  90. response.FailWithMessage("更新隧道所属区域失败", c)
  91. return
  92. }
  93. response.OkWithMessage("更新隧道所属区域成功", c)
  94. }
  95. func (ta *TunnelApi) UpdateTunnelTime(c *gin.Context) {
  96. var tunnelTime dao.TunnelTime
  97. if err := c.ShouldBindJSON(&tunnelTime); err != nil {
  98. logger.Get().Error("UpdateTunnelTime ---- " + err.Error())
  99. response.FailWithMessage("参数解析失败", c)
  100. return
  101. }
  102. err := tunnelService.UpdateTunnelTime(tunnelTime)
  103. if err != nil {
  104. logger.Get().Error("UpdateTunnelTime ---- " + err.Error())
  105. response.FailWithMessage("更新隧道定时失败", c)
  106. return
  107. }
  108. response.OkWithMessage("更新隧道定时成功", c)
  109. }
  110. func (ta *TunnelApi) DeleteTunnel(c *gin.Context) {
  111. id, err := strconv.Atoi(c.Query("id"))
  112. if err != nil {
  113. logger.Get().Error("DeleteTunnel ---- " + err.Error())
  114. response.FailWithMessage("参数错误", c)
  115. return
  116. }
  117. err = tunnelService.DeleteTunnel(id)
  118. if err != nil {
  119. logger.Get().Error("DeleteTunnel ---- " + err.Error())
  120. response.FailWithMessage("删除隧道失败", c)
  121. return
  122. }
  123. response.OkWithMessage("删除隧道成功", c)
  124. }