information.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package handler
  2. import (
  3. "city_chips/internal/model"
  4. "city_chips/internal/service"
  5. "city_chips/pkg/helper/resp"
  6. "fmt"
  7. "github.com/gin-gonic/gin"
  8. "github.com/spf13/viper"
  9. "math/rand"
  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 < 10; i++ {
  34. name := fmt.Sprintf("显示大屏%v", i+1)
  35. records := model.LargeController{
  36. Id: i + 1,
  37. DeviceName: name,
  38. UseState: rand.Intn(2),
  39. }
  40. Large = append(Large, records)
  41. }
  42. for i := 0; i < 4; i++ {
  43. name := fmt.Sprintf("类型%v", i+1)
  44. count := model.InformationCount{
  45. Id: i + 1,
  46. InformationType: name,
  47. Vale: rand.Intn(1000),
  48. }
  49. information = append(information, count)
  50. }
  51. readings["Under30"] = rand.Intn(1000) //30以下
  52. readings["Under30And40"] = rand.Intn(1000) //30-40
  53. readings["Under40And50"] = rand.Intn(1000) //40-50
  54. readings["Under50And60"] = rand.Intn(1000) //50-60
  55. readings["More60"] = rand.Intn(1000) //60以上
  56. m["LargeScreen"] = rand.Intn(1000) //大屏总数
  57. m["Normal"] = rand.Intn(1000) //大屏正常数
  58. m["Fault"] = rand.Intn(1000) //大屏故障数
  59. m["Idle"] = rand.Intn(1000) //大屏空闲数
  60. m["UrgentNotice"] = rand.Intn(1000) //紧急通知
  61. m["Policy"] = rand.Intn(1000) //政策法规
  62. m["Activity"] = rand.Intn(1000) //活动预告
  63. m["Large"] = Large //大屏控制
  64. m["Information"] = information //进入信息占比
  65. m["Readings"] = readings //车辆出入记录
  66. resp.HandleSuccess(ctx, m)
  67. }