Рефакторинг WellInfoService и WellCompositeController

This commit is contained in:
Степанов Дмитрий 2023-10-12 15:47:26 +05:00
parent 2f2599f9ab
commit 6556a03bb5
2 changed files with 14 additions and 14 deletions

View File

@ -34,7 +34,7 @@ public class WellInfoService
{ {
var wellService = services.GetRequiredService<IWellService>(); var wellService = services.GetRequiredService<IWellService>();
var operationsStatService = services.GetRequiredService<IOperationsStatService>(); var operationsStatService = services.GetRequiredService<IOperationsStatService>();
var wellDrillingProcessMapRepository = services.GetRequiredService<IWellDrillingProcessMapRepository>(); var processMapPlanWellDrillingRepository = services.GetRequiredService<IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto>>();
var subsystemOperationTimeService = services.GetRequiredService<ISubsystemOperationTimeService>(); var subsystemOperationTimeService = services.GetRequiredService<ISubsystemOperationTimeService>();
var telemetryDataSaubCache = services.GetRequiredService<TelemetryDataCache<TelemetryDataSaubDto>>(); var telemetryDataSaubCache = services.GetRequiredService<TelemetryDataCache<TelemetryDataSaubDto>>();
var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>(); var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();
@ -44,10 +44,10 @@ public class WellInfoService
var wellsIds = activeWells.Select(w => w.Id); var wellsIds = activeWells.Select(w => w.Id);
var wellDrillingProcessMapRequests = wellsIds.Select(id => new WellDrillingProcessMapRequest { IdWell = id }); var processMapPlanWellDrillingRequests = wellsIds.Select(id => new ProcessMapPlanRequest { IdWell = id });
var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetAsync(wellDrillingProcessMapRequests, token); var processMapPlanWellDrillings = await processMapPlanWellDrillingRepository.GetAsync(processMapPlanWellDrillingRequests, token);
var wellDepthByProcessMap = wellDrillingProcessMaps var wellDepthByProcessMap = processMapPlanWellDrillings
.GroupBy(p => p.IdWell) .GroupBy(p => p.IdWell)
.Select(g => new .Select(g => new
{ {
@ -85,20 +85,20 @@ public class WellInfoService
var wellLastFactSection = wellOperationsStat?.Sections.LastOrDefault(s => s.Fact is not null); var wellLastFactSection = wellOperationsStat?.Sections.LastOrDefault(s => s.Fact is not null);
currentDepth ??= wellLastFactSection?.Fact?.WellDepthEnd; currentDepth ??= wellLastFactSection?.Fact?.WellDepthEnd;
var wellProcessMaps = wellDrillingProcessMaps var wellProcessMaps = processMapPlanWellDrillings
.Where(p => p.IdWell == well.Id) .Where(p => p.IdWell == well.Id)
.OrderBy(p => p.DepthEnd); .OrderBy(p => p.DepthEnd);
int? idSection = wellLastFactSection?.Id; int? idSection = wellLastFactSection?.Id;
WellDrillingProcessMapDto? wellDrillingProcessMap = null; ProcessMapPlanWellDrillingDto? processMapPlanWellDrilling = null;
if (idSection.HasValue) if (idSection.HasValue)
{ {
wellDrillingProcessMap = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection); processMapPlanWellDrilling = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection);
} }
else if (currentDepth.HasValue) else if (currentDepth.HasValue)
{ {
wellDrillingProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value); processMapPlanWellDrilling = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value);
} }
double? planTotalDepth = null; double? planTotalDepth = null;
@ -114,25 +114,25 @@ public class WellInfoService
wellMapInfo.AxialLoad = new() wellMapInfo.AxialLoad = new()
{ {
Plan = wellDrillingProcessMap?.AxialLoad.Plan, Plan = processMapPlanWellDrilling?.AxialLoad.Plan,
Fact = lastSaubTelemetry?.AxialLoad Fact = lastSaubTelemetry?.AxialLoad
}; };
wellMapInfo.TopDriveSpeed = new() wellMapInfo.TopDriveSpeed = new()
{ {
Plan = wellDrillingProcessMap?.TopDriveSpeed.Plan, Plan = processMapPlanWellDrilling?.TopDriveSpeed.Plan,
Fact = lastSaubTelemetry?.RotorSpeed Fact = lastSaubTelemetry?.RotorSpeed
}; };
wellMapInfo.TopDriveTorque = new() wellMapInfo.TopDriveTorque = new()
{ {
Plan = wellDrillingProcessMap?.TopDriveTorque.Plan, Plan = processMapPlanWellDrilling?.TopDriveTorque.Plan,
Fact = lastSaubTelemetry?.RotorTorque Fact = lastSaubTelemetry?.RotorTorque
}; };
wellMapInfo.Pressure = new() wellMapInfo.Pressure = new()
{ {
Plan = wellDrillingProcessMap?.Pressure.Plan, Plan = processMapPlanWellDrilling?.Pressure.Plan,
Fact = lastSaubTelemetry?.Pressure Fact = lastSaubTelemetry?.Pressure
}; };
@ -146,7 +146,7 @@ public class WellInfoService
wellMapInfo.ROP = new() wellMapInfo.ROP = new()
{ {
Plan = wellDrillingProcessMap?.RopPlan, Plan = processMapPlanWellDrilling?.RopPlan,
Fact = wellOperationsStat?.Total.Fact?.Rop, Fact = wellOperationsStat?.Total.Fact?.Rop,
}; };

View File

@ -73,7 +73,7 @@ namespace AsbCloudWebApi.Controllers
/// <returns></returns> /// <returns></returns>
[HttpGet("compositeProcessMap")] [HttpGet("compositeProcessMap")]
[Permission] [Permission]
[ProducesResponseType(typeof(IEnumerable<WellDrillingProcessMapDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<ProcessMapPlanWellDrillingDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetCompositeProcessMap(int idWell, CancellationToken token) public async Task<IActionResult> GetCompositeProcessMap(int idWell, CancellationToken token)
{ {
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))