deviceCountController.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // Device 设备统计
  11. var Device = new(deviceCtl)
  12. type deviceCtl struct{}
  13. func (c deviceCtl) CountDevice(ctx *gin.Context) {
  14. value, _ := ctx.Get(middleware.Authorization)
  15. claims := value.(*middleware.Claims)
  16. var req model.RequestDeviceCountFilter
  17. err := ctx.ShouldBindQuery(&req)
  18. if err != nil {
  19. ctx.JSON(http.StatusOK, err)
  20. return
  21. }
  22. records, err := service.DeviceCountService.CountDevice(claims.TenantId, req)
  23. if err != nil {
  24. ctx.JSON(http.StatusOK, err)
  25. return
  26. }
  27. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  28. }
  29. func (c deviceCtl) MonthList(ctx *gin.Context) {
  30. value, _ := ctx.Get(middleware.Authorization)
  31. claims := value.(*middleware.Claims)
  32. var req model.RequestDeviceCountFilter
  33. err := ctx.ShouldBindQuery(&req)
  34. if err != nil {
  35. ctx.JSON(http.StatusOK, err)
  36. return
  37. }
  38. var records interface{}
  39. err = nil
  40. if req.QueryType == "day" {
  41. records, err = service.DeviceCountService.GetDayList(claims.TenantId, req)
  42. } else {
  43. records, err = service.DeviceCountService.GetMonthList(claims.TenantId, req)
  44. }
  45. if err != nil {
  46. ctx.JSON(http.StatusOK, err)
  47. return
  48. }
  49. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  50. }
  51. func (c deviceCtl) YearList(ctx *gin.Context) {
  52. value, _ := ctx.Get(middleware.Authorization)
  53. claims := value.(*middleware.Claims)
  54. var req model.RequestDeviceCountFilter
  55. err := ctx.ShouldBindQuery(&req)
  56. if err != nil {
  57. ctx.JSON(http.StatusOK, err)
  58. return
  59. }
  60. records, err := service.DeviceCountService.GetYearList(claims.TenantId, req)
  61. if err != nil {
  62. ctx.JSON(http.StatusOK, err)
  63. return
  64. }
  65. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
  66. }