| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package service
- import (
- "fmt"
- device "iot_manager_service/app/device/service"
- "iot_manager_service/app/operation/model"
- "iot_manager_service/util/cache"
- "iot_manager_service/util/common"
- )
- var EnvironmentService = new(environmentService)
- type environmentService struct{}
- func (s *environmentService) EnvironmentList(tenantId int) ([]model.EnvironmentDetail, *common.Errors) {
- var result []model.EnvironmentDetail
- devices := device.OptoSensorService.GetByTenant(tenantId)
- for _, d := range devices {
- _, values := cache.GetDeviceData(d.Sn)
- detail := model.EnvironmentDetail{CreateDate: d.CreateTime, Name: d.Name, Sn: d.Sn}
- for key, value := range values {
- switch key {
- case model.ModelInfoAirQuality:
- detail.Air = value
- case model.ModelInfoHumidity:
- detail.Humidity = value
- case model.ModelInfoPM25:
- detail.Pm25 = value
- case model.ModelInfoPM10:
- detail.Pm10 = value
- case model.ModelInfoTemprature:
- detail.Temp = value
- case model.ModelInfowindSpeed:
- detail.WindSpeed = value
- case model.ModelInfoPressure:
- detail.Hpa = value
- case model.ModelInfoNoise:
- detail.Noise = value
- case model.ModelInfoLightIntensity:
- detail.Illuminance = value
- case model.ModelInfoWindDirection:
- detail.WindDirection = value
- case model.ModelInfoRainfall:
- detail.Rainfall = value
- case model.ModelInfoUltravioletRays:
- detail.Ultraviolet = value
- }
- }
- if detail.WindSpeed == "无风" {
- detail.WindDirection = "-"
- }
- lampPole, _ := device.LampPoleService.GetOne(d.LampPoleId)
- if lampPole != nil {
- detail.LampPoleLocation = lampPole.InstallLocation
- detail.LampLat = fmt.Sprintf("%f", lampPole.PoleLat)
- detail.LampLng = fmt.Sprintf("%f", lampPole.PoleLng)
- }
- result = append(result, detail)
- }
- return result, nil
- }
|