platformAlarmController.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. var PlatformAlarm = new(platformAlarmCrl)
  13. type platformAlarmCrl struct {
  14. }
  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. list, total, err := service.PlatformAlarmService.GetList(claims.TenantId, filter)
  33. if err != nil {
  34. ctx.JSON(http.StatusBadRequest, err)
  35. return
  36. }
  37. pages := math.Ceil(float64((total)) / float64(size))
  38. rsp := model.ResposePlatFormAlart{
  39. Current: current,
  40. Size: size,
  41. Total: total,
  42. Pages: int(pages),
  43. Records: list,
  44. }
  45. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
  46. }
  47. func (c platformAlarmCrl) Refresh(ctx *gin.Context) {
  48. value, _ := ctx.Get(middleware.Authorization)
  49. claims := value.(*middleware.Claims)
  50. tenantId := claims.TenantId
  51. alarmService := service.PlatformAlarmService
  52. go func() {
  53. alarmService.Refresh(tenantId)
  54. }()
  55. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  56. }
  57. func (c platformAlarmCrl) HannleAlart(ctx *gin.Context) {
  58. value, _ := ctx.Get(middleware.Authorization)
  59. claims := value.(*middleware.Claims)
  60. id, _ := strconv.Atoi(ctx.Query("id"))
  61. armHandle, _ := strconv.Atoi(ctx.Query("armHandle"))
  62. remark := ctx.Query("remark")
  63. err := service.PlatformAlarmService.HannleAlart(claims.TenantId, id, armHandle, remark)
  64. if err != nil {
  65. ctx.JSON(http.StatusBadRequest, err)
  66. return
  67. }
  68. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  69. }
  70. func (c platformAlarmCrl) Detail(ctx *gin.Context) {
  71. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil))
  72. }