workbenchController.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/common"
  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, common.SuccessResponse(common.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, common.SuccessResponse(common.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.Aqi(claims.TenantId)
  36. if err != nil {
  37. ctx.JSON(http.StatusOK, err)
  38. return
  39. }
  40. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  41. }
  42. func (c *workbenchCtl) CountJobTodo(ctx *gin.Context) {
  43. value, _ := ctx.Get(middleware.Authorization)
  44. claims := value.(*middleware.Claims)
  45. alarms, err := service.WorkbenchService.CountJobTodo(claims.TenantId)
  46. if err != nil {
  47. ctx.JSON(http.StatusOK, err)
  48. return
  49. }
  50. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  51. }
  52. func (c *workbenchCtl) Notification(ctx *gin.Context) {
  53. value, _ := ctx.Get(middleware.Authorization)
  54. claims := value.(*middleware.Claims)
  55. alarms, err := service.WorkbenchService.Notification(claims.TenantId)
  56. if err != nil {
  57. ctx.JSON(http.StatusOK, err)
  58. return
  59. }
  60. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  61. }
  62. func (c *workbenchCtl) LightRate(ctx *gin.Context) {
  63. value, _ := ctx.Get(middleware.Authorization)
  64. claims := value.(*middleware.Claims)
  65. //queryType=month&startDate=2022-09-01&endDate=2022-10-04
  66. alarms, err := service.WorkbenchService.LightRate(claims.TenantId)
  67. if err != nil {
  68. ctx.JSON(http.StatusOK, err)
  69. return
  70. }
  71. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  72. }