forked from ddrilling/AsbCloudServer
добавлен контроллер для получения диапозона
изменен аргумент метода перестроена логика работы метода и возвращаемое значение
This commit is contained in:
parent
87805a7104
commit
dd711c4aa5
@ -1,5 +1,6 @@
|
||||
using AsbCloudApp.Data.Subsystems;
|
||||
using AsbCloudApp.Requests;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -41,10 +42,10 @@ namespace AsbCloudApp.Services.Subsystems
|
||||
/// <summary>
|
||||
/// Временной диапазон за который есть статистика работы подсистем
|
||||
/// </summary>
|
||||
/// <param name="idSubsystem"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<SubsystemOperationTimeDto>?> GetDateRangeOperationTimeAsync(int idSubsystem, CancellationToken token);
|
||||
Task<IEnumerable<(DateTimeOffset, DateTimeOffset)>?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -185,22 +185,28 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
|
||||
}
|
||||
|
||||
private async Task<(DateTimeOffset, DateTimeOffset)?> GetDateRangeOperationTime(int idSubsystem, CancellationToken token)
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<(DateTimeOffset, DateTimeOffset)>?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
{
|
||||
var dateRange = await db.SubsystemOperationTimes
|
||||
.Where(o => o.Id == idSubsystem)
|
||||
.GroupBy(o => o.IdSubsystem)
|
||||
.Select(g => new
|
||||
{
|
||||
DateFirst = g.Min(o => o.DateStart),
|
||||
DateLast = g.Max(o => o.DateEnd)
|
||||
})
|
||||
.FirstOrDefaultAsync(token);
|
||||
if (dateRange == null)
|
||||
{
|
||||
if (request.IdsSubsystems is null)
|
||||
return null;
|
||||
List<(DateTimeOffset dateFirst, DateTimeOffset dateLast)> result = new();
|
||||
var dateRanges = await db.SubsystemOperationTimes
|
||||
.Where(o => request.IdsSubsystems.Contains(o.IdSubsystem))
|
||||
.GroupBy(o => o.IdSubsystem)
|
||||
.Select(g => new
|
||||
{
|
||||
DateFirst = g.Min(o => o.DateStart),
|
||||
DateLast = g.Max(o => o.DateEnd)
|
||||
})
|
||||
.ToListAsync(token);
|
||||
if (dateRanges.Any() != true)
|
||||
return null;
|
||||
foreach (var dateRange in dateRanges)
|
||||
{
|
||||
var resultItem = (dateRange.DateFirst, dateRange.DateLast);
|
||||
result.Add(resultItem);
|
||||
}
|
||||
(DateTimeOffset dateFirst, DateTimeOffset dateLast) result = (dateRange.DateFirst, dateRange.DateLast);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -268,6 +274,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(well.Timezone.Hours);
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -59,6 +59,19 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получить доступный диапазон дат наработки подсистемы.
|
||||
/// </summary>
|
||||
[HttpGet("rangeDate")]
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetDateRangeOperationTimeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token = default)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
var result = await subsystemOperationTimeService.GetDateRangeOperationTimeAsync(request, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получить список наработок подсистем
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user