package controller import ( "github.com/gin-gonic/gin" "iot_manager_service/app/device/model" "iot_manager_service/app/device/service" "iot_manager_service/app/middleware" "iot_manager_service/util" "math" "net/http" "strconv" ) var IntelligentLighting = new(intelligentLightingCtl) type intelligentLightingCtl struct{} func (c *intelligentLightingCtl) Detail(ctx *gin.Context) { value, _ := ctx.Get(middleware.Authorization) claims := value.(*middleware.Claims) publicId, e := strconv.Atoi(ctx.Query("publicId")) if e != nil { ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil)) return } if publicId == 0 { ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.RelationIdInvalid, nil)) return } detail, err := service.IntelligentLightingService.GetDetailByLight(claims.TenantId, publicId) if err != nil { ctx.JSON(http.StatusOK, err) return } ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail)) } func (c *intelligentLightingCtl) List(ctx *gin.Context) { value, _ := ctx.Get(middleware.Authorization) claims := value.(*middleware.Claims) searchValue := ctx.Query("searchValue") groupId := ctx.Query("groupId") current, _ := strconv.Atoi(ctx.Query("current")) size, _ := strconv.Atoi(ctx.Query("size")) gId, err := strconv.Atoi(groupId) if err != nil { ctx.JSON(http.StatusOK, util.ParamsInvalidResponse("groupId invalid", nil)) return } if current == 0 { current = 1 } if size <= 0 || size > 100 { size = 10 } strategies, err := service.IntelligentLightingService.List(claims.TenantId, searchValue, current, size, gId) if err != nil { ctx.JSON(http.StatusOK, err) return } pages := math.Ceil(float64(len(strategies)) / float64(size)) rsp := model.RspIntelligentLightList{ Current: current, Size: size, Total: len(strategies), Pages: int(pages), Records: strategies, } ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, rsp)) } func (c *intelligentLightingCtl) RelationList(ctx *gin.Context) { } func (c *intelligentLightingCtl) Relation(ctx *gin.Context) { } func (c *intelligentLightingCtl) Remove(ctx *gin.Context) { } func (c *intelligentLightingCtl) ChangeHandSwitch(ctx *gin.Context) { } func (c *intelligentLightingCtl) GetStatus(ctx *gin.Context) { }