1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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"
- )
- 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))
- }
|