package handler import ( "city_chips/internal/model" "city_chips/internal/service" "city_chips/pkg/helper/resp" "github.com/gin-gonic/gin" "github.com/spf13/viper" "math/rand" ) type InformationHandler struct { *Handler informationService service.InformationService conf *viper.Viper } func NewInformationHandler( handler *Handler, informationService service.InformationService, conf *viper.Viper, ) *InformationHandler { return &InformationHandler{ Handler: handler, informationService: informationService, conf: conf, } } // GetInformation 获取信息发布数据 func (h *InformationHandler) GetInformation(ctx *gin.Context) { m := make(map[string]any) readings := make(map[string]any) var Large []model.LargeController var information []model.InformationCount for i := 0; i < 10; i++ { records := model.LargeController{ Id: i + 1, DeviceName: model.LargeScreenNames[i], UseState: rand.Intn(2), } Large = append(Large, records) } for i := 0; i < 4; i++ { count := model.InformationCount{ Id: i + 1, InformationType: model.InfoTypes[rand.Intn(len(model.InfoTypes)-1)], Vale: rand.Intn(1000), } information = append(information, count) } readings["Under30"] = rand.Intn(1000) //30以下 readings["Under30And40"] = rand.Intn(1000) //30-40 readings["Under40And50"] = rand.Intn(1000) //40-50 readings["Under50And60"] = rand.Intn(1000) //50-60 readings["More60"] = rand.Intn(1000) //60以上 m["LargeScreen"] = rand.Intn(1000) //大屏总数 m["Normal"] = rand.Intn(1000) //大屏正常数 m["Fault"] = rand.Intn(1000) //大屏故障数 m["Idle"] = rand.Intn(1000) //大屏空闲数 m["UrgentNotice"] = rand.Intn(1000) //紧急通知 m["Policy"] = rand.Intn(1000) //政策法规 m["Activity"] = rand.Intn(1000) //活动预告 m["Large"] = Large //大屏控制 m["Information"] = information //进入信息占比 m["Readings"] = readings //车辆出入记录 resp.HandleSuccess(ctx, m) }