Рефакторинг

This commit is contained in:
Степанов Дмитрий 2023-12-18 13:53:51 +05:00
parent 0570c4f4e4
commit 8b15297a74
5 changed files with 40 additions and 33 deletions

View File

@ -14,9 +14,9 @@ public class SubsystemActiveWellStatDto
/// </summary>
public SubsystemStatDto? SubsystemAPD { get; set; }
/// <summary>
/// Наработки подсистемы СПИН
/// Наработки подсистемы с осцилляцией
/// </summary>
public SubsystemStatDto? SubsystemSpinMaster { get; set; }
public SubsystemStatDto? SubsystemOscillation { get; set; }
/// <summary>
/// Наработки подсистемы ТОРК
/// </summary>

View File

@ -20,22 +20,22 @@ namespace AsbCloudApp.Requests
/// <summary>
/// Больше или равно дате
/// </summary>
public DateTime? GeDate { get; set; }
public DateTimeOffset? GeDate { get; set; }
/// <summary>
/// Меньше или равно дате
/// </summary>
public DateTime? LtDate { get; set; }
public DateTimeOffset? LeDate { get; set; }
/// <summary>
/// Больше или равно глубины забоя
/// </summary>
public double? GtDepth { get; set; }
public double? GeDepth { get; set; }
/// <summary>
/// Меньше или равно глубины забоя
/// </summary>
public double? LtDepth { get; set; }
public double? LeDepth { get; set; }
/// <inheritdoc/>
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
@ -45,20 +45,20 @@ namespace AsbCloudApp.Requests
$"Должно быть больше {validationMinDate:O})",
new[] { nameof(GeDate) });
if (LtDate.HasValue && GeDate.HasValue)
if (LeDate.HasValue && GeDate.HasValue)
{
if (LtDate < GeDate)
if (LeDate < GeDate)
yield return new ValidationResult(
$"{nameof(LtDate)} должно быть больше {nameof(GeDate)}. ({LtDate:O} < {GeDate:O})",
new[] { nameof(LtDate), nameof(GeDate) });
$"{nameof(LeDate)} должно быть больше {nameof(GeDate)}. ({LeDate:O} < {GeDate:O})",
new[] { nameof(LeDate), nameof(GeDate) });
}
if (LtDepth.HasValue && GtDepth.HasValue)
if (LeDepth.HasValue && GeDepth.HasValue)
{
if (LtDepth < GtDepth)
if (LeDepth < GeDepth)
yield return new ValidationResult(
$"{nameof(LtDepth)} должно быть больше {nameof(GtDepth)}. ({LtDepth} < {GtDepth})",
new[] { nameof(LtDepth), nameof(GtDepth) });
$"{nameof(LeDepth)} должно быть больше {nameof(GeDepth)}. ({LeDepth} < {GeDepth})",
new[] { nameof(LeDepth), nameof(GeDepth) });
}
yield break;

View File

@ -319,7 +319,7 @@ public class DailyReportService : IDailyReportService
{
IdWell = dailyReport.IdWell,
GeDate = dailyReport.Date,
LtDate = dailyReport.Date.AddHours(24)
LeDate = dailyReport.Date.AddHours(24)
}, cancellationToken);
var subsystems = subsystemsStatPerWell

View File

