platformAlarmController.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/middleware"
  5. "iot_manager_service/app/warn/model"
  6. "iot_manager_service/app/warn/service"
  7. "iot_manager_service/util/common"
  8. "math"
  9. "net/http"
  10. "strconv"
  11. )
  12. // PlatformAlarm 运维告警记录
  13. var PlatformAlarm = new(platformAlarmCrl)
  14. type platformAlarmCrl struct{}
  15. func (c platformAlarmCrl) List(ctx *gin.Context) {
  16. value, _ := ctx.Get(middleware.Authorization)
  17. claims := value.(*middleware.Claims)
  18. filter := model.RequestPlatFormAlartFilter{}
  19. current, _ := strconv.Atoi(ctx.Query("current"))
  20. size, _ := strconv.Atoi(ctx.Query("size"))
  21. if current == 0 {
  22. current = 1
  23. }
  24. if size <= 0 || size > 100 {
  25. size = 10
  26. }
  27. err := ctx.ShouldBind(&filter)
  28. if err != nil {
  29. ctx.JSON(http.StatusBadRequest, err)
  30. return
  31. }
  32. filter.ArmSource = 1 //运维
  33. list, total, err := service.PlatformAlarmService.GetList(claims.TenantId, filter)
  34. if err != nil {
  35. ctx.JSON(http.StatusBadRequest, err)
  36. return
  37. }
  38. pages := math.Ceil(float64((total)) / float64(size))
  39. rsp := model.ResposePlatFormAlart{
  40. Current: current,
  41. Size: size,
  42. Total: total,
  43. Pages: int(pages),
  44. Records: list,
  45. }
  46. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
  47. }
  48. func (c platformAlarmCrl) List2(ctx *gin.Context) {
  49. value, _ := ctx.Get(middleware.Authorization)
  50. claims := value.(*middleware.Claims)
  51. filter := model.RequestPlatFormAlartFilter{}
  52. current, _ := strconv.Atoi(ctx.Query("current"))
  53. size, _ := strconv.Atoi(ctx.Query("size"))
  54. if current == 0 {
  55. current = 1
  56. }
  57. if size <= 0 || size > 100 {
  58. size = 10
  59. }
  60. err := ctx.ShouldBind(&filter)
  61. if err != nil {
  62. ctx.JSON(http.StatusBadRequest, err)
  63. return
  64. }
  65. filter.ArmSource = 2 //运维
  66. list, total, err := service.PlatformAlarmService.GetList(claims.TenantId, filter)
  67. if err != nil {
  68. ctx.JSON(http.StatusBadRequest, err)
  69. return
  70. }
  71. pages := math.Ceil(float64((total)) / float64(size))
  72. rsp := model.ResposePlatFormAlart{
  73. Current: current,
  74. Size: size,
  75. Total: total,
  76. Pages: int(pages),
  77. Records: list,
  78. }
  79. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
  80. }
  81. func (c platformAlarmCrl) Refresh(ctx *gin.Context) {
  82. value, _ := ctx.Get(middleware.Authorization)
  83. claims := value.(*middleware.Claims)
  84. tenantId := claims.TenantId
  85. alarmService := service.PlatformAlarmService
  86. go func() {
  87. alarmService.Refresh(tenantId)
  88. }()
  89. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  90. }
  91. func (c platformAlarmCrl) HandleAlert(ctx *gin.Context) {
  92. value, _ := ctx.Get(middleware.Authorization)
  93. claims := value.(*middleware.Claims)
  94. id, _ := strconv.Atoi(ctx.Query("id"))
  95. armHandle, _ := strconv.Atoi(ctx.Query("armHandle"))
  96. remark := ctx.Query("remark")
  97. err := service.PlatformAlarmService.HandleAlarm(claims.TenantId, id, armHandle, remark)
  98. if err != nil {
  99. ctx.JSON(http.StatusBadRequest, err)
  100. return
  101. }
  102. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  103. }
  104. func (c platformAlarmCrl) Detail(ctx *gin.Context) {
  105. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  106. }