DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellReport/WellReportService.cs
2024-08-23 16:43:09 +05:00

116 lines
3.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Data.WellReport;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services.WellReport;
public class WellReportService : IWellReportService
{
private readonly IWellService wellService;
private readonly IWellOperationService wellOperationService;
private readonly IWellOperationRepository wellOperationRepository;
private readonly ITrajectoryRepository<TrajectoryGeoPlanDto> trajectoryPlanRepository;
private readonly ITrajectoryRepository<TrajectoryGeoFactDto> trajectoryFactRepository;
private readonly IWellContactService wellContactService;
public WellReportService()
{
}
public async Task<WellReportDto> GetAsync(int idWell, CancellationToken token)
{
var wellOperationRequest = new WellOperationRequest(new[] { idWell })
{
OperationType = WellOperation.IdOperationTypeFact
};
var factOperations = (await wellOperationService.GetAsync(wellOperationRequest, token))
.OrderBy(x => x.DateStart);
if (!factOperations.Any())
throw new ArgumentInvalidException(nameof(idWell), "Данные в ГГД факт отсутствуют");
wellOperationRequest.OperationType = WellOperation.IdOperationTypePlan;
var planOperations = (await wellOperationService.GetAsync(wellOperationRequest, token))
.OrderBy(x => x.DateStart);
if (!planOperations.Any())
throw new ArgumentInvalidException(nameof(idWell), "Данные ГГД план отсутствуют");
var wellContactRequest = new WellContactRequest()
{
IdsWells = new[] { idWell },
};
var well = await wellService.GetOrDefaultAsync(idWell, token)
?? throw new ArgumentInvalidException(nameof(idWell), "Скважина не найдена");
var drillingInfo = await GetDrillingInfoAsync(idWell, planOperations, factOperations, token);
var contacts = await wellContactService.GetAllAsync(wellContactRequest, token);
return new WellReportDto
{
Well = well,
DrillingInfo = drillingInfo,
Constacts = contacts,
};
}
private async Task<IEnumerable<PlanFactDto<OperatingModeItemDto>>> GetOperationModeAsync(int idWell,
IEnumerable<WellOperationDto> factWellOperations, CancellationToken token)
{
}
private async Task<DrillingInfoDto> GetDrillingInfoAsync(int idWell,
IEnumerable<WellOperationDto> planOperations,
IEnumerable<WellOperationDto> factOperations,
CancellationToken token)
{
var firstFactOperation = factOperations.First();
var lastFactOperation = factOperations.Last();
var lastPlanOperation = planOperations.Last();
var planTrajectories = await trajectoryPlanRepository.GetAsync(idWell, token);
var factTrajectories = await trajectoryFactRepository.GetAsync(idWell, token);
var drillingInfo = new DrillingInfoDto
{
Dates = new DatesRangeDto
{
From = firstFactOperation.DateStart,
To = lastPlanOperation.DateStart.AddHours(lastPlanOperation.DurationHours),
},
Days = new PlanFactDto<double>
{
Plan = lastPlanOperation.Day,
Fact = lastFactOperation.Day
},
WellBoreDepth = new PlanFactDto<double>
{
Plan = planOperations.Max(x => x.DepthEnd),
Fact = factOperations.Max(x => x.DepthEnd)
},
VerticalDepth = new PlanFactDto<double?>
{
Plan = planTrajectories.Max(x => x.VerticalDepth),
Fact = factTrajectories.Max(x => x.VerticalDepth)
},
};
return drillingInfo;
}
}