123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "iot_manager_service/app/middleware"
- "iot_manager_service/app/operation/model"
- "iot_manager_service/app/operation/service"
- "iot_manager_service/util/common"
- "net/http"
- )
- // Device 设备统计
- var Device = new(deviceCtl)
- type deviceCtl struct{}
- func (c deviceCtl) CountDevice(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- var req model.RequestDeviceCountFilter
- err := ctx.ShouldBindQuery(&req)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- records, err := service.DeviceCountService.CountDevice(claims.TenantId, req)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
- }
- func (c deviceCtl) MonthList(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- var req model.RequestDeviceCountFilter
- err := ctx.ShouldBindQuery(&req)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- var records interface{}
- err = nil
- if req.QueryType == "day" {
- records, err = service.DeviceCountService.GetDayList(claims.TenantId, req)
- } else {
- records, err = service.DeviceCountService.GetMonthList(claims.TenantId, req)
- }
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
- }
- func (c deviceCtl) YearList(ctx *gin.Context) {
- value, _ := ctx.Get(middleware.Authorization)
- claims := value.(*middleware.Claims)
- var req model.RequestDeviceCountFilter
- err := ctx.ShouldBindQuery(&req)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- records, err := service.DeviceCountService.GetYearList(claims.TenantId, req)
- if err != nil {
- ctx.JSON(http.StatusOK, err)
- return
- }
- ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, records))
- }
|