bigService.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package service
  2. import (
  3. deviceDao "iot_manager_service/app/device/dao"
  4. )
  5. type BigService interface {
  6. DeviceCount() deviceDao.DeviceStatus
  7. ListDevices() []deviceDao.Device
  8. }
  9. var BigServer = new(bigService)
  10. type bigService struct {
  11. }
  12. // 设备的数量
  13. func (big *bigService) DeviceNum(queryType string) deviceDao.QueryDevices {
  14. var server BigService
  15. server = getService(queryType)
  16. obj := server.DeviceCount()
  17. return deviceDao.QueryDevices{
  18. CountNum: obj.CountNum,
  19. FaultNum: obj.FaultNum,
  20. Devices: server.ListDevices(),
  21. }
  22. }
  23. // 获取灯杆的数量
  24. func (big *bigService) GetLampCount() (int64, int64) {
  25. dao := deviceDao.LampPole{}
  26. all, err1 := dao.CountAll()
  27. fault, err2 := dao.CountFault()
  28. if err1 != nil {
  29. all = 0
  30. }
  31. if err2 != nil {
  32. fault = 0
  33. }
  34. return all, fault
  35. }
  36. // 获取设备的状态
  37. func (big *bigService) DevicesStatus() []deviceDao.DeviceStatus {
  38. //1.灯杆 2.灯控 3.摄像头 4.led 5.环境传感器 6.网关 7. 报警器 8.管理端
  39. //9.路面状况传感器 10.ip音柱 11.集控器 12.抓拍单元
  40. var names = []string{"camera", "wisdomGateway", "lightControl", "switchBox", "infoBoard",
  41. "optoSensor", "zigBee", "aKeyAlarmTerminal", "aKeyAlarmServe", "lampPole", "captureUnit", "bridgeSensor", "ipCast", "manhole"}
  42. var rsp = make([]deviceDao.DeviceStatus, 0, 14) //创建了一个长度为0、容量为14的切片
  43. for _, v := range names {
  44. ds := getService(v).DeviceCount()
  45. ds.DeviceType = v
  46. rsp = append(rsp, ds)
  47. }
  48. return rsp
  49. }
  50. // 报警状态
  51. func (big *bigService) AlarmStatus() []deviceDao.DeviceStatus {
  52. var names = []string{"camera", "lightControl", "infoBoard", "optoSensor",
  53. "zigBee", "lampPole", "captureUnit"}
  54. var rsp = make([]deviceDao.DeviceStatus, 0, 6) //创建了一个长度为0、容量为6的切片
  55. for _, v := range names {
  56. ds := getService(v).DeviceCount()
  57. ds.DeviceType = v
  58. rsp = append(rsp, ds)
  59. }
  60. return rsp
  61. }
  62. // 根据设备名称获取服务
  63. func getService(deviceName string) BigService {
  64. switch deviceName {
  65. case "camera":
  66. return CameraService
  67. case "wisdomGateway", "gateway":
  68. return GatewayService
  69. case "lightControl", "control":
  70. return LightControlService
  71. case "switchBox", "box":
  72. return SwitchBoxService
  73. case "infoBoard", "board":
  74. return InfoBoardService
  75. case "optoSensor", "sensor":
  76. return OptoSensorService
  77. case "zigBee", "zigbee":
  78. return ZigbeeService
  79. case "aKeyAlarmTerminal", "terminal":
  80. return AlarmTerminalService
  81. case "aKeyAlarmServe", "serve":
  82. return AlarmService
  83. case "lampPole", "lamppole":
  84. return LampPoleService
  85. case "captureUnit":
  86. return CaptureUintService
  87. case "bridgeSensor", "xueshui":
  88. return BridgeService
  89. case "ipCast", "ipcast":
  90. return IpBroadcastService
  91. case "manhole":
  92. return ManholeCoverService
  93. default:
  94. return nil
  95. }
  96. }
  97. // 获取能量
  98. func (big *bigService) GetEnergy(start, end string) []deviceDao.Energy {
  99. return deviceDao.GetEnergy(start, end)
  100. }
  101. // 获取灯控状态
  102. func (big *bigService) GetLightRate(tenant string) []interface{} {
  103. return deviceDao.GetLightRate(tenant)
  104. }
  105. // 获取报警信息
  106. func (big *bigService) GetAlarmInfo() deviceDao.AlarmList {
  107. return deviceDao.GetAlarmInfo()
  108. }
  109. // 获取环境监测
  110. func (big *bigService) GetEnv(deviceId string) deviceDao.Environment {
  111. return deviceDao.GetEnvData(deviceId)
  112. }
  113. // 获取led程序
  114. func (big *bigService) GetLEDProgram(tenantId string) []deviceDao.InfoBoardProgram {
  115. return deviceDao.GetLEDProgramList(tenantId)
  116. }
  117. // 获取程序路径
  118. func (big *bigService) GetProgramUrl(id string) deviceDao.Program {
  119. return deviceDao.GetProgramUrl(id)
  120. }
  121. // 获取桥接传感器
  122. func (big *bigService) GetBridgeSensors(tenantId string) []deviceDao.Sensor {
  123. return deviceDao.GetBridgeSensors(tenantId)
  124. }
  125. // 概述
  126. func (big *bigService) OverView(tenantId, padScreen string) []deviceDao.OverViewInfo {
  127. dao := deviceDao.OverView{}
  128. return dao.Query(tenantId, padScreen)
  129. }
  130. // 提交
  131. func (big *bigService) Submit(data []deviceDao.OverView) {
  132. dao := deviceDao.OverView{}
  133. for _, v := range data {
  134. dao.Submit(v)
  135. }
  136. }