From fb307ccceb431fa1e0903d6a9371d63476a34583 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Tue, 17 Oct 2023 10:20:27 +0500 Subject: [PATCH] Process map some nit refactoring --- .../ProcessMaps/ProcessMapPlanWellReamDto.cs | 5 - .../AsbCloudInfrastructure.csproj | 4 +- AsbCloudInfrastructure/DependencyInjection.cs | 6 +- .../Repository/CacheBase.cs | 10 +- .../ProcessMaps/Report/Data/ParamStat.cs | 110 +++++++++++++++ .../Report/Data/TelemetryStat.cs | 7 +- .../ProcessMapReportTemplate.xlsx} | Bin ...ocessMapReportWellDrillingExportService.cs | 6 +- .../ProcessMapReportWellDrillingService.cs | 8 +- ...rocessMapPlanImportWellDrillingService.cs} | 12 +- ...essMapPlanImportWellDrillingTemplate.xlsx} | Bin .../WellDrilling/Report/Data/ParamStat.cs | 110 --------------- .../ProcessMaps/ProcessMapBaseController.cs | 129 +++++++++--------- 13 files changed, 203 insertions(+), 204 deletions(-) create mode 100644 AsbCloudInfrastructure/Services/ProcessMaps/Report/Data/ParamStat.cs rename AsbCloudInfrastructure/Services/ProcessMaps/{WellDrilling => }/Report/Data/TelemetryStat.cs (89%) rename AsbCloudInfrastructure/Services/ProcessMaps/{Files/DrillingProcessMapReportTemplate.xlsx => Report/ProcessMapReportTemplate.xlsx} (100%) rename AsbCloudInfrastructure/Services/ProcessMaps/{WellDrilling => }/Report/ProcessMapReportWellDrillingExportService.cs (97%) rename AsbCloudInfrastructure/Services/ProcessMaps/{WellDrilling => }/Report/ProcessMapReportWellDrillingService.cs (96%) rename AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/{ProcessMapPlanWellDrillingImportService.cs => ProcessMapPlanImportWellDrillingService.cs} (97%) rename AsbCloudInfrastructure/Services/ProcessMaps/{Files/DrillingProcessMapTemplate.xlsx => WellDrilling/ProcessMapPlanImportWellDrillingTemplate.xlsx} (100%) delete mode 100644 AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/ParamStat.cs diff --git a/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs b/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs index 657bb493..264d3b8b 100644 --- a/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs +++ b/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs @@ -62,11 +62,6 @@ public class ProcessMapPlanWellReamDto : ProcessMapPlanBaseDto, IValidatableObje [Range(0, 99999.9, ErrorMessage = "Крутящий момент должен быть в пределах от 0 до 99999.9")] public double Torque { get; set; } - /// - /// Комментарий - /// - public string? Comment { get; set; } - /// public IEnumerable Validate(ValidationContext validationContext) { diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index 955fcf7d..bc825b4b 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -37,8 +37,8 @@ - - + + diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index be020f89..ef248c13 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -24,8 +24,8 @@ using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; using AsbCloudInfrastructure.Services.DailyReport; using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DrillingProgram; -using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap; -using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report; +using AsbCloudInfrastructure.Services.ProcessMaps.Report; +using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling; using AsbCloudInfrastructure.Services.SAUB; using AsbCloudInfrastructure.Services.Subsystems; using AsbCloudInfrastructure.Services.Trajectory; @@ -197,7 +197,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AsbCloudInfrastructure/Repository/CacheBase.cs b/AsbCloudInfrastructure/Repository/CacheBase.cs index 78ad240e..28d07f07 100644 --- a/AsbCloudInfrastructure/Repository/CacheBase.cs +++ b/AsbCloudInfrastructure/Repository/CacheBase.cs @@ -15,7 +15,7 @@ namespace AsbCloudInfrastructure.Repository { protected readonly IMemoryCache memoryCache; protected string CacheTag = typeof(TEntity).Name; - protected TimeSpan CacheOlescence = TimeSpan.FromMinutes(5); + protected TimeSpan CacheObsolescence = TimeSpan.FromMinutes(5); public CacheBase(IAsbCloudDbContext context, IMemoryCache memoryCache) : base(context) @@ -36,8 +36,8 @@ namespace AsbCloudInfrastructure.Repository { var cache = memoryCache.GetOrCreate(CacheTag, cacheEntry => { - cacheEntry.AbsoluteExpirationRelativeToNow = CacheOlescence; - cacheEntry.SlidingExpiration = CacheOlescence; + cacheEntry.AbsoluteExpirationRelativeToNow = CacheObsolescence; + cacheEntry.SlidingExpiration = CacheObsolescence; var entities = this.GetQuery().ToArray(); cacheEntry.Value = entities; @@ -50,8 +50,8 @@ namespace AsbCloudInfrastructure.Repository { var cache = memoryCache.GetOrCreateAsync(CacheTag, async (cacheEntry) => { - cacheEntry.AbsoluteExpirationRelativeToNow = CacheOlescence; - cacheEntry.SlidingExpiration = CacheOlescence; + cacheEntry.AbsoluteExpirationRelativeToNow = CacheObsolescence; + cacheEntry.SlidingExpiration = CacheObsolescence; var entities = await this.GetQuery().ToArrayAsync(token); cacheEntry.Value = entities; diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/Data/ParamStat.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/Data/ParamStat.cs new file mode 100644 index 00000000..90559ca1 --- /dev/null +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/Data/ParamStat.cs @@ -0,0 +1,110 @@ +using System; +using AsbCloudApp.Data.ProcessMaps.Report; +using AsbCloudApp.Data.SAUB; + +namespace AsbCloudInfrastructure.Services.ProcessMaps.Report.Data; + +internal class ParamStat +{ + private double spWSum; + private double pvWSum; + private double limitMaxWSum; + + private double deltaDepthSum; + + private readonly Func getterSp; + private readonly Func getterPv; + private readonly Func? getterLimitMax; + + private readonly int idFeedRegulator; + private readonly int idMode; + private TelemetryDataSaubStatDto? previous; + + public double SpUsageDepth { get; private set; } + private static double spUsageTotal; + + public ParamStat(Func getterSp, + Func getterPv, + Func? getterLimitMax, + int idFeedRegulator, + int idMode) + { + this.getterSp = getterSp; + this.getterPv = getterPv; + this.getterLimitMax = getterLimitMax; + this.idFeedRegulator = idFeedRegulator; + this.idMode = idMode; + spUsageTotal = 0d; + } + + public void UpdateStat(TelemetryDataSaubStatDto current) + { + if (previous is not null) + { + var deltaDepth = current.WellDepthMin - previous.WellDepthMin; + if (deltaDepth > 0) + { + var deltaDepthHalf = deltaDepth / 2; + + double CalculateWeight(Func getter) => + (getter(previous!) + getter(current)) * deltaDepthHalf; + + spWSum += CalculateWeight(getterSp); + pvWSum += CalculateWeight(getterPv); + if (getterLimitMax is not null) + limitMaxWSum += CalculateWeight(getterLimitMax!); + + if (current.IdFeedRegulator is not null) + if (current.IdFeedRegulator == idFeedRegulator) + { + SpUsageDepth += deltaDepth; + spUsageTotal += deltaDepth; + } + else + { + var pvErr = (getterSp(current) - getterPv(current)) / getterSp(current); + if (pvErr < 0.03d) //3% + { + SpUsageDepth += deltaDepth; + spUsageTotal += deltaDepth; + } + } + + deltaDepthSum += deltaDepth; + } + } + + previous = current; + } + + public ProcessMapReportWellDrillingParamsDto MakeParams(double? spPlan) + { + var result = new ProcessMapReportWellDrillingParamsDto + { + SetpointPlan = spPlan, + Fact = DivideValByDepth(pvWSum), + }; + + if (idMode == 0) + { + result.SetpointFact = null; + result.Limit = null; + result.SetpointUsage = null; + } + else + { + result.SetpointFact = DivideValByDepth(spWSum); + result.Limit = getterLimitMax is not null ? DivideValByDepth(limitMaxWSum) : null; + result.SetpointUsage = deltaDepthSum > 0d ? 100d * SpUsageDepth / spUsageTotal : null; + } + + return result; + } + + private double? DivideValByDepth(double? val) + { + if (val is null || val == 0d || deltaDepthSum == 0d) + return null; + return val / deltaDepthSum; + } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/TelemetryStat.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/Data/TelemetryStat.cs similarity index 89% rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/TelemetryStat.cs rename to AsbCloudInfrastructure/Services/ProcessMaps/Report/Data/TelemetryStat.cs index 7b231d7f..89fe6291 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/TelemetryStat.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/Data/TelemetryStat.cs @@ -1,8 +1,7 @@ using System; using AsbCloudApp.Data.SAUB; -using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling.Report.Data; -namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.Data; +namespace AsbCloudInfrastructure.Services.ProcessMaps.Report.Data; internal class TelemetryStat { @@ -24,7 +23,7 @@ internal class TelemetryStat public float DeltaDepth { get; } public int IdMode { get; } public string ModeName { get; } - public double MechDrillingHours { get; } + public double DrillingHours { get; } public TelemetryStat(Span telemetry) { @@ -35,7 +34,7 @@ internal class TelemetryStat ModeName = GetModeName(IdMode); DateStart = telemetryFirst.DateMin; DeltaDepth = telemetryLast.WellDepthMax - telemetryFirst.WellDepthMin; - MechDrillingHours = (telemetryLast.DateMax - telemetryFirst.DateMin).TotalHours; + DrillingHours = (telemetryLast.DateMax - telemetryFirst.DateMin).TotalHours; BlockSpeed = new(t => t.BlockSpeedSp, t => t.BlockSpeed, null, 1, IdMode); Pressure = new(t => t.PressureSpDelta, t => t.PressureDelta, t => t.PressureDeltaLimitMax, 2, IdMode); diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Files/DrillingProcessMapReportTemplate.xlsx b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportTemplate.xlsx similarity index 100% rename from AsbCloudInfrastructure/Services/ProcessMaps/Files/DrillingProcessMapReportTemplate.xlsx rename to AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportTemplate.xlsx diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingExportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportWellDrillingExportService.cs similarity index 97% rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingExportService.cs rename to AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportWellDrillingExportService.cs index 17c8c423..246d03e6 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingExportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportWellDrillingExportService.cs @@ -9,7 +9,7 @@ using AsbCloudApp.Services; using AsbCloudApp.Services.ProcessMaps.WellDrilling; using ClosedXML.Excel; -namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report; +namespace AsbCloudInfrastructure.Services.ProcessMaps.Report; public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDrillingExportService { @@ -208,8 +208,8 @@ public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDr { var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream( - "AsbCloudInfrastructure.Services.ProcessMaps.Files.DrillingProcessMapReportTemplate.xlsx"); - + "AsbCloudInfrastructure.Services.ProcessMaps.Report.ProcessMapReportTemplate.xlsx"); + return stream!; } diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportWellDrillingService.cs similarity index 96% rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingService.cs rename to AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportWellDrillingService.cs index 2a11d729..a1fe7960 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportWellDrillingService.cs @@ -10,9 +10,9 @@ using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudApp.Services.ProcessMaps.WellDrilling; -using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.Data; +using AsbCloudInfrastructure.Services.ProcessMaps.Report.Data; -namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report; +namespace AsbCloudInfrastructure.Services.ProcessMaps.Report; public class ProcessMapReportWellDrillingService : IProcessMapReportWellDrillingService { @@ -22,7 +22,7 @@ public class ProcessMapReportWellDrillingService : IProcessMapReportWellDrilling private readonly IWellOperationRepository wellOperationRepository; public ProcessMapReportWellDrillingService(IWellService wellService, - IProcessMapPlanRepository processMapPlanWellDrillingRepository, + IProcessMapPlanRepository processMapPlanWellDrillingRepository, ITelemetryDataSaubService telemetryDataSaubService, IWellOperationRepository wellOperationRepository) { @@ -178,7 +178,7 @@ public class ProcessMapReportWellDrillingService : IProcessMapReportWellDrilling DepthEnd = subInterval.DepthEnd, DateStart = telemetryStat.DateStart, - MechDrillingHours = telemetryStat.MechDrillingHours, + MechDrillingHours = telemetryStat.DrillingHours, DrillingMode = telemetryStat.ModeName, DeltaDepth = telemetryStat.DeltaDepth, diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanWellDrillingImportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanImportWellDrillingService.cs similarity index 97% rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanWellDrillingImportService.cs rename to AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanImportWellDrillingService.cs index 2e556f2e..c0bcf61d 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanWellDrillingImportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanImportWellDrillingService.cs @@ -13,12 +13,12 @@ using AsbCloudApp.Services; using AsbCloudApp.Services.ProcessMaps; using ClosedXML.Excel; -namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap; +namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling; /* * password for ProcessMapImportTemplate.xlsx is ASB2020! */ -public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportService +public class ProcessMapPlanImportWellDrillingService : IProcessMapPlanImportService { private readonly IProcessMapPlanRepository processMapPlanWellDrillingRepository; private readonly ICrudRepository wellSectionTypeRepository; @@ -49,7 +49,7 @@ public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportServ private WellSectionTypeDto[] sections = null!; - public ProcessMapPlanWellDrillingImportService(IProcessMapPlanRepository processMapPlanWellDrillingRepository, + public ProcessMapPlanImportWellDrillingService(IProcessMapPlanRepository processMapPlanWellDrillingRepository, ICrudRepository wellSectionTypeRepository, IWellService wellService) { @@ -100,7 +100,7 @@ public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportServ { var resourceName = Assembly.GetExecutingAssembly() .GetManifestResourceNames() - .FirstOrDefault(n => n.EndsWith("DrillingProcessMapTemplate.xlsx"))!; + .FirstOrDefault(n => n.EndsWith("ProcessMapPlanImportWellDrillingTemplate.xlsx"))!; using var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(resourceName)!; @@ -225,6 +225,10 @@ public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportServ ?? throw new FileFormatException( $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указана некорректная секция"); + if(string.IsNullOrEmpty(modeName)) + throw new FileFormatException( + $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} не указан режим"); + var idMode = GetIdMode(modeName) ?? throw new FileFormatException( $"Лист {row.Worksheet.Name}. В строке {row.RowNumber()} указан некорректный режим"); diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Files/DrillingProcessMapTemplate.xlsx b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanImportWellDrillingTemplate.xlsx similarity index 100% rename from AsbCloudInfrastructure/Services/ProcessMaps/Files/DrillingProcessMapTemplate.xlsx rename to AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanImportWellDrillingTemplate.xlsx diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/ParamStat.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/ParamStat.cs deleted file mode 100644 index 3672487d..00000000 --- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/ParamStat.cs +++ /dev/null @@ -1,110 +0,0 @@ -using System; -using AsbCloudApp.Data.ProcessMaps.Report; -using AsbCloudApp.Data.SAUB; - -namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling.Report.Data; - -internal class ParamStat -{ - private double spWSum; - private double pvWSum; - private double limitMaxWSum; - - private double deltaDepthSum; - - private readonly Func getterSp; - private readonly Func getterPv; - private readonly Func? getterLimitMax; - - private readonly int idFeedRegulator; - private readonly int idMode; - private TelemetryDataSaubStatDto? previous; - - public double SpUsageDepth { get; private set; } - private static double spUsageTotal; - - public ParamStat(Func getterSp, - Func getterPv, - Func? getterLimitMax, - int idFeedRegulator, - int idMode) - { - this.getterSp = getterSp; - this.getterPv = getterPv; - this.getterLimitMax = getterLimitMax; - this.idFeedRegulator = idFeedRegulator; - this.idMode = idMode; - spUsageTotal = 0d; - } - - public void UpdateStat(TelemetryDataSaubStatDto current) - { - if (previous is not null) - { - var deltaDepth = current.WellDepthMin - previous.WellDepthMin; - if (deltaDepth > 0) - { - var deltaDepthHalf = deltaDepth / 2; - - double CalculateWeight(Func getter) => - (getter(previous!) + getter(current)) * deltaDepthHalf; - - spWSum += CalculateWeight(getterSp); - pvWSum += CalculateWeight(getterPv); - if (getterLimitMax is not null) - limitMaxWSum += CalculateWeight(getterLimitMax!); - - if (current.IdFeedRegulator is not null) - if (current.IdFeedRegulator == idFeedRegulator) - { - SpUsageDepth += deltaDepth; - spUsageTotal += deltaDepth; - } - else - { - var pvErr = (getterSp(current) - getterPv(current)) / getterSp(current); - if (pvErr < 0.03d) //3% - { - SpUsageDepth += deltaDepth; - spUsageTotal += deltaDepth; - } - } - - deltaDepthSum += deltaDepth; - } - } - - previous = current; - } - - public ProcessMapReportWellDrillingParamsDto MakeParams(double? spPlan) - { - var result = new ProcessMapReportWellDrillingParamsDto - { - SetpointPlan = spPlan, - Fact = DivideValByDepth(pvWSum), - }; - - if (idMode == 0) - { - result.SetpointFact = null; - result.Limit = null; - result.SetpointUsage = null; - } - else - { - result.SetpointFact = DivideValByDepth(spWSum); - result.Limit = getterLimitMax is not null ? DivideValByDepth(limitMaxWSum) : null; - result.SetpointUsage = deltaDepthSum > 0d ? 100d * SpUsageDepth / spUsageTotal : null; - } - - return result; - } - - private double? DivideValByDepth(double? val) - { - if (val is null || val == 0d || deltaDepthSum == 0d) - return null; - return val / deltaDepthSum; - } -} \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs index 7fbaae15..c3c6413f 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs @@ -32,15 +32,15 @@ public abstract class ProcessMapBaseController : ControllerBase protected int IdUser { - get - { - var idUser = User.GetUserId(); + get + { + var idUser = User.GetUserId(); - if (!idUser.HasValue) - throw new ForbidException("Неизвестный пользователь"); + if (!idUser.HasValue) + throw new ForbidException("Неизвестный пользователь"); - return idUser.Value; - } + return idUser.Value; + } } private readonly IWellService wellService; @@ -50,18 +50,18 @@ public abstract class ProcessMapBaseController : ControllerBase protected readonly IProcessMapPlanRepository repository; protected ProcessMapBaseController(IWellService wellService, - IProcessMapPlanRepository repository, - IUserRepository userRepository, - ICrudRepository wellSectionRepository, - IHubContext telemetryHubContext, - ITelemetryService telemetryService) + IProcessMapPlanRepository repository, + IUserRepository userRepository, + ICrudRepository wellSectionRepository, + IHubContext telemetryHubContext, + ITelemetryService telemetryService) { - this.wellService = wellService; - this.repository = repository; - this.userRepository = userRepository; - this.wellSectionRepository = wellSectionRepository; - this.telemetryHubContext = telemetryHubContext; - this.telemetryService = telemetryService; + this.wellService = wellService; + this.repository = repository; + this.userRepository = userRepository; + this.wellSectionRepository = wellSectionRepository; + this.telemetryHubContext = telemetryHubContext; + this.telemetryService = telemetryService; } /// @@ -76,19 +76,19 @@ public abstract class ProcessMapBaseController : ControllerBase [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public virtual async Task InsertAsync(T processMap, int idWell, CancellationToken cancellationToken) { - processMap.IdWell = idWell; - processMap.IdUser = IdUser; - processMap.LastUpdate = DateTime.UtcNow; + processMap.IdWell = idWell; + processMap.IdUser = IdUser; + processMap.LastUpdate = DateTime.UtcNow; - await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); + await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); - await AssertUserHasAccessToEditProcessMapAsync(processMap.IdWell, cancellationToken); + await AssertUserHasAccessToEditProcessMapAsync(processMap.IdWell, cancellationToken); var result = await repository.InsertAsync(processMap, cancellationToken); - await NotifyUsersBySignalR(idWell, cancellationToken); + await NotifyUsersBySignalR(idWell, cancellationToken); - return Ok(result); + return Ok(result); } /// @@ -103,22 +103,22 @@ public abstract class ProcessMapBaseController : ControllerBase [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public virtual async Task UpdateAsync(T processMap, int idWell, CancellationToken cancellationToken) { - processMap.IdWell = idWell; - processMap.IdUser = IdUser; - processMap.LastUpdate = DateTime.UtcNow; + processMap.IdWell = idWell; + processMap.IdUser = IdUser; + processMap.LastUpdate = DateTime.UtcNow; - await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); + await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); - await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); + await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); var result = await repository.UpdateAsync(processMap, cancellationToken); - if (result == ICrudRepository.ErrorIdNotFound) - return this.ValidationBadRequest(nameof(processMap.Id), $"РТК с Id: {processMap.Id} не существует"); + if (result == ICrudRepository.ErrorIdNotFound) + return this.ValidationBadRequest(nameof(processMap.Id), $"РТК с Id: {processMap.Id} не существует"); - await NotifyUsersBySignalR(idWell, cancellationToken); + await NotifyUsersBySignalR(idWell, cancellationToken); - return Ok(result); + return Ok(result); } /// @@ -132,13 +132,13 @@ public abstract class ProcessMapBaseController : ControllerBase [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] public virtual async Task DeleteAsync(int id, int idWell, CancellationToken cancellationToken) { - await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); + await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); - var result = await repository.DeleteAsync(id, cancellationToken); + var result = await repository.DeleteAsync(id, cancellationToken); - await NotifyUsersBySignalR(idWell, cancellationToken); + await NotifyUsersBySignalR(idWell, cancellationToken); - return Ok(result); + return Ok(result); } /// @@ -150,9 +150,9 @@ public abstract class ProcessMapBaseController : ControllerBase [HttpGet] public async Task>> GetAsync(int idWell, CancellationToken cancellationToken) { - var processMaps = await repository.GetByIdWellAsync(idWell, cancellationToken); + var processMaps = await repository.GetByIdWellAsync(idWell, cancellationToken); - return Ok(processMaps); + return Ok(processMaps); } /// @@ -167,49 +167,50 @@ public abstract class ProcessMapBaseController : ControllerBase [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task>> GetProcessMapPlanByTelemetry(string uid, DateTime updateFrom, CancellationToken cancellationToken) { - var idWell = telemetryService.GetIdWellByTelemetryUid(uid); + var idWell = telemetryService.GetIdWellByTelemetryUid(uid); - if (!idWell.HasValue) - return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}"); + if (!idWell.HasValue) + return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}"); - var wellDrillingProcessMaps = await repository.GetAsync(new[] { new ProcessMapPlanRequest - { - IdWell = idWell.Value, - UpdateFrom = updateFrom - }}, cancellationToken); + var requests = new[] { new ProcessMapPlanRequest + { + IdWell = idWell.Value, + UpdateFrom = updateFrom + } + }; - return Ok(wellDrillingProcessMaps); + var processMaps = await repository.GetAsync(requests, cancellationToken); + + return Ok(processMaps); } protected async Task AssertUserHasAccessToEditProcessMapAsync(int idWell, CancellationToken cancellationToken) { - var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken) - ?? throw new ArgumentInvalidException(nameof(idWell), $"Скважины с {idWell} не существует"); + var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken) + ?? throw new ArgumentInvalidException(nameof(idWell), $"Скважины с {idWell} не существует"); var idCompany = User.GetCompanyId(); - if (!idCompany.HasValue || - !await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, cancellationToken)) - throw new ForbidException("Нет доступа к скважине"); + if (!idCompany.HasValue || + !await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, cancellationToken)) + throw new ForbidException("Нет доступа к скважине"); - if (well.IdState == 2 && !userRepository.HasPermission(IdUser, "ProcessMap.editCompletedWell")) - throw new ForbidException("Недостаточно прав для редактирования РТК завершенной скважины"); + if (well.IdState == 2 && !userRepository.HasPermission(IdUser, "ProcessMap.editCompletedWell")) + throw new ForbidException("Недостаточно прав для редактирования РТК завершенной скважины"); } protected async Task NotifyUsersBySignalR(int idWell, CancellationToken cancellationToken) { - var dtos = await repository.GetByIdWellAsync(idWell, cancellationToken); + var dtos = await repository.GetByIdWellAsync(idWell, cancellationToken); - await telemetryHubContext.Clients - .Group($"{SignalRMethod}_{idWell}") - .SendAsync("UpdateProcessMap", dtos, cancellationToken); + await telemetryHubContext.Clients + .Group($"{SignalRMethod}_{idWell}") + .SendAsync("UpdateProcessMap", dtos, cancellationToken); } private async Task CheckIsExistsWellSectionTypeAsync(int idWellSectionType, CancellationToken cancellationToken) { - var wellSection = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken); - - if (wellSection is null) - throw new ArgumentInvalidException(nameof(ProcessMapPlanWellDrillingDto.IdWellSectionType), $"Тип секции с Id: {idWellSectionType} не найден"); + _ = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken) + ?? throw new ArgumentInvalidException(nameof(ProcessMapPlanWellDrillingDto.IdWellSectionType), $"Тип секции с Id: {idWellSectionType} не найден"); } } \ No newline at end of file