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;
|
2024-03-22 09:29:01 +05:00
|
|
|
|
using AsbCloudApp.Data.WellOperation;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
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;
|
2024-02-21 15:08:51 +05:00
|
|
|
|
private readonly IProcessMapReportDrillingService processMapReportDrillingService;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
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,
|
2024-02-21 15:08:51 +05:00
|
|
|
|
IProcessMapReportDrillingService processMapReportDrillingService,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
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;
|
2024-02-21 15:08:51 +05:00
|
|
|
|
this.processMapReportDrillingService = processMapReportDrillingService;
|
2023-11-03 19:24:58 +05:00
|
|
|
|
this.detectedOperationService = detectedOperationService;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 16:55:17 +05:00
|
|
|
|
public async Task<int> UpdateOrInsertAsync<TBlock>(int idWell, DateOnly 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;
|
|
|
|
|
|
2024-03-19 17:21:05 +05:00
|
|
|
|
dailyReport.DateLastUpdate = DateTimeOffset.UtcNow;
|
2023-11-14 11:01:34 +05:00
|
|
|
|
|
|
|
|
|
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-12-20 16:55:17 +05:00
|
|
|
|
public async Task<DailyReportDto> GetAsync(int idWell, DateOnly 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-12-20 16:55:17 +05:00
|
|
|
|
Date = dateDailyReport,
|
2023-11-03 19:24:58 +05:00
|
|
|
|
IdWell = well.Id
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-22 17:59:03 +05:00
|
|
|
|
var offsetHours = wellService.GetTimezone(dailyReport.IdWell).Hours;
|
|
|
|
|
var geDate = new DateTimeOffset(dailyReport.Date, TimeOnly.MinValue, TimeSpan.FromHours(offsetHours));
|
2024-03-25 16:08:59 +05:00
|
|
|
|
var leDate = new DateTimeOffset(dailyReport.Date.AddDays(1), TimeOnly.MinValue, TimeSpan.FromHours(offsetHours));
|
2024-03-22 17:59:03 +05:00
|
|
|
|
|
2024-03-27 09:53:54 +05:00
|
|
|
|
var factOperationRequest = new WellOperationRequest(new []{ idWell })
|
|
|
|
|
{
|
2023-12-11 10:58:03 +05:00
|
|
|
|
OperationType = WellOperation.IdOperationTypeFact,
|
2023-12-20 16:55:17 +05:00
|
|
|
|
GeDate = geDate,
|
2024-03-22 09:29:01 +05:00
|
|
|
|
LeDate = leDate
|
2023-12-11 10:58:03 +05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
await UpdateTimeBalanceBlockAsync(dailyReport, factWellOperations, geDate, leDate, cancellationToken);
|
|
|
|
|
await UpdateSubsystemBlockAsync(dailyReport, geDate, leDate, cancellationToken);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
await AddTrajectoryBlockAsync(dailyReport, geDate, leDate, cancellationToken);
|
2024-03-25 09:36:57 +05:00
|
|
|
|
await AddScheduleBlockAsync(dailyReport, geDate, cancellationToken);
|
2024-03-25 16:08:59 +05:00
|
|
|
|
await AddProcessMapWellDrillingBlockAsync(dailyReport, geDate, leDate, cancellationToken);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
|
|
|
|
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>()
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-26 10:16:18 +05:00
|
|
|
|
var datesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, cancellationToken);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
|
|
|
|
if (datesRange is null)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
var dailyReports = new List<DailyReportDto>();
|
2024-03-19 17:21:05 +05:00
|
|
|
|
TimeSpan offset = wellService.GetTimezone(idWell).Offset;
|
|
|
|
|
|
|
|
|
|
if (request.GeDate.HasValue)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
2024-03-19 17:21:05 +05:00
|
|
|
|
var startDate = new DateTimeOffset(request.GeDate.Value, TimeOnly.MinValue, offset);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2024-03-19 17:21:05 +05:00
|
|
|
|
if (startDate >= datesRange.From)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
datesRange.From = startDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.LeDate.HasValue)
|
|
|
|
|
{
|
2024-03-19 17:21:05 +05:00
|
|
|
|
var finishDate = new DateTimeOffset(request.LeDate.Value, TimeOnly.MinValue, offset);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2024-03-19 17:21:05 +05:00
|
|
|
|
if (finishDate <= datesRange.To)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
datesRange.To = finishDate;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-15 12:09:07 +05:00
|
|
|
|
result.Count = (datesRange.To.Day - DateTimeOffset.UnixEpoch.Day) - (datesRange.From.Day - DateTimeOffset.UnixEpoch.Day);
|
2023-12-11 10:58:03 +05:00
|
|
|
|
|
|
|
|
|
var existingDailyReports = await dailyReportRepository.GetAsync(idWell, request, cancellationToken);
|
|
|
|
|
|
|
|
|
|
var geDateFactWellOperation = datesRange.From.AddDays(result.Skip);
|
2024-03-22 09:29:01 +05:00
|
|
|
|
var leDateFactWellOperation = geDateFactWellOperation.AddDays(result.Take);
|
2023-12-11 10:58:03 +05:00
|
|
|
|
|
2024-03-27 09:53:54 +05:00
|
|
|
|
var factWellOperationRequest = new WellOperationRequest(new[] { idWell })
|
2023-12-11 10:58:03 +05:00
|
|
|
|
{
|
|
|
|
|
OperationType = WellOperation.IdOperationTypeFact,
|
|
|
|
|
GeDate = geDateFactWellOperation,
|
2024-03-22 09:29:01 +05:00
|
|
|
|
LeDate = leDateFactWellOperation
|
2023-12-11 10:58:03 +05:00
|
|
|
|
};
|
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++)
|
|
|
|
|
{
|
2024-03-22 09:29:01 +05:00
|
|
|
|
var dateDailyReport = DateOnly.FromDateTime(datesRange.To.AddDays(-day).DateTime);
|
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++)
|
|
|
|
|
{
|
2024-03-22 09:29:01 +05:00
|
|
|
|
var dateDailyReport = DateOnly.FromDateTime(datesRange.From.AddDays(day).DateTime);
|
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-12-20 16:55:17 +05:00
|
|
|
|
void AddDailyReport(DateOnly 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
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
var geDate = new DateTimeOffset(date, TimeOnly.MinValue, offset);
|
|
|
|
|
var leDate = new DateTimeOffset(date.AddDays(1), TimeOnly.MinValue, offset);
|
2023-12-20 16:55:17 +05:00
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
var factWellOperationPerDay = factWellOperations.Where(o => o.DateStart >= geDate &&
|
|
|
|
|
o.DateStart <= leDate);
|
2023-12-11 10:58:03 +05:00
|
|
|
|
|
|
|
|
|
AddFactWellOperationBlock(dailyReport, factWellOperationPerDay);
|
2023-11-27 11:20:10 +05:00
|
|
|
|
|
|
|
|
|
dailyReports.Add(dailyReport);
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task UpdateTimeBalanceBlockAsync(DailyReportDto dailyReport, IEnumerable<WellOperationDto> factWellOperations,
|
2024-03-25 16:08:59 +05:00
|
|
|
|
DateTimeOffset geDateStart, DateTimeOffset leDateEnd, CancellationToken cancellationToken)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
dailyReport.TimeBalanceBlock.WellOperationSlipsTimeCount = (await detectedOperationService.GetAsync(
|
2024-02-08 11:38:25 +05:00
|
|
|
|
new DetectedOperationByWellRequest
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
|
|
|
|
IdsCategories = new[] { idWellOperationSlipsTime },
|
|
|
|
|
IdWell = dailyReport.IdWell,
|
2023-12-20 16:55:17 +05:00
|
|
|
|
GeDateStart = geDateStart,
|
|
|
|
|
LeDateEnd = leDateEnd
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
private async Task AddTrajectoryBlockAsync(DailyReportDto dailyReport,
|
|
|
|
|
DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken cancellationToken)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
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-12-20 16:55:17 +05:00
|
|
|
|
GeDate = geDate,
|
|
|
|
|
LeDate = leDate
|
2023-11-14 11:01:34 +05:00
|
|
|
|
}, 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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-25 09:36:57 +05:00
|
|
|
|
private async Task AddScheduleBlockAsync(DailyReportDto dailyReport, DateTimeOffset workDate, CancellationToken cancellationToken)
|
2023-12-20 16:55:17 +05:00
|
|
|
|
{
|
2024-03-25 09:36:57 +05:00
|
|
|
|
dailyReport.ScheduleBlock = (await scheduleRepository.GetAsync(dailyReport.IdWell, workDate, 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
|
|
|
|
|
});
|
2023-12-20 16:55:17 +05:00
|
|
|
|
}
|
2023-11-03 19:24:58 +05:00
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
private async Task UpdateSubsystemBlockAsync(DailyReportDto dailyReport,
|
|
|
|
|
DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken cancellationToken)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
|
|
|
|
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 14:23:59 +05:00
|
|
|
|
var subsystemsStatPerWell = await subsystemService.GetStatAsync(new SubsystemRequest
|
2023-11-15 17:23:17 +05:00
|
|
|
|
{
|
|
|
|
|
IdWell = dailyReport.IdWell
|
|
|
|
|
}, cancellationToken);
|
2023-12-20 16:55:17 +05:00
|
|
|
|
|
2023-12-16 14:23:59 +05:00
|
|
|
|
var subsystemsStatPerDay = await subsystemService.GetStatAsync(new SubsystemRequest
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
|
|
|
|
IdWell = dailyReport.IdWell,
|
2023-12-20 16:55:17 +05:00
|
|
|
|
GeDate = geDate,
|
|
|
|
|
LeDate = leDate
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-25 16:08:59 +05:00
|
|
|
|
private async Task AddProcessMapWellDrillingBlockAsync(DailyReportDto dailyReport,
|
|
|
|
|
DateTimeOffset geDate, DateTimeOffset leDate, CancellationToken cancellationToken)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
{
|
2024-02-20 15:54:18 +05:00
|
|
|
|
var request = new DataSaubStatRequest();
|
2024-02-21 15:08:51 +05:00
|
|
|
|
dailyReport.ProcessMapWellDrillingBlock = (await processMapReportDrillingService.GetAsync(dailyReport.IdWell, request,
|
2023-12-20 16:55:17 +05:00
|
|
|
|
cancellationToken)).Where(p => p.DateStart >= geDate && p.DateStart <= leDate)
|
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
|
|
|
|
},
|
2024-02-20 15:54:18 +05:00
|
|
|
|
MechDrillingHours = g.Sum(p => p.DrilledTime)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2023-12-20 16:55:17 +05:00
|
|
|
|
WellOperations = factWellOperations.GroupBy(o => o.IdCategory)
|
2023-11-03 19:24:58 +05:00
|
|
|
|
.Select(g => new WellOperationRecordDto
|
|
|
|
|
{
|
2024-03-22 09:29:01 +05:00
|
|
|
|
CategoryName = g.First().OperationCategoryName,
|
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-12-20 16:55:17 +05:00
|
|
|
|
private async Task<bool> IsDateDailyReportInRangeAsync(int idWell, DateOnly dateDailyReport, CancellationToken cancellationToken)
|
2023-11-14 16:43:39 +05:00
|
|
|
|
{
|
2024-03-26 10:16:18 +05:00
|
|
|
|
var datesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact, cancellationToken);
|
2023-11-14 16:43:39 +05:00
|
|
|
|
|
2023-12-20 16:55:17 +05:00
|
|
|
|
if (datesRange is null)
|
|
|
|
|
return false;
|
2024-03-22 09:29:01 +05:00
|
|
|
|
var from = DateOnly.FromDateTime(datesRange.From.DateTime);
|
|
|
|
|
var to = DateOnly.FromDateTime(datesRange.To.DateTime);
|
2023-12-20 16:55:17 +05:00
|
|
|
|
|
2023-12-21 11:10:06 +05:00
|
|
|
|
return dateDailyReport >= from && dateDailyReport <= to;
|
2023-11-14 16:43:39 +05:00
|
|
|
|
}
|
2023-11-03 19:24:58 +05:00
|
|
|
|
}
|