deviceCountController.go 1.9 KB

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