information.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package handler
  2. import (
  3. "city_chips/internal/model"
  4. "city_chips/internal/service"
  5. "city_chips/pkg/helper/resp"
  6. "github.com/gin-gonic/gin"
  7. "github.com/spf13/viper"
  8. "math/rand"
  9. "time"
  10. )
  11. type InformationHandler struct {
  12. *Handler
  13. informationService service.InformationService
  14. conf *viper.Viper
  15. }
  16. func NewInformationHandler(
  17. handler *Handler,
  18. informationService service.InformationService,
  19. conf *viper.Viper,
  20. ) *InformationHandler {
  21. return &InformationHandler{
  22. Handler: handler,
  23. informationService: informationService,
  24. conf: conf,
  25. }
  26. }
  27. // GetInformation 获取信息发布数据
  28. func (h *InformationHandler) GetInformation(ctx *gin.Context) {
  29. m := make(map[string]any)
  30. readings := make(map[string]any)
  31. var Large []model.LargeController
  32. var information []model.InformationCount
  33. for i := 0; i < 20; i++ {
  34. records := model.LargeController{
  35. Id: i + 1,
  36. DeviceName: model.LargeScreenNames[i],
  37. UseState: rand.Intn(2),
  38. }
  39. Large = append(Large, records)
  40. }
  41. for i := 0; i < 20; i++ {
  42. count := model.InformationCount{
  43. Id: i + 1,
  44. DeviceName: model.GetRandomItem(model.LargeScreenNames),
  45. State: rand.Intn(2),
  46. Date: time.Now().Format("2006-01-02 15:04:05"),
  47. }
  48. information = append(information, count)
  49. }
  50. readings["online"] = rand.Intn(100) //在线率
  51. readings["unline"] = rand.Intn(1000) //离线率
  52. m["LargeScreen"] = rand.Intn(1000) //大屏总数
  53. m["Normal"] = rand.Intn(1000) //大屏正常数
  54. m["Fault"] = rand.Intn(1000) //大屏故障数
  55. m["Idle"] = rand.Intn(1000) //大屏空闲数
  56. m["Large"] = Large //大屏控制
  57. m["Information"] = information //进入信息占比
  58. resp.HandleSuccess(ctx, m)
  59. }