workbenchController.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/device/service"
  5. "iot_manager_service/app/middleware"
  6. "iot_manager_service/util"
  7. "net/http"
  8. )
  9. // 工作台管理对象
  10. var Workbench = new(workbenchCtl)
  11. type workbenchCtl struct{}
  12. func (c *workbenchCtl) CountDevice(ctx *gin.Context) {
  13. value, _ := ctx.Get(middleware.Authorization)
  14. claims := value.(*middleware.Claims)
  15. devices, err := service.WorkbenchService.CountDevice(claims.TenantId)
  16. if err != nil {
  17. ctx.JSON(http.StatusOK, err)
  18. return
  19. }
  20. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
  21. }
  22. func (c *workbenchCtl) CountAlarm(ctx *gin.Context) {
  23. value, _ := ctx.Get(middleware.Authorization)
  24. claims := value.(*middleware.Claims)
  25. alarms, err := service.WorkbenchService.CountAlarm(claims.TenantId)
  26. if err != nil {
  27. ctx.JSON(http.StatusOK, err)
  28. return
  29. }
  30. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
  31. }
  32. func (c *workbenchCtl) Aqi(ctx *gin.Context) {
  33. value, _ := ctx.Get(middleware.Authorization)
  34. claims := value.(*middleware.Claims)
  35. alarms, err := service.WorkbenchService.CountAlarm(claims.TenantId)
  36. if err != nil {
  37. ctx.JSON(http.StatusOK, err)
  38. return
  39. }
  40. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
  41. }