workbenchController.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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, isExist := ctx.Get(middleware.Authorization)
  14. if !isExist || value == nil {
  15. ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
  16. }
  17. devices, err := service.WorkbenchService.CountDevice(value.(*middleware.JwtToken).TenantId)
  18. if err != nil {
  19. ctx.JSON(http.StatusOK, err)
  20. return
  21. }
  22. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, devices))
  23. }
  24. func (c *workbenchCtl) CountAlarm(ctx *gin.Context) {
  25. value, isExist := ctx.Get(middleware.Authorization)
  26. if !isExist || value == nil {
  27. ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
  28. }
  29. alarms, err := service.WorkbenchService.CountAlarm(value.(*middleware.JwtToken).TenantId)
  30. if err != nil {
  31. ctx.JSON(http.StatusOK, err)
  32. return
  33. }
  34. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
  35. }
  36. func (c *workbenchCtl) Aqi(ctx *gin.Context) {
  37. value, isExist := ctx.Get(middleware.Authorization)
  38. if !isExist || value == nil {
  39. ctx.JSON(http.StatusUnauthorized, util.NormalResponse(http.StatusUnauthorized, "", nil))
  40. }
  41. alarms, err := service.WorkbenchService.CountAlarm(value.(*middleware.JwtToken).TenantId)
  42. if err != nil {
  43. ctx.JSON(http.StatusOK, err)
  44. return
  45. }
  46. ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, alarms))
  47. }