deviceCoutService.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package service
  2. import (
  3. "iot_manager_service/app/operation/dao"
  4. "iot_manager_service/app/operation/model"
  5. "iot_manager_service/app/warn/service"
  6. )
  7. var DeviceCountService = new(deviceCountService)
  8. type deviceCountService struct{}
  9. func (s deviceCountService) CountDevice(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
  10. list := dao.ViewsAllCodeDevice{
  11. TenantId: tenantId,
  12. }
  13. // TODO: 在线数 未做
  14. counts, err := list.GetDeviceCount()
  15. for i, count := range counts {
  16. warnCount, _ := service.PlatformAlarmService.GetWarnCount(tenantId, count.DeviceType)
  17. counts[i].AlarmCountT = int(warnCount)
  18. counts[i].OffLineCountT = 0 // 在线数 未做
  19. }
  20. if err != nil {
  21. return nil, err
  22. }
  23. return counts, nil
  24. }
  25. func (s deviceCountService) GetYearList(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
  26. list := dao.ViewsAllCodeDevice{
  27. TenantId: tenantId,
  28. }
  29. return list.GetYearDeviceCount(req)
  30. }
  31. func (s deviceCountService) GetMonthList(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
  32. list := dao.ViewsAllCodeDevice{
  33. TenantId: tenantId,
  34. }
  35. return list.GetMonthDeviceCount(req)
  36. }
  37. func (s deviceCountService) GetDayList(tenantId string, req model.RequestDeviceCountFilter) ([]dao.ViewsAllCodeDevice, error) {
  38. list := dao.ViewsAllCodeDevice{
  39. TenantId: tenantId,
  40. }
  41. return list.GetDayDeviceCount(req)
  42. }