home.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package handler
  2. import (
  3. "city_chips/internal/service"
  4. "city_chips/pkg/helper/resp"
  5. "github.com/gin-gonic/gin"
  6. "github.com/spf13/viper"
  7. "math/rand"
  8. )
  9. type HomeHandler struct {
  10. *Handler
  11. homeService service.HomeService
  12. conf *viper.Viper
  13. }
  14. func NewHomeHandler(handler *Handler, homeService service.HomeService, conf *viper.Viper) *HomeHandler {
  15. return &HomeHandler{
  16. Handler: handler,
  17. homeService: homeService,
  18. conf: conf,
  19. }
  20. }
  21. // GetHome 获取首页数据
  22. func (h *HomeHandler) GetHome(ctx *gin.Context) {
  23. m := make(map[string]any)
  24. Alarm := make(map[string]any)
  25. m["Area"] = rand.Intn(1000) //建筑面积
  26. m["FloorSpace"] = rand.Intn(1000) //占地面积
  27. m["BuildingHeight"] = rand.Intn(1000) //建筑高度
  28. m["Storey"] = rand.Intn(1000) //建筑层数
  29. m["Device"] = rand.Intn(1000) //设备总数
  30. m["Runing"] = rand.Intn(1000) //运行总数
  31. m["Fault"] = rand.Intn(1000) //设备故障
  32. m["Alarm"] = rand.Intn(1000) //报警数量
  33. m["TodayConsumption"] = rand.Intn(1000) //今日电能耗
  34. m["WeekConsumption"] = rand.Intn(1000) //本周电能耗
  35. m["MonthConsumption"] = rand.Intn(1000) //本月电能耗
  36. m["YearConsumption"] = rand.Intn(1000) //本年电能耗
  37. m["Impetus"] = rand.Intn(1000) //动力能耗
  38. m["illuminating"] = rand.Intn(1000) //照明能耗
  39. m["SpecialElectricity"] = rand.Intn(1000) //特殊用电能耗
  40. m["AirConditioningSockets"] = rand.Intn(1000) //空调插座能耗
  41. m["TodaysTicket"] = rand.Intn(1000) //今日工单
  42. m["ConductedTicket"] = rand.Intn(1000) //进行工单
  43. m["TimeoutTicket"] = rand.Intn(1000) //超时工单
  44. m["Demands"] = rand.Intn(1000) //诉求总数
  45. m["DisposeDemands"] = rand.Intn(1000) //已处理诉求
  46. m["UnDisposeDemands"] = rand.Intn(1000) //未处理诉求
  47. m["TodayDisposeDemands"] = rand.Intn(1000) //今日新增
  48. m["OccupationDriveway"] = rand.Intn(1000) //占用车位
  49. m["IdleDriveway"] = rand.Intn(1000) //空闲车位
  50. Alarm["2025-5-1"] = rand.Intn(1000)
  51. Alarm["2025-5-2"] = rand.Intn(1000)
  52. Alarm["2025-5-3"] = rand.Intn(1000)
  53. Alarm["2025-5-4"] = rand.Intn(1000)
  54. Alarm["2025-5-5"] = rand.Intn(1000)
  55. Alarm["2025-5-6"] = rand.Intn(1000)
  56. Alarm["2025-5-7"] = rand.Intn(1000)
  57. m["AlarmCount"] = Alarm //报警统计
  58. resp.HandleSuccess(ctx, m)
  59. }