garbageService.go 1009 B

123456789101112131415161718192021222324252627282930313233343536
  1. package service
  2. import (
  3. data "iot_manager_service/app/data/service"
  4. device "iot_manager_service/app/device/service"
  5. "iot_manager_service/app/operation/model"
  6. "iot_manager_service/util/common"
  7. )
  8. var GarbageService = new(garbageService)
  9. type garbageService struct{}
  10. func (s *garbageService) GarbageList(tenantId string, ) ([]model.GarbageDetail, *common.Errors) {
  11. var result []model.GarbageDetail
  12. devices, err := device.GarbageService.GetList(tenantId)
  13. if err != nil {
  14. return nil, err
  15. }
  16. for _, d := range devices {
  17. garbageData := data.GarbageDataService.Get(d.DeviceIMei)
  18. if garbageData != nil {
  19. result = append(result, model.GarbageDetail{
  20. DeviceName: d.DeviceName,
  21. SensorOnePercentage: garbageData.SensorOnePercentage,
  22. SensorTwoPercentage: garbageData.SensorTwoPercentage,
  23. Longitude: d.PoleLng,
  24. Latitude: d.PoleLat,
  25. BatteryPercentage: garbageData.BatteryPercentage,
  26. NetworkState: 1,
  27. })
  28. }
  29. }
  30. return result, nil
  31. }