information.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. )
  10. type InformationHandler struct {
  11. *Handler
  12. informationService service.InformationService
  13. conf *viper.Viper
  14. }
  15. func NewInformationHandler(
  16. handler *Handler,
  17. informationService service.InformationService,
  18. conf *viper.Viper,
  19. ) *InformationHandler {
  20. return &InformationHandler{
  21. Handler: handler,
  22. informationService: informationService,
  23. conf: conf,
  24. }
  25. }
  26. // GetInformation 获取信息发布数据
  27. func (h *InformationHandler) GetInformation(ctx *gin.Context) {
  28. m := make(map[string]any)
  29. readings := make(map[string]any)
  30. var Large []model.LargeController
  31. var information []model.InformationCount
  32. for i := 0; i < 10; i++ {
  33. records := model.LargeController{
  34. Id: i + 1,
  35. DeviceName: model.LargeScreenNames[i],
  36. UseState: rand.Intn(2),
  37. }
  38. Large = append(Large, records)
  39. }
  40. for i := 0; i < 4; i++ {
  41. count := model.InformationCount{
  42. Id: i + 1,
  43. InformationType: model.InfoTypes[rand.Intn(len(model.InfoTypes)-1)],
  44. Vale: rand.Intn(1000),
  45. }
  46. information = append(information, count)
  47. }
  48. readings["Under30"] = rand.Intn(1000) //30以下
  49. readings["Under30And40"] = rand.Intn(1000) //30-40
  50. readings["Under40And50"] = rand.Intn(1000) //40-50
  51. readings["Under50And60"] = rand.Intn(1000) //50-60
  52. readings["More60"] = rand.Intn(1000) //60以上
  53. m["LargeScreen"] = rand.Intn(1000) //大屏总数
  54. m["Normal"] = rand.Intn(1000) //大屏正常数
  55. m["Fault"] = rand.Intn(1000) //大屏故障数
  56. m["Idle"] = rand.Intn(1000) //大屏空闲数
  57. m["UrgentNotice"] = rand.Intn(1000) //紧急通知
  58. m["Policy"] = rand.Intn(1000) //政策法规
  59. m["Activity"] = rand.Intn(1000) //活动预告
  60. m["Large"] = Large //大屏控制
  61. m["Information"] = information //进入信息占比
  62. m["Readings"] = readings //车辆出入记录
  63. resp.HandleSuccess(ctx, m)
  64. }