workbenchController.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "iot_manager_service/app/device/model"
  5. "iot_manager_service/app/device/service"
  6. "iot_manager_service/app/middleware"
  7. "iot_manager_service/util/common"
  8. "net/http"
  9. )
  10. // 工作台管理对象
  11. var Workbench = new(workbenchCtl)
  12. type workbenchCtl struct{}
  13. func (c *workbenchCtl) CountDevice(ctx *gin.Context) {
  14. value, _ := ctx.Get(middleware.Authorization)
  15. claims := value.(*middleware.Claims)
  16. devices, err := service.WorkbenchService.CountDevice(claims.TenantId)
  17. if err != nil {
  18. ctx.JSON(http.StatusOK, err)
  19. return
  20. }
  21. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, devices))
  22. }
  23. func (c *workbenchCtl) CountAlarm(ctx *gin.Context) {
  24. value, _ := ctx.Get(middleware.Authorization)
  25. claims := value.(*middleware.Claims)
  26. alarms, err := service.WorkbenchService.CountAlarm(claims.TenantId)
  27. if err != nil {
  28. ctx.JSON(http.StatusOK, err)
  29. return
  30. }
  31. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  32. }
  33. func (c *workbenchCtl) Aqi(ctx *gin.Context) {
  34. value, _ := ctx.Get(middleware.Authorization)
  35. claims := value.(*middleware.Claims)
  36. alarms, err := service.WorkbenchService.Aqi(claims.TenantId)
  37. if err != nil {
  38. ctx.JSON(http.StatusOK, err)
  39. return
  40. }
  41. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  42. }
  43. func (c *workbenchCtl) CountJobTodo(ctx *gin.Context) {
  44. value, _ := ctx.Get(middleware.Authorization)
  45. claims := value.(*middleware.Claims)
  46. alarms, err := service.WorkbenchService.CountJobTodo(claims.TenantId)
  47. if err != nil {
  48. ctx.JSON(http.StatusOK, err)
  49. return
  50. }
  51. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  52. }
  53. func (c *workbenchCtl) Notification(ctx *gin.Context) {
  54. value, _ := ctx.Get(middleware.Authorization)
  55. claims := value.(*middleware.Claims)
  56. alarms, err := service.WorkbenchService.Notification(claims.TenantId)
  57. if err != nil {
  58. ctx.JSON(http.StatusOK, err)
  59. return
  60. }
  61. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  62. }
  63. func (c *workbenchCtl) LightRate(ctx *gin.Context) {
  64. value, _ := ctx.Get(middleware.Authorization)
  65. claims := value.(*middleware.Claims)
  66. var req model.ReqLightRates
  67. if err := ctx.ShouldBindQuery(&req); err != nil {
  68. ctx.JSON(http.StatusServiceUnavailable, err)
  69. }
  70. //queryType=month&startDate=2022-09-01&endDate=2022-10-04
  71. alarms, err := service.WorkbenchService.LightRate(claims.TenantId, req)
  72. if err != nil {
  73. ctx.JSON(http.StatusOK, err)
  74. return
  75. }
  76. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, alarms))
  77. }