123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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"
- "time"
- )
- 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 < 20; i++ {
- records := model.LargeController{
- Id: i + 1,
- DeviceName: model.LargeScreenNames[i],
- UseState: rand.Intn(2),
- }
- Large = append(Large, records)
- }
- for i := 0; i < 20; i++ {
- count := model.InformationCount{
- Id: i + 1,
- DeviceName: model.GetRandomItem(model.LargeScreenNames),
- State: rand.Intn(2),
- Date: time.Now().Format("2006-01-02 15:04:05"),
- }
- information = append(information, count)
- }
- readings["online"] = rand.Intn(100) //在线率
- readings["unline"] = rand.Intn(1000) //离线率
- m["LargeScreen"] = rand.Intn(1000) //大屏总数
- m["Normal"] = rand.Intn(1000) //大屏正常数
- m["Fault"] = rand.Intn(1000) //大屏故障数
- m["Idle"] = rand.Intn(1000) //大屏空闲数
- m["Large"] = Large //大屏控制
- m["Information"] = information //进入信息占比
- resp.HandleSuccess(ctx, m)
- }
|