alarmController.go 923 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/middleware"
  5. "iot_manager_service/app/operation/model"
  6. "iot_manager_service/app/operation/service"
  7. "iot_manager_service/util/common"
  8. "net/http"
  9. )
  10. // Alarm 告警统计
  11. var Alarm = new(alarmCtl)
  12. type alarmCtl struct{}
  13. func (c alarmCtl) List(ctx *gin.Context) {
  14. value, _ := ctx.Get(middleware.Authorization)
  15. claims := value.(*middleware.Claims)
  16. var req model.RequestAlarmFilter
  17. err := ctx.ShouldBindQuery(&req)
  18. if err != nil {
  19. ctx.JSON(http.StatusOK, err)
  20. return
  21. }
  22. var records interface{}
  23. err = nil
  24. if req.QueryType == "day" {
  25. records, err = service.AlarmService.GetDayList(claims.TenantId, req)
  26. } else {
  27. records, err = service.AlarmService.GetMonthList(claims.TenantId, req)
  28. }
  29. if err != nil {
  30. ctx.JSON(http.StatusOK, err)
  31. return
  32. }
  33. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  34. }