bigController.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package controller
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/sirupsen/logrus"
  6. "iot_manager_service/app/device/dao"
  7. "iot_manager_service/app/device/service"
  8. "iot_manager_service/app/middleware"
  9. "iot_manager_service/util/common"
  10. "net/http"
  11. "strconv"
  12. )
  13. //点击获取当前设备总数/状态数量+列表
  14. //http://localhost/api/longchi/largescreen/mapclieck/device-num?queryType=lampPole
  15. //需要数据:
  16. //countNum:灯杆总数,
  17. //faultNum:灯杆报警数,
  18. //[]polist:(lng经度,lat纬度,status:状态,name:名字,code:编码,lampPoleName:灯杆名,brand:品牌,model:型号,linkNum:连接设备数,)
  19. var BigScreen = new(bigScreen)
  20. type bigScreen struct {
  21. }
  22. func (big *bigScreen) DeviceNum(ctx *gin.Context) {
  23. queryType := ctx.Query("queryType")
  24. rsp := service.BigServer.DeviceNum(queryType)
  25. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
  26. }
  27. func (big *bigScreen) LampPoleStatus(ctx *gin.Context) {
  28. var rsp dao.TotalLamp
  29. all, fault := service.BigServer.GetLampCount()
  30. rsp.CountNum = all
  31. rsp.FaultNum = fault
  32. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  33. }
  34. // DevicesStatus 设备统计 /api/longchi/largescreen/overview/device-status
  35. func (big *bigScreen) DevicesStatus(ctx *gin.Context) {
  36. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, service.BigServer.DevicesStatus()))
  37. }
  38. // Energy 能耗: /api/longchi/largescreen/overview/energy-consumption
  39. func (big *bigScreen) Energy(ctx *gin.Context) {
  40. fmt.Printf("Start:%v,End:%v\n", ctx.Query("startDate"), ctx.Query("endDate"))
  41. rsp := service.BigServer.GetEnergy(ctx.Query("startDate"), ctx.Query("endDate"))
  42. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  43. }
  44. // LightRate 亮灯率: /api/longchi/largescreen/overview/lighting-rate
  45. func (big *bigScreen) LightRate(ctx *gin.Context) {
  46. authorization := ctx.GetHeader("Authorization")
  47. claims := middleware.ParseAccessToken(authorization)
  48. //rsp := service.BigServer.GetLightRate(claims.TenantId)
  49. //var rsp = make([]interface{}, 0, 4)
  50. //var lrm = dao.LightRateM{Month: "2023-07", Rate: 30}
  51. //var lrq = dao.LightRateQ{Quarter: "3", Rate: 50}
  52. //var lry = dao.LightRateY{Year: "2023", Rate: 50}
  53. //rsp = append(rsp, []interface{}{})
  54. //rsp = append(rsp, lrm)
  55. //rsp = append(rsp, lrq)
  56. //rsp = append(rsp, lry)
  57. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, service.BigServer.GetLightRate(claims.TenantId)))
  58. }
  59. // AlarmInfo http://localhost/api/longchi/largescreen/overview/alarm-information
  60. func (big *bigScreen) AlarmInfo(ctx *gin.Context) {
  61. rsp := service.BigServer.GetAlarmInfo()
  62. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  63. }
  64. // AlarmStatistics 报警设备统计 http://localhost/api/longchi/largescreen/overview/alarm-device-count?startDate=2022-07-10&endDate=2023-07-10
  65. func (big *bigScreen) AlarmStatistics(ctx *gin.Context) {
  66. //deviceType faultNum
  67. rsp := service.BigServer.AlarmStatus()
  68. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  69. }
  70. // FlowInfo 工单信息 http://localhost/api/longchi/largescreen/overview/flow-information
  71. func (big *bigScreen) FlowInfo(ctx *gin.Context) {
  72. //deviceType faultNum
  73. rsp := service.BigServer.AlarmStatus()
  74. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  75. }
  76. func (big *bigScreen) Environment(ctx *gin.Context) {
  77. deviceId := ctx.Query("id")
  78. rsp := service.BigServer.GetEnv(deviceId)
  79. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  80. }
  81. func (big *bigScreen) InfoBoard(ctx *gin.Context) {
  82. authorization := ctx.GetHeader("Authorization")
  83. claims := middleware.ParseAccessToken(authorization)
  84. rsp := service.BigServer.GetLEDProgram(claims.TenantId)
  85. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  86. }
  87. func (big *bigScreen) Program(ctx *gin.Context) {
  88. id := ctx.Query("id")
  89. atoi, _ := strconv.Atoi(id)
  90. rsp := service.BigServer.GetProgramUrl(id)
  91. rsp.Id = int64(atoi)
  92. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  93. }
  94. func (big *bigScreen) BridgeSensor(ctx *gin.Context) {
  95. authorization := ctx.GetHeader("Authorization")
  96. claims := middleware.ParseAccessToken(authorization)
  97. rsp := service.BigServer.GetBridgeSensors(claims.TenantId)
  98. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  99. }
  100. // QueryOverView http://localhost/api/longchi/largescreen/setting/query-large-screen?padScreen=overview
  101. func (big *bigScreen) QueryOverView(ctx *gin.Context) {
  102. padScreen := ctx.Query("padScreen")
  103. authorization := ctx.GetHeader("Authorization")
  104. claims := middleware.ParseAccessToken(authorization)
  105. rsp := service.BigServer.OverView(claims.TenantId, padScreen)
  106. ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
  107. }
  108. func (big *bigScreen) SubmitOverView(ctx *gin.Context) {
  109. authorization := ctx.GetHeader("Authorization")
  110. claims := middleware.ParseAccessToken(authorization)
  111. var req []dao.OverView
  112. err := ctx.ShouldBind(&req)
  113. if err != nil {
  114. logrus.Errorf("SubmitOverView ShouldBind error:%v", err)
  115. }
  116. for i, _ := range req {
  117. req[i].TenantId = claims.TenantId
  118. }
  119. service.BigServer.Submit(req)
  120. ctx.JSON(200, "")
  121. }