bigService.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. func (big *bigService) DeviceNum(queryType string) deviceDao.QueryDevices {
  13. var server BigService
  14. server = getService(queryType)
  15. obj := server.DeviceCount()
  16. return deviceDao.QueryDevices{
  17. CountNum: obj.CountNum,
  18. FaultNum: obj.FaultNum,
  19. Devices: server.ListDevices(),
  20. }
  21. }
  22. func (big *bigService) GetLampCount() (int64, int64) {
  23. dao := deviceDao.LampPole{}
  24. all, err1 := dao.CountAll()
  25. fault, err2 := dao.CountFault()
  26. if err1 != nil {
  27. all = 0
  28. }
  29. if err2 != nil {
  30. fault = 0
  31. }
  32. return all, fault
  33. }
  34. func (big *bigService) DevicesStatus() []deviceDao.DeviceStatus {
  35. //1.灯杆 2.灯控 3.摄像头 4.led 5.环境传感器 6.网关 7. 报警器 8.管理端
  36. //9.路面状况传感器 10.ip音柱 11.集控器 12.抓拍单元
  37. var names = []string{"camera", "wisdomGateway", "lightControl", "switchBox", "infoBoard",
  38. "optoSensor", "zigBee", "aKeyAlarmTerminal", "aKeyAlarmServe", "lampPole", "captureUnit", "bridgeSensor", "ipCast", "manhole"}
  39. var rsp = make([]deviceDao.DeviceStatus, 0, 14)
  40. for _, v := range names {
  41. ds := getService(v).DeviceCount()
  42. ds.DeviceType = v
  43. rsp = append(rsp, ds)
  44. }
  45. return rsp
  46. }
  47. func (big *bigService) AlarmStatus() []deviceDao.DeviceStatus {
  48. var names = []string{"camera", "lightControl", "infoBoard", "optoSensor",
  49. "zigBee", "lampPole", "captureUnit"}
  50. var rsp = make([]deviceDao.DeviceStatus, 0, 6)
  51. for _, v := range names {
  52. ds := getService(v).DeviceCount()
  53. ds.DeviceType = v
  54. rsp = append(rsp, ds)
  55. }
  56. return rsp
  57. }
  58. func getService(deviceName string) BigService {
  59. switch deviceName {
  60. case "camera":
  61. return CameraService
  62. case "wisdomGateway", "gateway":
  63. return GatewayService
  64. case "lightControl", "control":
  65. return LightControlService
  66. case "switchBox", "box":
  67. return SwitchBoxService
  68. case "infoBoard", "board":
  69. return InfoBoardService
  70. case "optoSensor", "sensor":
  71. return OptoSensorService
  72. case "zigBee", "zigbee":
  73. return ZigbeeService
  74. case "aKeyAlarmTerminal", "terminal":
  75. return AlarmTerminalService
  76. case "aKeyAlarmServe", "serve":
  77. return AlarmService
  78. case "lampPole", "lamppole":
  79. return LampPoleService
  80. case "captureUnit":
  81. return CaptureUintService
  82. case "bridgeSensor", "xueshui":
  83. return BridgeService
  84. case "ipCast", "ipcast":
  85. return IpBroadcastService
  86. case "manhole":
  87. return ManholeCoverService
  88. default:
  89. return nil
  90. }
  91. }
  92. func (big *bigService) GetEnergy(start, end string) []deviceDao.Energy {
  93. return deviceDao.GetEnergy(start, end)
  94. }
  95. func (big *bigService) GetLightRate(tenant string) []interface{} {
  96. return deviceDao.GetLightRate(tenant)
  97. }
  98. func (big *bigService) GetAlarmInfo() deviceDao.AlarmList {
  99. return deviceDao.GetAlarmInfo()
  100. }
  101. func (big *bigService) GetEnv(deviceId string) deviceDao.Environment {
  102. return deviceDao.GetEnvData(deviceId)
  103. }
  104. func (big *bigService) GetLEDProgram(tenantId string) []deviceDao.InfoBoardProgram {
  105. return deviceDao.GetLEDProgramList(tenantId)
  106. }
  107. func (big *bigService) GetProgramUrl(id string) deviceDao.Program {
  108. return deviceDao.GetProgramUrl(id)
  109. }
  110. func (big *bigService) GetBridgeSensors(tenantId string) []deviceDao.Sensor {
  111. return deviceDao.GetBridgeSensors(tenantId)
  112. }
  113. func (big *bigService) OverView(tenantId, padScreen string) []deviceDao.OverViewInfo {
  114. dao := deviceDao.OverView{}
  115. return dao.Query(tenantId, padScreen)
  116. }
  117. func (big *bigService) Submit(data []deviceDao.OverView) {
  118. dao := deviceDao.OverView{}
  119. for _, v := range data {
  120. dao.Submit(v)
  121. }
  122. }