2023-11-03 19:24:58 +05:00
|
|
|
|
using AsbCloudApp.Data.DailyReport;
|
2023-03-09 11:38:43 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
2023-03-21 15:55:03 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2023-03-09 11:38:43 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-04-29 15:39:12 +05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks.Sign;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks.Subsystems;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance;
|
|
|
|
|
using AsbCloudApp.Data.DailyReport.Blocks.WellOperation;
|
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudApp.Services.DailyReport;
|
|
|
|
|
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Mapster;
|
2022-04-29 15:39:12 +05:00
|
|
|
|
|
2023-11-03 19:24:58 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.DailyReport;
|
2023-04-18 16:22:53 +05:00
|
|
|
|
|
2023-11-03 19:24:58 +05:00
|
|
|
|
public class DailyReportService : IDailyReportService
|
|
|
|
|
{
|
|
|
|
|
private readonly IWellService wellService;
|
2023-11-30 09:40:51 +05:00
|
|
|
|
private readonly ITrajectoryNnbRepository trajectoryFactNnbRepository;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
private readonly IDailyReportRepository dailyReportRepository;
|
|
|
|
|
private readonly IScheduleRepository scheduleRepository;
|
|
|
|
|
private readonly IWellOperationRepository wellOperationRepository;
|
2023-12-16 13:22:23 +05:00
|
|
|
|
private readonly ISubsystemService subsystemService;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingService;
|
|
|
|
|
private readonly IDetectedOperationService detectedOperationService;
|
|
|
|
|
|
|
|
|
|
public DailyReportService(IWellService wellService,
|
2023-11-30 09:40:51 +05:00
|
|
|
|
ITrajectoryNnbRepository trajectoryFactNnbRepository,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
IDailyReportRepository dailyReportRepository,
|
|
|
|
|
IScheduleRepository scheduleRepository,
|
|
|
|
|
IWellOperationRepository wellOperationRepository,
|
2023-12-16 13:22:23 +05:00
|
|
|
|
ISubsystemService subsystemService,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
IProcessMapReportWellDrillingService processMapReportWellDrillingService,
|
|
|
|
|
IDetectedOperationService detectedOperationService)
|
|
|
|
|
{
|
|
|
|
|
this.wellService = wellService;
|
2023-11-30 09:40:51 +05:00
|
|
|
|
this.trajectoryFactNnbRepository = trajectoryFactNnbRepository;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
this.dailyReportRepository = dailyReportRepository;
|
|
|
|
|
this.scheduleRepository = scheduleRepository;
|
|
|
|
|
this.wellOperationRepository = wellOperationRepository;
|
2023-12-16 13:22:23 +05:00
|
|
|
|
this.subsystemService = subsystemService;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
this.processMapReportWellDrillingService = processMapReportWellDrillingService;
|
|
|
|
|
this.detectedOperationService = detectedOperationService;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
public async Task<int> UpdateOrInsertAsync<TBlock>(int idWell, DateTime dateDailyReport, int idUser, TBlock editableBlock,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
CancellationToken cancellationToken)
|
2023-11-14 11:01:34 +05:00
|
|
|
|
where TBlock : ItemInfoDto
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
2023-11-14 16:43:39 +05:00
|
|
|
|
if (!await IsDateDailyReportInRangeAsync(idWell, dateDailyReport, cancellationToken))
|
|
|
|
|
throw new ArgumentInvalidException(nameof(dateDailyReport), "Невозможно обновить суточный отчёт");
|
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
var dailyReport = await dailyReportRepository.GetOrDefaultAsync(idWell, dateDailyReport, cancellationToken) ??
|
|
|
|
|
new DailyReportDto
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
Date = dateDailyReport
|
|
|
|
|
};
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
|
|
|
|
switch (editableBlock)
|
|
|
|
|
{
|
|
|
|
|
case SubsystemBlockDto subsystemBlock:
|
|
|
|
|
dailyReport.SubsystemBlock = subsystemBlock;
|
|
|
|
|
break;
|
|
|
|
|
case TimeBalanceBlockDto timeBalanceBlock:
|
|
|
|
|
dailyReport.TimeBalanceBlock = timeBalanceBlock;
|
|
|
|
|
break;
|
|
|
|
|
case SignBlockDto signBlock:
|
|
|
|
|
dailyReport.SignBlock = signBlock;
|
|
|
|
|
break;
|
2023-11-14 11:01:34 +05:00
|
|
|
|
default:
|
|
|
|
|
throw new InvalidOperationException("Unexpected type of editableBlock");
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
editableBlock.IdUser = idUser;
|
|
|
|
|
editableBlock.LastUpdateDate = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
dailyReport.DateLastUpdate = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
if (dailyReport.Id == 0)
|
|
|
|
|
return await dailyReportRepository.InsertAsync(dailyReport, cancellationToken);
|
|
|
|
|
|
2023-11-03 19:24:58 +05:00
|
|
|
|
return await dailyReportRepository.UpdateAsync(dailyReport, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
public async Task<DailyReportDto> GetAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
2023-12-05 14:48:56 +05:00
|
|
|
|
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken)
|
|
|
|
|
?? throw new ArgumentNullException(nameof(idWell), $"Скважина с Id: {idWell} не найдена");
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-12-05 14:48:56 +05:00
|
|
|
|
if (!await IsDateDailyReportInRangeAsync(idWell, dateDailyReport, cancellationToken))
|
2023-11-14 16:43:39 +05:00
|
|
|
|
throw new ArgumentInvalidException(nameof(dateDailyReport), "Невозможно получить суточный отчёт");
|
|
|
|
|
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
var dailyReport = await dailyReportRepository.GetOrDefaultAsync(idWell, dateDailyReport, cancellationToken) ?? new DailyReportDto
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
2023-11-14 11:01:34 +05:00
|
|
|
|
Date = dateDailyReport.Date,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
IdWell = well.Id
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-11 10:58:03 +05:00
|
|
|
|
var factOperationRequest = new WellOperationRequest
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
OperationType = WellOperation.IdOperationTypeFact,
|
|
|
|
|
GeDate = dateDailyReport,
|
|
|
|
|
LtDate = dateDailyReport.AddHours(24)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken))
|
2023-11-14 11:01:34 +05:00
|
|
|
|
.OrderBy(o => o.DateStart)
|
|
|
|
|
.ThenBy(o => o.DepthStart);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
dailyReport.WellCaption = well.Caption;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
dailyReport.WellType = well.WellType;
|
|
|
|
|
dailyReport.Cluster = well.Cluster;
|
|
|
|
|
dailyReport.Deposit = well.Deposit;
|
|
|
|
|
dailyReport.Customer = well.Companies.FirstOrDefault(c => c.IdCompanyType == 1)?.Caption;
|
|
|
|
|
dailyReport.Contractor = well.Companies.FirstOrDefault(c => c.IdCompanyType == 2)?.Caption;
|
2023-11-14 11:01:34 +05:00
|
|
|
|
dailyReport.DepthStart = factWellOperations.FirstOrDefault()?.DepthStart;
|
|
|
|
|
dailyReport.DepthEnd = factWellOperations.LastOrDefault()?.DepthEnd;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
|
|
|
|
await UpdateTimeBalanceBlockAsync(dailyReport, factWellOperations, cancellationToken);
|
|
|
|
|
await UpdateSubsystemBlockAsync(dailyReport, cancellationToken);
|
|
|
|
|
|
|
|
|
|
await AddTrajectoryBlockAsync(dailyReport, cancellationToken);
|
|
|
|
|
await AddScheduleBlockAsync(dailyReport, cancellationToken);
|
|
|
|
|
await AddProcessMapWellDrillingBlockAsync(dailyReport, cancellationToken);
|
|
|
|
|
|
|
|
|
|
AddFactWellOperationBlock(dailyReport, factWellOperations);
|
|
|
|
|
|
|
|
|
|
return dailyReport;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<PaginationContainer<DailyReportDto>> GetAsync(int idWell, FileReportRequest request,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var result = new PaginationContainer<DailyReportDto>
|
|
|
|
|
{
|
|
|
|
|
Skip = request.Skip ?? 0,
|
|
|
|
|
Take = request.Take ?? 10,
|
|
|
|
|
Items = Enumerable.Empty<DailyReportDto>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var datesRange = await GetDatesRangeAsync(idWell, cancellationToken);
|
|
|
|
|
|
|
|
|
|
if (datesRange is null)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
var dailyReports = new List<DailyReportDto>();
|
2023-12-11 10:58:03 +05:00
|
|
|
|
|
2023-11-03 19:24:58 +05:00
|
|
|
|
if (request.GeDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var startDate = new DateTime(request.GeDate.Value.Year, request.GeDate.Value.Month,
|
|
|
|
|
request.GeDate.Value.Day);
|
|
|
|
|
|
|
|
|
|
if (startDate.Date >= datesRange.From.Date)
|
|
|
|
|
datesRange.From = startDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.LeDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var finishDate = new DateTime(request.LeDate.Value.Year, request.LeDate.Value.Month,
|
|
|
|
|
request.LeDate.Value.Day);
|
|
|
|
|
|
|
|
|
|
if (finishDate.Date <= datesRange.To.Date)
|
|
|
|
|
datesRange.To = finishDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (datesRange.From.AddDays(result.Skip) <= datesRange.To)
|
|
|
|
|
result.Count = (int)(Math.Ceiling((datesRange.To - DateTime.UnixEpoch).TotalDays) -
|
2023-12-11 10:58:03 +05:00
|
|
|
|
Math.Floor((datesRange.From - DateTime.UnixEpoch).TotalDays)) + 1;
|
|
|
|
|
|
|
|
|
|
var existingDailyReports = await dailyReportRepository.GetAsync(idWell, request, cancellationToken);
|
|
|
|
|
|
|
|
|
|
var geDateFactWellOperation = datesRange.From.AddDays(result.Skip);
|
|
|
|
|
var ltDateFactWellOperation = geDateFactWellOperation.AddDays(result.Take);
|
|
|
|
|
|
|
|
|
|
var factWellOperationRequest = new WellOperationRequest
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
OperationType = WellOperation.IdOperationTypeFact,
|
|
|
|
|
GeDate = geDateFactWellOperation,
|
|
|
|
|
LtDate = ltDateFactWellOperation
|
|
|
|
|
};
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-12-11 10:58:03 +05:00
|
|
|
|
var factWellOperations = await wellOperationRepository.GetAsync(factWellOperationRequest, cancellationToken);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
|
|
|
|
if (request.SortFields?.Contains("DateStart desc") == true)
|
|
|
|
|
{
|
|
|
|
|
for (var day = result.Skip; day - result.Skip < result.Take && datesRange.To.AddDays(-day) >= datesRange.From; day++)
|
|
|
|
|
{
|
2023-11-14 11:01:34 +05:00
|
|
|
|
var dateDailyReport = datesRange.To.AddDays(-day).Date;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
AddDailyReport(dateDailyReport);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (var day = result.Skip; day - result.Skip < result.Take && datesRange.From.AddDays(day) <= datesRange.To; day++)
|
|
|
|
|
{
|
2023-11-14 11:01:34 +05:00
|
|
|
|
var dateDailyReport = datesRange.From.AddDays(day).Date;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
AddDailyReport(dateDailyReport);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.Items = dailyReports;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
void AddDailyReport(DateTime date)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
2023-11-27 11:20:10 +05:00
|
|
|
|
var dailyReport = existingDailyReports.FirstOrDefault(d => d.IdWell == idWell && d.Date == date)
|
|
|
|
|
?? new DailyReportDto
|
|
|
|
|
{
|
|
|
|
|
Date = date,
|
|
|
|
|
IdWell = idWell
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-11 10:58:03 +05:00
|
|
|
|
var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart.Date >= date && o.DateStart.Date <= date.AddDays(1));
|
|
|
|
|
|
|
|
|
|
AddFactWellOperationBlock(dailyReport, factWellOperationPerDay);
|
2023-11-27 11:20:10 +05:00
|
|
|
|
|
|
|
|
|
dailyReports.Add(dailyReport);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-12-11 10:58:03 +05:00
|
|
|
|
var factOperationDatesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact,
|
|
|
|
|
cancellationToken);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-12-11 10:58:03 +05:00
|
|
|
|
if (factOperationDatesRange is null)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
return null;
|
2023-12-11 10:58:03 +05:00
|
|
|
|
|
2023-11-03 19:24:58 +05:00
|
|
|
|
return new DatesRangeDto
|
|
|
|
|
{
|
2023-12-11 10:58:03 +05:00
|
|
|
|
From = factOperationDatesRange.From.AddDays(1) <= DateTime.UtcNow ? factOperationDatesRange.From : DateTime.UtcNow.Date.AddDays(-1),
|
|
|
|
|
To = factOperationDatesRange.To.AddDays(1) <= DateTime.UtcNow ? factOperationDatesRange.To : DateTime.UtcNow.Date.AddDays(-1)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task UpdateTimeBalanceBlockAsync(DailyReportDto dailyReport, IEnumerable<WellOperationDto> factWellOperations,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
const int idWellOperationSlipsTime = 5011;
|
2023-11-14 11:01:34 +05:00
|
|
|
|
|
2023-11-03 19:24:58 +05:00
|
|
|
|
if (dailyReport.TimeBalanceBlock is not null)
|
|
|
|
|
{
|
2023-11-07 15:57:15 +05:00
|
|
|
|
dailyReport.TimeBalanceBlock.SectionName = wellOperationRepository.GetSectionTypes()
|
|
|
|
|
.FirstOrDefault(s => s.Id == dailyReport.TimeBalanceBlock.IdSection)?.Caption;
|
2023-11-14 11:01:34 +05:00
|
|
|
|
|
2023-11-09 15:01:29 +05:00
|
|
|
|
dailyReport.TimeBalanceBlock.WellOperationSlipsTimeCount = (await detectedOperationService.GetAsync(
|
2023-11-03 19:24:58 +05:00
|
|
|
|
new DetectedOperationRequest
|
|
|
|
|
{
|
|
|
|
|
IdsCategories = new[] { idWellOperationSlipsTime },
|
|
|
|
|
IdWell = dailyReport.IdWell,
|
2023-11-14 11:01:34 +05:00
|
|
|
|
GtDate = dailyReport.Date,
|
|
|
|
|
LtDate = dailyReport.Date.AddHours(24)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}, cancellationToken))?.Stats.Sum(s => s.Count);
|
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
dailyReport.TimeBalanceBlock.WellDepth.Fact = factWellOperations
|
2023-11-03 19:24:58 +05:00
|
|
|
|
.Where(o => o.IdWellSectionType == dailyReport.TimeBalanceBlock.IdSection)
|
2023-11-14 11:01:34 +05:00
|
|
|
|
.Sum(o => o.DepthEnd - o.DepthStart);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task AddTrajectoryBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-11-30 09:40:51 +05:00
|
|
|
|
var trajectory = (await trajectoryFactNnbRepository.GetByRequestAsync(new TrajectoryRequest
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
|
|
|
|
IdWell = dailyReport.IdWell,
|
2023-11-14 11:01:34 +05:00
|
|
|
|
GeDate = dailyReport.Date,
|
|
|
|
|
LeDate = dailyReport.Date.AddHours(24)
|
|
|
|
|
}, cancellationToken)).MaxBy(t => t.WellboreDepth);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
|
|
|
|
dailyReport.TrajectoryBlock = new TrajectoryBlockDto
|
|
|
|
|
{
|
|
|
|
|
WellboreDepth = trajectory?.WellboreDepth,
|
|
|
|
|
VerticalDepth = trajectory?.VerticalDepth,
|
|
|
|
|
ZenithAngle = trajectory?.ZenithAngle,
|
|
|
|
|
AzimuthGeo = trajectory?.AzimuthGeo
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken) =>
|
2023-11-14 11:01:34 +05:00
|
|
|
|
dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, dailyReport.Date, cancellationToken))
|
2023-11-03 19:24:58 +05:00
|
|
|
|
.Select(s => new ScheduleRecordDto
|
|
|
|
|
{
|
|
|
|
|
ShiftStart = s.ShiftStart,
|
|
|
|
|
ShiftEnd = s.ShiftEnd,
|
|
|
|
|
Name = s.Driller?.Name,
|
|
|
|
|
Surname = s.Driller?.Surname,
|
|
|
|
|
Patronymic = s.Driller?.Patronymic
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
private async Task UpdateSubsystemBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
dailyReport.SubsystemBlock ??= new SubsystemBlockDto();
|
|
|
|
|
|
2023-11-09 15:01:29 +05:00
|
|
|
|
dailyReport.SubsystemBlock.Subsystems = await GetSubsystemsAsync();
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-11-09 15:01:29 +05:00
|
|
|
|
async Task<IEnumerable<SubsystemRecordDto>> GetSubsystemsAsync()
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
2023-12-16 13:22:23 +05:00
|
|
|
|
var subsystemsStatPerWell = await subsystemService.GetStatAsync(new SubsystemTimeRequest
|
2023-11-15 17:23:17 +05:00
|
|
|
|
{
|
|
|
|
|
IdWell = dailyReport.IdWell
|
|
|
|
|
}, cancellationToken);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-12-16 13:22:23 +05:00
|
|
|
|
var subsystemsStatPerDay = await subsystemService.GetStatAsync(new SubsystemTimeRequest
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
|
|
|
|
IdWell = dailyReport.IdWell,
|
2023-12-16 13:22:23 +05:00
|
|
|
|
GeDate = dailyReport.Date,
|
2023-11-14 11:01:34 +05:00
|
|
|
|
LtDate = dailyReport.Date.AddHours(24)
|
2023-11-15 17:23:17 +05:00
|
|
|
|
}, cancellationToken);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-12-16 13:22:23 +05:00
|
|
|
|
var subsystems = subsystemsStatPerWell
|
|
|
|
|
.Select(subsystemStatPerWell => new SubsystemRecordDto
|
2023-11-15 17:23:17 +05:00
|
|
|
|
{
|
2023-12-16 13:22:23 +05:00
|
|
|
|
Name = subsystemStatPerWell.SubsystemName,
|
|
|
|
|
UsagePerDay = subsystemsStatPerDay.FirstOrDefault(s => s.IdSubsystem == subsystemStatPerWell.IdSubsystem)?.Adapt<SubsystemParametersDto>(),
|
|
|
|
|
UsagePerWell = subsystemStatPerWell.Adapt<SubsystemParametersDto>()
|
2023-11-15 17:23:17 +05:00
|
|
|
|
}).ToList();
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-11-09 15:01:29 +05:00
|
|
|
|
if (dailyReport.SubsystemBlock?.Subsystems != null && dailyReport.SubsystemBlock.Subsystems.Any())
|
2023-11-14 11:01:34 +05:00
|
|
|
|
subsystems.AddRange(dailyReport.SubsystemBlock.Subsystems);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2023-11-15 17:23:17 +05:00
|
|
|
|
return subsystems.OrderBy(s => s.Name);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task AddProcessMapWellDrillingBlockAsync(DailyReportDto dailyReport, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
dailyReport.ProcessMapWellDrillingBlock = (await processMapReportWellDrillingService.GetAsync(dailyReport.IdWell,
|
2023-11-14 11:01:34 +05:00
|
|
|
|
cancellationToken)).Where(p => p.DateStart >= dailyReport.Date &&
|
|
|
|
|
p.DateStart <= dailyReport.Date.AddHours(24))
|
2023-11-07 15:57:15 +05:00
|
|
|
|
.GroupBy(p => p.DrillingMode)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
.Select(g => new ProcessMapWellDrillingRecordDto
|
|
|
|
|
{
|
2023-11-07 15:57:15 +05:00
|
|
|
|
DrillingMode = g.Key,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
WellBoreDepth = g.Sum(p => p.DeltaDepth),
|
|
|
|
|
Rop = new PlanFactDto<double?>
|
|
|
|
|
{
|
2023-11-09 15:01:29 +05:00
|
|
|
|
Plan = g.Sum(p => p.Rop.Plan),
|
|
|
|
|
Fact = g.Sum(p => p.Rop.Fact)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
},
|
|
|
|
|
MechDrillingHours = g.Sum(p => p.MechDrillingHours)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 11:01:34 +05:00
|
|
|
|
private static void AddFactWellOperationBlock(DailyReportDto dailyReport, IEnumerable<WellOperationDto> factWellOperations)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
|
|
|
|
const int idWellOperationCategoryDrilling = 4001;
|
|
|
|
|
|
|
|
|
|
dailyReport.FactWellOperationBlock = new WellOperationBlockDto
|
|
|
|
|
{
|
|
|
|
|
WellOperations = factWellOperations.GroupBy(o => o.IdParentCategory)
|
|
|
|
|
.Select(g => new WellOperationRecordDto
|
|
|
|
|
{
|
2023-11-07 15:57:15 +05:00
|
|
|
|
CategoryName = g.First().CategoryName,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
DurationHours = g.Sum(o => o.DurationHours)
|
|
|
|
|
}),
|
|
|
|
|
|
2023-11-09 15:01:29 +05:00
|
|
|
|
SectionDrillingHours = factWellOperations
|
2023-11-03 19:24:58 +05:00
|
|
|
|
.Where(o => o.IdParentCategory is idWellOperationCategoryDrilling)
|
|
|
|
|
.Sum(o => o.DurationHours)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 16:43:39 +05:00
|
|
|
|
private async Task<bool> IsDateDailyReportInRangeAsync(int idWell, DateTime dateDailyReport, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var datesRange = await GetDatesRangeAsync(idWell, cancellationToken);
|
|
|
|
|
|
|
|
|
|
return dateDailyReport >= datesRange?.From && dateDailyReport <= datesRange.To;
|
|
|
|
|
}
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|