package controller import ( "github.com/gin-gonic/gin" "iot_manager_service/app/device/model" "iot_manager_service/app/device/service" "iot_manager_service/util" "math" "net/http" "strconv" ) var IntelligentLighting = new(intelligentLightingCtl) type intelligentLightingCtl struct{} func (c *intelligentLightingCtl) Detail(ctx *gin.Context) { 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 } //当前类型1=灯杆2=灯杆分组 relationType, e := strconv.Atoi(ctx.Query("type")) if e != nil { ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(e.Error(), nil)) return } if relationType == model.RelationTypeLight { detail, err := service.IntelligentLightingService.GetDetailByLight(publicId) if err != nil { ctx.JSON(http.StatusOK, err) return } ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail)) } else if relationType == model.RelationTypeLampPoleGroup { detail, err := service.IntelligentLightingService.GetDetailByGroup(publicId) if err != nil { ctx.JSON(http.StatusOK, err) return } ctx.JSON(http.StatusOK, util.SuccessResponse(util.Succeeded, detail)) } else { ctx.JSON(http.StatusOK, util.ParamsInvalidResponse(model.RelationTypeInvalid, nil)) } } func (c *intelligentLightingCtl) List(ctx *gin.Context) { searchValue := ctx.Query("searchValue") groupId := ctx.Query("groupId") current, _ := strconv.Atoi(ctx.Query("current")) size, _ := strconv.Atoi(ctx.Query("size")) if current == 0 { current = 1 } if size <= 0 || size > 100 { size = 10 } if groupId != "" { } strategies, err := service.IntelligentLightingService.List(searchValue, current, size) 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), } for _, strategy := range strategies { rsp.Records = append(rsp.Records, strategy) } 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) { }