information.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. var Large []model.LargeController
  31. var information []model.InformationCount
  32. for i := 0; i < 20; i++ {
  33. records := model.LargeController{
  34. Id: i + 1,
  35. DeviceName: model.GetRandomItem(model.LargeScreenNames),
  36. UseState: rand.Intn(2),
  37. }
  38. Large = append(Large, records)
  39. }
  40. for i := 0; i < 20; i++ {
  41. count := model.InformationCount{
  42. Id: i + 1,
  43. DeviceName: model.GetRandomItem(model.LargeScreenNames),
  44. State: rand.Intn(2),
  45. Date: time.Now().Format("2006-01-02 15:04:05"),
  46. }
  47. information = append(information, count)
  48. }
  49. m["LargeScreen"] = rand.Intn(1000) //大屏总数
  50. m["Normal"] = rand.Intn(1000) //大屏正常数
  51. m["Fault"] = rand.Intn(1000) //大屏故障数
  52. m["Idle"] = rand.Intn(1000) //大屏空闲数
  53. m["Large"] = Large //大屏控制
  54. m["Information"] = information //进入信息占比
  55. m["online"] = rand.Intn(100) //在线率
  56. m["unline"] = rand.Intn(100) //离线率
  57. resp.HandleSuccess(ctx, m)
  58. }