Экспорт автоопределённых операций

This commit is contained in:
Степанов Дмитрий 2024-07-25 16:53:48 +03:00
parent acfe9ab000
commit ae79426973
2 changed files with 174 additions and 165 deletions

View File

@ -14,6 +14,7 @@ using AsbCloudApp.Exceptions;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Requests;
using AsbCloudInfrastructure.Services.DetectOperations.Detectors; using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
namespace AsbCloudInfrastructure.Services.DetectOperations; namespace AsbCloudInfrastructure.Services.DetectOperations;
@ -22,7 +23,7 @@ public class DetectedOperationExportService
{ {
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository; private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
private readonly IDetectedOperationService detectedOperationService; private readonly IDetectedOperationRepository detectedOperationRepository;
private const int headerRowsCount = 1; private const int headerRowsCount = 1;
private const string cellDepositName = "B1"; private const string cellDepositName = "B1";
@ -43,11 +44,11 @@ public class DetectedOperationExportService
public DetectedOperationExportService(IWellService wellService, public DetectedOperationExportService(IWellService wellService,
IWellOperationCategoryRepository wellOperationCategoryRepository, IWellOperationCategoryRepository wellOperationCategoryRepository,
IDetectedOperationService detectedOperationService) IDetectedOperationRepository detectedOperationRepository)
{ {
this.wellService = wellService; this.wellService = wellService;
this.wellOperationCategoryRepository = wellOperationCategoryRepository; this.wellOperationCategoryRepository = wellOperationCategoryRepository;
this.detectedOperationService = detectedOperationService; this.detectedOperationRepository = detectedOperationRepository;
} }
/// <summary> /// <summary>
@ -68,12 +69,19 @@ public class DetectedOperationExportService
if (!well.IdTelemetry.HasValue) if (!well.IdTelemetry.HasValue)
throw new ArgumentInvalidException(nameof(idWell), $"Well {idWell} has no telemetry"); throw new ArgumentInvalidException(nameof(idWell), $"Well {idWell} has no telemetry");
var operations = await detectedOperationService.DetectOperationsAsync(well.IdTelemetry.Value, DateTime.UnixEpoch, token); var request = new DetectedOperationByTelemetryRequest
{
IdTelemetry = well.IdTelemetry.Value
};
var operations = await detectedOperationRepository.Get(request, token);
return await GenerateExcelFileStreamAsync(well, host, operations, token); return await GenerateExcelFileStreamAsync(well, host, operations, token);
} }
private async Task<Stream> GenerateExcelFileStreamAsync(WellDto well, string host, IEnumerable<DetectedOperationDto> operationDetectorResults, private async Task<Stream> GenerateExcelFileStreamAsync(WellDto well,
string host,
IEnumerable<DetectedOperationDto> operationDetectorResults,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken); using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken);
@ -174,7 +182,8 @@ public class DetectedOperationExportService
} }
private static string GetIdReasonOfEnd(int idReasonOfEnd) private static string GetIdReasonOfEnd(int idReasonOfEnd)
=> idReasonOfEnd switch { => idReasonOfEnd switch
{
0 => "Не определена", 0 => "Не определена",
1 => "Не определено начало операции", 1 => "Не определено начало операции",
101 => "Разница глубин забоя и положением долота", 101 => "Разница глубин забоя и положением долота",
@ -182,7 +191,6 @@ public class DetectedOperationExportService
301 => "Высокое давление", 301 => "Высокое давление",
700 => "Изменение глубины долота и осевая нагрузка < веса на крюке", 700 => "Изменение глубины долота и осевая нагрузка < веса на крюке",
_ => idReasonOfEnd.ToString($"Причина № {idReasonOfEnd}"), _ => idReasonOfEnd.ToString($"Причина № {idReasonOfEnd}"),
}; };
private async Task<Stream> GetExcelTemplateStreamAsync(CancellationToken cancellationToken) private async Task<Stream> GetExcelTemplateStreamAsync(CancellationToken cancellationToken)
@ -211,7 +219,8 @@ public class DetectedOperationExportService
if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyAvgRotorSpeed, out object? oAvgRotorSpeed)) if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyAvgRotorSpeed, out object? oAvgRotorSpeed))
comment += $"Средняя скорость оборотов ротора: {oAvgRotorSpeed}\r\n"; comment += $"Средняя скорость оборотов ротора: {oAvgRotorSpeed}\r\n";
if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyDispersionOfNormalizedRotorSpeed, out object? oDispersionOfNormalizedRotorSpeed)) if (operation.ExtraData.TryGetValue(DetectorDrilling.ExtraDataKeyDispersionOfNormalizedRotorSpeed,
out object? oDispersionOfNormalizedRotorSpeed))
comment += $"Дисперсия нормированных оборотов ротора: {oDispersionOfNormalizedRotorSpeed}"; comment += $"Дисперсия нормированных оборотов ротора: {oDispersionOfNormalizedRotorSpeed}";
return comment; return comment;