@ -10,17 +10,16 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudInfrastructure.Services.DetectOperations;
namespace AsbCloudInfrastructure.Services.Subsystems;
internal class SubsystemService : ISubsystemService
{
private const int IdEnabledSubsystemSpinMaster = 128;
private const int IdSubsystemAPD = 1;
private const int IdSubsystemAPDRotor = 11;
private const int IdSubsystemAPDSlide = 12;
private const int IdSubsystemSpinMaster = 65536;
private const int IdSubsystemOscillation = 65536;
private readonly ICrudRepository<SubsystemDto> subsystemRepository;
@ -50,10 +49,10 @@ internal class SubsystemService : ISubsystemService
IdsOperationCategories = WellOperationCategory.MechanicalDrillingSubIds,
GeDateStart = request.GeDate,
LeDateStart = request.LtDate,
LeDateStart = request.LeDate,
GeDepthStart = request.GtDepth,
LeDepthStart = request.LtDepth,
GeDepthStart = request.GeDepth,
LeDepthStart = request.LeDepth,
};
var operations = await detectedOperationService.GetOperationSummaryAsync(detectedOperationSummaryRequest,
@ -66,7 +65,9 @@ internal class SubsystemService : ISubsystemService
return stat;
}
public async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany, DateTime? gtDate, DateTime? ltDate,
public async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatByActiveWells(int idCompany,
DateTime? gtDate,
DateTime? ltDate,
CancellationToken token)
{
var activeWells = await wellService.GetAsync(new() { IdCompany = idCompany, IdState = 1 }, token);
@ -98,7 +99,10 @@ internal class SubsystemService : ISubsystemService
nameof(groupOperations.Key)),
};
var operationsWithEnableSubsystems = groupOperations.Where(o => o.EnabledSubsystems >= 1);
var operationsWithEnableSubsystems = groupOperations.Where(o =>
(EnabledSubsystemsFlags.AutoRotor |
EnabledSubsystemsFlags.AutoSlide |
EnabledSubsystemsFlags.AutoOscillation).HasEnabledSubsystems(o.EnabledSubsystems));
var subsystemStat = new SubsystemStatDto
{
@ -120,17 +124,18 @@ internal class SubsystemService : ISubsystemService
if (apdSlidePart is not null)
{
var operationsWithSpinMaster = operations.Where(s => s.EnabledSubsystems == IdEnabledSubsystemSpinMaster);
var operationsWithOscillation =
operations.Where(o => EnabledSubsystemsFlags.AutoOscillation.HasEnabledSubsystems(o.EnabledSubsystems));
var spinMaster = new SubsystemStatDto
{
IdSubsystem = IdSubsystemSpinMaster,
SubsystemName = subsystems.FirstOrDefault(s => s.Id == IdSubsystemSpinMaster)?.Name ?? "unknown",
UsedTimeHours = operationsWithSpinMaster.Sum(o => o.SumDurationHours),
IdSubsystem = IdSubsystemOscillation,
SubsystemName = subsystems.FirstOrDefault(s => s.Id == IdSubsystemOscillation)?.Name ?? "unknown",
UsedTimeHours = operationsWithOscillation.Sum(o => o.SumDurationHours),
SumOperationDepthInterval = apdSlidePart.SumOperationDepthInterval,
SumOperationDurationHours = apdSlidePart.SumOperationDurationHours,
SumDepthInterval = operationsWithSpinMaster.Sum(o => o.SumDepthIntervals),
OperationCount = operationsWithSpinMaster.Sum(s => s.Count)
SumDepthInterval = operationsWithOscillation.Sum(o => o.SumDepthIntervals),
OperationCount = operationsWithOscillation.Sum(s => s.Count)
};
spinMaster.KUsage = spinMaster.SumDepthInterval / spinMaster.SumOperationDepthInterval;
@ -161,7 +166,9 @@ internal class SubsystemService : ISubsystemService
return stat;
}
private async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatAsync(IEnumerable<WellDto> wells, DateTime? gtDate, DateTime? ltDate,
private async Task<IEnumerable<SubsystemActiveWellStatDto>> GetStatAsync(IEnumerable<WellDto> wells,
DateTime? gtDate,
DateTime? ltDate,
CancellationToken token)
{
if (!wells.Any())
@ -210,7 +217,7 @@ internal class SubsystemService : ISubsystemService
continue;
wellStat.SubsystemAPD = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemAPD);
wellStat.SubsystemSpinMaster = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemSpinMaster);
wellStat.SubsystemOscillation = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemOscillation);
}
return wellsStat;

View File

@ -156,7 +156,7 @@ public class WellInfoService
var wellSubsystemStat = subsystemStat.FirstOrDefault(s => s.Well.Id == well.Id);
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAPD?.KUsage ?? 0d;
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemOscillation?.KUsage ?? 0d;
wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d;
wellMapInfo.TvdLagDays = wellOperationsStat?.TvdLagDays;
wellMapInfo.TvdDrillingDays = wellOperationsStat?.TvdDrillingDays;