environmentService.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package service
  2. import (
  3. "fmt"
  4. device "iot_manager_service/app/device/service"
  5. "iot_manager_service/app/operation/model"
  6. "iot_manager_service/util/cache"
  7. "iot_manager_service/util/common"
  8. )
  9. var EnvironmentService = new(environmentService)
  10. type environmentService struct{}
  11. func (s *environmentService) EnvironmentList(tenantId int) ([]model.EnvironmentDetail, *common.Errors) {
  12. var result []model.EnvironmentDetail
  13. devices := device.OptoSensorService.GetByTenant(tenantId)
  14. for _, d := range devices {
  15. _, values := cache.GetDeviceData(d.Sn)
  16. detail := model.EnvironmentDetail{CreateDate: d.CreateTime, Name: d.Name, Sn: d.Sn}
  17. for key, value := range values {
  18. switch key {
  19. case model.ModelInfoAirQuality:
  20. detail.Air = value
  21. case model.ModelInfoHumidity:
  22. detail.Humidity = value
  23. case model.ModelInfoPM25:
  24. detail.Pm25 = value
  25. case model.ModelInfoPM10:
  26. detail.Pm10 = value
  27. case model.ModelInfoTemprature:
  28. detail.Temp = value
  29. case model.ModelInfowindSpeed:
  30. detail.WindSpeed = value
  31. case model.ModelInfoPressure:
  32. detail.Hpa = value
  33. case model.ModelInfoNoise:
  34. detail.Noise = value
  35. case model.ModelInfoLightIntensity:
  36. detail.Illuminance = value
  37. case model.ModelInfoWindDirection:
  38. detail.WindDirection = value
  39. case model.ModelInfoRainfall:
  40. detail.Rainfall = value
  41. case model.ModelInfoUltravioletRays:
  42. detail.Ultraviolet = value
  43. }
  44. }
  45. if detail.WindSpeed == "无风" {
  46. detail.WindDirection = "-"
  47. }
  48. lampPole, _ := device.LampPoleService.GetOne(d.LampPoleId)
  49. if lampPole != nil {
  50. detail.LampPoleLocation = lampPole.InstallLocation
  51. detail.LampLat = fmt.Sprintf("%f", lampPole.PoleLat)
  52. detail.LampLng = fmt.Sprintf("%f", lampPole.PoleLng)
  53. }
  54. result = append(result, detail)
  55. }
  56. return result, nil
  57. }