tunnel.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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) UpdateTunnelLamp(c *gin.Context) {
  81. var info request.TunnelLamp
  82. err := c.ShouldBindJSON(&info)
  83. if err != nil {
  84. logger.Get().Error("UpdateTunnelLamp ---- " + err.Error())
  85. response.FailWithMessage("参数解析失败", c)
  86. return
  87. }
  88. err = tunnelService.UpdateTunnelLamp(info)
  89. if err != nil {
  90. logger.Get().Error("UpdateTunnelLamp ---- " + err.Error())
  91. response.FailWithMessage("更新隧道灯光状态失败", c)
  92. return
  93. }
  94. response.OkWithMessage("更新隧道灯光状态成功", c)
  95. }
  96. func (ta *TunnelApi) UpdateTactics(c *gin.Context) {
  97. var tactics request.EditTactics
  98. if err := c.ShouldBindJSON(&tactics); err != nil {
  99. logger.Get().Error("UpdateTactics ---- " + err.Error())
  100. response.FailWithMessage("参数解析失败", c)
  101. return
  102. }
  103. err := tunnelService.UpdateTactics(tactics.Sn, tactics.Tactics)
  104. if err != nil {
  105. logger.Get().Error("UpdateTactics ---- " + err.Error())
  106. response.FailWithMessage("更新隧道策略失败", c)
  107. return
  108. }
  109. response.OkWithMessage("更新隧道策略成功", c)
  110. }
  111. func (ta *TunnelApi) UpdateTunnelsRegion(c *gin.Context) {
  112. var info request.RegionTunnelsId
  113. if err := c.ShouldBindJSON(&info); err != nil {
  114. logger.Get().Error("UpdateTunnelsRegion ---- " + err.Error())
  115. response.FailWithMessage("参数解析失败", c)
  116. return
  117. }
  118. err := tunnelService.UpdateTunnelsRegion(info.TunnelIds, info.RegionId)
  119. if err != nil {
  120. logger.Get().Error("UpdateTunnelsRegion ---- " + err.Error())
  121. response.FailWithMessage("更新隧道所属区域失败", c)
  122. return
  123. }
  124. response.OkWithMessage("更新隧道所属区域成功", c)
  125. }
  126. func (ta *TunnelApi) UpdateTunnelTime(c *gin.Context) {
  127. var tunnelTime dao.TunnelTime
  128. if err := c.ShouldBindJSON(&tunnelTime); err != nil {
  129. logger.Get().Error("UpdateTunnelTime ---- " + err.Error())
  130. response.FailWithMessage("参数解析失败", c)
  131. return
  132. }
  133. err := tunnelService.UpdateTunnelTime(tunnelTime)
  134. if err != nil {
  135. logger.Get().Error("UpdateTunnelTime ---- " + err.Error())
  136. response.FailWithMessage("更新隧道定时失败", c)
  137. return
  138. }
  139. response.OkWithMessage("更新隧道定时成功", c)
  140. }
  141. func (ta *TunnelApi) DeleteTunnel(c *gin.Context) {
  142. id, err := strconv.Atoi(c.Query("id"))
  143. if err != nil {
  144. logger.Get().Error("DeleteTunnel ---- " + err.Error())
  145. response.FailWithMessage("参数错误", c)
  146. return
  147. }
  148. err = tunnelService.DeleteTunnel(id)
  149. if err != nil {
  150. logger.Get().Error("DeleteTunnel ---- " + err.Error())
  151. response.FailWithMessage("删除隧道失败", c)
  152. return
  153. }
  154. response.OkWithMessage("删除隧道成功", c)
  155. }