diff --git a/AsbCloudApp/Data/DrillerDetectedOperationStatDto.cs b/AsbCloudApp/Data/DrillerDetectedOperationStatDto.cs index d350c838..96a5a232 100644 --- a/AsbCloudApp/Data/DrillerDetectedOperationStatDto.cs +++ b/AsbCloudApp/Data/DrillerDetectedOperationStatDto.cs @@ -3,10 +3,23 @@ using AsbCloudApp.Data.Subsystems; namespace AsbCloudApp.Data; -public record DrillerDetectedOperationStatDto +/// +/// статистика наработки по бурильщикам +/// +public class DrillerDetectedOperationStatDto { - public DrillerDto driller; - public IEnumerable statistic; - public ScheduleDto schedule; - public IEnumerable well; + /// + /// Статистики подсистем + /// + public IEnumerable Statistic { get; set; } = null!; + + /// + /// Расписание бурильщика + /// + public ScheduleDto Schedule { get; set; } = null!; + + /// + /// Скважина + /// + public WellDto Well { get; set; } = null!; } \ No newline at end of file diff --git a/AsbCloudApp/Requests/GetStatRequest.cs b/AsbCloudApp/Requests/GetStatRequest.cs index 607c0fc6..8794198b 100644 --- a/AsbCloudApp/Requests/GetStatRequest.cs +++ b/AsbCloudApp/Requests/GetStatRequest.cs @@ -1,9 +1,20 @@ using System.Collections.Generic; +using System.Linq; namespace AsbCloudApp.Requests; +/// +/// Запрос на получение статистики использования подсистем бурильщиком +/// public class GetStatRequest: RequestBase { - public IEnumerable idWell; - public int? idDriller; + /// + /// id скважин + /// + public IEnumerable IdsWells { get; set; } = Enumerable.Empty(); + + /// + /// id Бурильщика + /// + public int? IdDriller { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Services/ISubsystemService.cs b/AsbCloudApp/Services/ISubsystemService.cs index 7ccc0aa1..b82563f8 100644 --- a/AsbCloudApp/Services/ISubsystemService.cs +++ b/AsbCloudApp/Services/ISubsystemService.cs @@ -29,6 +29,12 @@ public interface ISubsystemService /// Task> GetStatByActiveWells(IEnumerable wellIds, CancellationToken token); + /// + /// Получение статистики РїРѕ бурильщику + /// + /// + /// + /// Task> GetByWellsAsync(GetStatRequest request, CancellationToken token); } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/ScheduleRepository.cs b/AsbCloudInfrastructure/Repository/ScheduleRepository.cs index 971cd735..e7c2aa1f 100644 --- a/AsbCloudInfrastructure/Repository/ScheduleRepository.cs +++ b/AsbCloudInfrastructure/Repository/ScheduleRepository.cs @@ -56,9 +56,9 @@ namespace AsbCloudInfrastructure.Repository public async Task> GetPageAsync(GetStatRequest request, CancellationToken token) { - var idWell = request.idWell; - var idDriller = request.idDriller; - var query = GetQuery().Where(s => request.idWell.Contains(s.IdWell)); + var idWell = request.IdsWells; + var idDriller = request.IdDriller; + var query = GetQuery().Where(s => request.IdsWells.Contains(s.IdWell)); if (idDriller is not null) { query.Where(s => s.IdDriller == idDriller); diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs index 36f373b0..ed2571a9 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs @@ -56,13 +56,12 @@ internal class SubsystemService : ISubsystemService { var result = new List(); var schedulePage = await scheduleRepository.GetPageAsync(request, token); - var wellTree = await wellService.GetAsync(new WellRequest { Ids = request.idWell }, token); - var wellGroup = wellTree.GroupBy(w => w.Id); + var wells = await wellService.GetAsync(new WellRequest { Ids = request.IdsWells }, token); foreach (var schedule in schedulePage) { var idWell = schedule.IdWell; - var well = wellGroup?.FirstOrDefault(w=> w.Key == idWell); + var well = wells.FirstOrDefault(w=> w.Id == idWell)!; var byWellRequest = new DetectedOperationByWellRequest(idWell, new DetectedOperationRequest()); @@ -78,16 +77,15 @@ internal class SubsystemService : ISubsystemService var drillerOperationsStat = await CalcStatAsync(entry, token); var dto = new DrillerDetectedOperationStatDto { - driller = entry.Key!, - statistic = drillerOperationsStat, - schedule = schedule, - well = well! + Statistic = drillerOperationsStat, + Schedule = schedule, + Well = well, }; result.Add(dto); } } - return await Task.FromResult(result); + return result; } public async Task> GetStatAsync(SubsystemRequest request, CancellationToken token) diff --git a/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs b/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs index 19c21641..4d16958b 100644 --- a/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs +++ b/AsbCloudWebApi/Controllers/Subsystems/SubsystemController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -62,13 +63,17 @@ namespace AsbCloudWebApi.Controllers.Subsystems return Ok(dateRange); } - [HttpGet("operationsReport/{idWell}")] - [ProducesResponseType(typeof(DrillerDetectedOperationStatDto), (int)System.Net.HttpStatusCode.OK)] - public async Task GetStatDateRangeAsync([FromRoute] int idWell, GetStatRequest request, + [HttpGet("drillerDetectedOperationStat")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetByWellsAsync(GetStatRequest request, CancellationToken token) { - if (!await UserHasAccessToWellAsync(idWell, token)) - return Forbid(); + if (!request.IdsWells.Any()) + return NoContent(); + + foreach(var idWell in request.IdsWells) + if (!await UserHasAccessToWellAsync(idWell, token)) + return Forbid(); var result = await subsystemService.GetByWellsAsync(request, token);