корректировка метода получения диапазона дат по наработкам подсистем,

добавление метода в интерфейс ISubsystemOperationTimeService
This commit is contained in:
eugeniy_ivanov 2022-10-20 14:26:36 +05:00
parent 0b419ec3c6
commit 87805a7104
2 changed files with 16 additions and 4 deletions

View File

@ -36,7 +36,15 @@ namespace AsbCloudApp.Services.Subsystems
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
/// <summary>
/// Временной диапазон за который есть статистика работы подсистем
/// </summary>
/// <param name="idSubsystem"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<SubsystemOperationTimeDto>?> GetDateRangeOperationTimeAsync(int idSubsystem, CancellationToken token);
}
#nullable disable
}

View File

@ -185,9 +185,9 @@ namespace AsbCloudInfrastructure.Services.Subsystems
}
private (DateTimeOffset, DateTimeOffset) GetDateRangeOperationTime(int idSubsystem)
private async Task<(DateTimeOffset, DateTimeOffset)?> GetDateRangeOperationTime(int idSubsystem, CancellationToken token)
{
var dateRange = db.SubsystemOperationTimes
var dateRange = await db.SubsystemOperationTimes
.Where(o => o.Id == idSubsystem)
.GroupBy(o => o.IdSubsystem)
.Select(g => new
@ -195,7 +195,11 @@ namespace AsbCloudInfrastructure.Services.Subsystems
DateFirst = g.Min(o => o.DateStart),
DateLast = g.Max(o => o.DateEnd)
})
.FirstOrDefault();
.FirstOrDefaultAsync(token);
if (dateRange == null)
{
return null;
}
(DateTimeOffset dateFirst, DateTimeOffset dateLast) result = (dateRange.DateFirst, dateRange.DateLast);
return result;
}