diff --git a/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs b/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs
index 12e9d193..657bb493 100644
--- a/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs
+++ b/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanWellReamDto.cs
@@ -6,7 +6,7 @@ namespace AsbCloudApp.Data.ProcessMaps;
///
/// РТК план проработка скважины
///
-public class ProcessMapPlanWellReamDto : ProcessMapPlanBaseDto
+public class ProcessMapPlanWellReamDto : ProcessMapPlanBaseDto, IValidatableObject
{
///
/// Количество повторений
diff --git a/AsbCloudApp/Repositories/IProcessMapPlanRepository.cs b/AsbCloudApp/Repositories/IProcessMapPlanRepository.cs
index 46b0103f..1828b3ed 100644
--- a/AsbCloudApp/Repositories/IProcessMapPlanRepository.cs
+++ b/AsbCloudApp/Repositories/IProcessMapPlanRepository.cs
@@ -25,7 +25,6 @@ public interface IProcessMapPlanRepository : IRepositoryWellRelated
/// Удалить РТК по скважине
///
///
- ///
///
- Task RemoveByWellAsync(int idWell, CancellationToken cancellationToken);
+ Task RemoveByWellAsync(int idWell);
}
diff --git a/AsbCloudApp/Services/ProcessMaps/IProcessMapImportService.cs b/AsbCloudApp/Services/ProcessMaps/IProcessMapPlanImportService.cs
similarity index 96%
rename from AsbCloudApp/Services/ProcessMaps/IProcessMapImportService.cs
rename to AsbCloudApp/Services/ProcessMaps/IProcessMapPlanImportService.cs
index 03a57085..7b30b80d 100644
--- a/AsbCloudApp/Services/ProcessMaps/IProcessMapImportService.cs
+++ b/AsbCloudApp/Services/ProcessMaps/IProcessMapPlanImportService.cs
@@ -7,7 +7,7 @@ namespace AsbCloudApp.Services.ProcessMaps;
///
/// Сервис импорта РТК
///
-public interface IProcessMapImportService
+public interface IProcessMapPlanImportService
{
///
/// Загрузить данные из файла
diff --git a/AsbCloudApp/Services/ProcessMaps/IProcessMapReportExportService.cs b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportWellDrillingExportService.cs
similarity index 79%
rename from AsbCloudApp/Services/ProcessMaps/IProcessMapReportExportService.cs
rename to AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportWellDrillingExportService.cs
index ff1edeff..4a262fa8 100644
--- a/AsbCloudApp/Services/ProcessMaps/IProcessMapReportExportService.cs
+++ b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportWellDrillingExportService.cs
@@ -2,12 +2,12 @@
using System.Threading.Tasks;
using System.Threading;
-namespace AsbCloudApp.Services.ProcessMaps;
+namespace AsbCloudApp.Services.ProcessMaps.WellDrilling;
///
/// Сервис экспорт РТК
///
-public interface IProcessMapReportExportService
+public interface IProcessMapReportWellDrillingExportService
{
///
/// Сформировать файл с данными
diff --git a/AsbCloudApp/Services/ProcessMaps/WellDrillingProcessMap/IProcessMapReportWellDrillingService.cs b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportWellDrillingService.cs
similarity index 79%
rename from AsbCloudApp/Services/ProcessMaps/WellDrillingProcessMap/IProcessMapReportWellDrillingService.cs
rename to AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportWellDrillingService.cs
index c2c54f99..52079d92 100644
--- a/AsbCloudApp/Services/ProcessMaps/WellDrillingProcessMap/IProcessMapReportWellDrillingService.cs
+++ b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportWellDrillingService.cs
@@ -3,10 +3,10 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps.Report;
-namespace AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
+namespace AsbCloudApp.Services.ProcessMaps.WellDrilling;
///
-/// Сервис формирования отчёта РТК
+/// Сервис формирования отчёта РТК бурение
///
public interface IProcessMapReportWellDrillingService
{
diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs
index 9f3de68a..be020f89 100644
--- a/AsbCloudInfrastructure/DependencyInjection.cs
+++ b/AsbCloudInfrastructure/DependencyInjection.cs
@@ -10,7 +10,7 @@ using AsbCloudApp.Services;
using AsbCloudApp.Services.AutoGeneratedDailyReports;
using AsbCloudApp.Services.Notifications;
using AsbCloudApp.Services.ProcessMaps;
-using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
+using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using AsbCloudApp.Services.Subsystems;
using AsbCloudApp.Services.WellOperationImport;
using AsbCloudDb.Model;
@@ -183,7 +183,7 @@ namespace AsbCloudInfrastructure
services.AddTransient();
services.AddTransient();
services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -196,8 +196,8 @@ namespace AsbCloudInfrastructure
services.AddTransient();
services.AddTransient();
services.AddTransient();
- services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
diff --git a/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheRepositoryBase.cs b/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheRepositoryBase.cs
index 7afc8428..c02702b5 100644
--- a/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheRepositoryBase.cs
+++ b/AsbCloudInfrastructure/Repository/CrudWellRelatedCacheRepositoryBase.cs
@@ -32,20 +32,6 @@ namespace AsbCloudInfrastructure.Repository
return dtos;
}
- public async Task RemoveByWellAsync(int idWell, CancellationToken cancellationToken)
- {
- var query = GetQuery().Where(x => x.IdWell == idWell);
-
- dbSet.RemoveRange(query);
-
- var result = await dbContext.SaveChangesAsync(cancellationToken);
-
- if(result > 0)
- DropCache();
-
- return result;
- }
-
public async Task> GetByIdWellAsync(IEnumerable idsWells, CancellationToken token)
{
if (!idsWells.Any())
diff --git a/AsbCloudInfrastructure/Repository/ProcessMapPlanRepository.cs b/AsbCloudInfrastructure/Repository/ProcessMapPlanRepository.cs
index e447bc2d..c362611a 100644
--- a/AsbCloudInfrastructure/Repository/ProcessMapPlanRepository.cs
+++ b/AsbCloudInfrastructure/Repository/ProcessMapPlanRepository.cs
@@ -30,19 +30,20 @@ public class ProcessMapPlanRepository : CrudWellRelatedRepository
public async Task> GetAsync(IEnumerable requests, CancellationToken cancellationToken)
{
- var entities = await BuildQuery(requests)
- .ToArrayAsync(cancellationToken);
+ var query = BuildQuery(requests);
+
+ var entities = await query.ToArrayAsync(cancellationToken);
return entities.Select(Convert);
}
- public Task RemoveByWellAsync(int idWell, CancellationToken cancellationToken)
+ public Task RemoveByWellAsync(int idWell)
{
var query = GetQuery().Where(x => x.IdWell == idWell);
dbSet.RemoveRange(query);
- return dbContext.SaveChangesAsync(cancellationToken);
+ return dbContext.SaveChangesAsync(CancellationToken.None);
}
private IQueryable BuildQuery(IEnumerable requests)
diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/WellDrillingProcessMapImportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanWellDrillingImportService.cs
similarity index 98%
rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/WellDrillingProcessMapImportService.cs
rename to AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanWellDrillingImportService.cs
index 3e4704bc..2e556f2e 100644
--- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/WellDrillingProcessMapImportService.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/ProcessMapPlanWellDrillingImportService.cs
@@ -18,7 +18,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap;
/*
* password for ProcessMapImportTemplate.xlsx is ASB2020!
*/
-public class WellDrillingProcessMapImportService : IProcessMapImportService
+public class ProcessMapPlanWellDrillingImportService : IProcessMapPlanImportService
{
private readonly IProcessMapPlanRepository processMapPlanWellDrillingRepository;
private readonly ICrudRepository wellSectionTypeRepository;
@@ -49,7 +49,7 @@ public class WellDrillingProcessMapImportService : IProcessMapImportService
private WellSectionTypeDto[] sections = null!;
- public WellDrillingProcessMapImportService(IProcessMapPlanRepository processMapPlanWellDrillingRepository,
+ public ProcessMapPlanWellDrillingImportService(IProcessMapPlanRepository processMapPlanWellDrillingRepository,
ICrudRepository wellSectionTypeRepository,
IWellService wellService)
{
@@ -68,7 +68,7 @@ public class WellDrillingProcessMapImportService : IProcessMapImportService
var wellDrillingProcessMaps = ParseWorkBook(workBook);
if (deleteProcessMapPlansBeforeImport)
- await processMapPlanWellDrillingRepository.RemoveByWellAsync(idWell, cancellationToken);
+ await processMapPlanWellDrillingRepository.RemoveByWellAsync(idWell);
foreach (var wellDrillingProcessMap in wellDrillingProcessMaps)
{
diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/ParamStat.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/ParamStat.cs
new file mode 100644
index 00000000..3672487d
--- /dev/null
+++ b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/ParamStat.cs
@@ -0,0 +1,110 @@
+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/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/Data/TelemetryStat.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/TelemetryStat.cs
similarity index 97%
rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/Data/TelemetryStat.cs
rename to AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/TelemetryStat.cs
index 34daa65e..7b231d7f 100644
--- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/Data/TelemetryStat.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/Data/TelemetryStat.cs
@@ -1,5 +1,6 @@
using System;
using AsbCloudApp.Data.SAUB;
+using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling.Report.Data;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.Data;
diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/WellDrillingProcessMapReportExportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingExportService.cs
similarity index 96%
rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/WellDrillingProcessMapReportExportService.cs
rename to AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingExportService.cs
index 233ca49b..17c8c423 100644
--- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/WellDrillingProcessMapReportExportService.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingExportService.cs
@@ -6,13 +6,12 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps.Report;
using AsbCloudApp.Services;
-using AsbCloudApp.Services.ProcessMaps;
-using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
+using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using ClosedXML.Excel;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
-public class WellDrillingProcessMapReportExportService : IProcessMapReportExportService
+public class ProcessMapReportWellDrillingExportService : IProcessMapReportWellDrillingExportService
{
const int firstColumn = 2;
const int lastColumn = 42;
@@ -22,7 +21,7 @@ public class WellDrillingProcessMapReportExportService : IProcessMapReportExport
private readonly IWellService wellService;
private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingService;
- public WellDrillingProcessMapReportExportService(IWellService wellService,
+ public ProcessMapReportWellDrillingExportService(IWellService wellService,
IProcessMapReportWellDrillingService processMapReportWellDrillingService)
{
this.wellService = wellService;
diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/WellDrillingProcessMapReportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingService.cs
similarity index 98%
rename from AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/WellDrillingProcessMapReportService.cs
rename to AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingService.cs
index 38574c30..2a11d729 100644
--- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/WellDrillingProcessMapReportService.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrilling/Report/ProcessMapReportWellDrillingService.cs
@@ -9,19 +9,19 @@ using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
-using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
+using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.Data;
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
-public class WellDrillingProcessMapReportService : IProcessMapReportWellDrillingService
+public class ProcessMapReportWellDrillingService : IProcessMapReportWellDrillingService
{
private readonly IWellService wellService;
private readonly IProcessMapPlanRepository processMapPlanWellDrillingRepository;
private readonly ITelemetryDataSaubService telemetryDataSaubService;
private readonly IWellOperationRepository wellOperationRepository;
- public WellDrillingProcessMapReportService(IWellService wellService,
+ public ProcessMapReportWellDrillingService(IWellService wellService,
IProcessMapPlanRepository processMapPlanWellDrillingRepository,
ITelemetryDataSaubService telemetryDataSaubService,
IWellOperationRepository wellOperationRepository)
diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/Data/ParamStat.cs b/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/Data/ParamStat.cs
deleted file mode 100644
index 56f84efd..00000000
--- a/AsbCloudInfrastructure/Services/ProcessMaps/WellDrillingProcessMap/Report/Data/ParamStat.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-using System;
-using AsbCloudApp.Data.ProcessMaps.Report;
-using AsbCloudApp.Data.SAUB;
-
-namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.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 612f30e4..1377a15a 100644
--- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs
+++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs
@@ -5,10 +5,13 @@ using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
+using AsbCloudApp.Requests;
using AsbCloudApp.Services;
+using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.SignalR;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@@ -21,38 +24,47 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
public abstract class ProcessMapBaseController : ControllerBase
where T : ProcessMapPlanBaseDto
{
+ private readonly IHubContext telemetryHubContext;
+ private readonly ITelemetryService telemetryService;
+
+ public abstract string SignalRMethod { get; }
+
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;
private readonly IUserRepository userRepository;
private readonly ICrudRepository wellSectionRepository;
- protected readonly IRepositoryWellRelated repository;
+ protected readonly IProcessMapPlanRepository repository;
protected ProcessMapBaseController(IWellService wellService,
- IProcessMapPlanRepository repository,
- IUserRepository userRepository,
- ICrudRepository wellSectionRepository)
+ IProcessMapPlanRepository repository,
+ IUserRepository userRepository,
+ ICrudRepository wellSectionRepository,
+ IHubContext telemetryHubContext,
+ ITelemetryService telemetryService)
{
- this.wellService = wellService;
- this.repository = repository;
- this.userRepository = userRepository;
- this.wellSectionRepository = wellSectionRepository;
+ this.wellService = wellService;
+ this.repository = repository;
+ this.userRepository = userRepository;
+ this.wellSectionRepository = wellSectionRepository;
+ this.telemetryHubContext = telemetryHubContext;
+ this.telemetryService = telemetryService;
}
///
- /// Создание РТК
+ /// Создание плановой РТК
///
/// Тело запроса
/// Id скважины
@@ -64,8 +76,8 @@ public abstract class ProcessMapBaseController : ControllerBase
public virtual async Task InsertAsync(T processMap, int idWell, CancellationToken cancellationToken)
{
processMap.IdWell = idWell;
- processMap.IdUser = IdUser;
- processMap.LastUpdate = DateTime.UtcNow;
+ processMap.IdUser = IdUser;
+ processMap.LastUpdate = DateTime.UtcNow;
await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken);
@@ -73,11 +85,13 @@ public abstract class ProcessMapBaseController : ControllerBase
var result = await repository.InsertAsync(processMap, cancellationToken);
- return Ok(result);
+ await NotifyUsersBySignalR(idWell, cancellationToken);
+
+ return Ok(result);
}
///
- /// Обновление РТК
+ /// Обновление плановой РТК
///
/// Тело запроса
/// Id скважины
@@ -88,9 +102,9 @@ 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);
@@ -98,14 +112,16 @@ public abstract class ProcessMapBaseController : ControllerBase
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} не существует");
- return Ok(result);
+ await NotifyUsersBySignalR(idWell, cancellationToken);
+
+ return Ok(result);
}
///
- /// Удаление РТК
+ /// Удаление плановой РТК
///
/// Id удаляемой РТК
/// Id скважины
@@ -113,14 +129,15 @@ public abstract class ProcessMapBaseController : ControllerBase
///
[HttpDelete]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
- [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public virtual async Task DeleteAsync(int id, int idWell, CancellationToken cancellationToken)
{
await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken);
- var result = await repository.DeleteAsync(id, cancellationToken);
+ var result = await repository.DeleteAsync(id, cancellationToken);
- return Ok(result);
+ await NotifyUsersBySignalR(idWell, cancellationToken);
+
+ return Ok(result);
}
///
@@ -130,27 +147,62 @@ public abstract class ProcessMapBaseController : ControllerBase
///
///
[HttpGet]
- [ProducesResponseType(StatusCodes.Status204NoContent)]
+ [ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
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);
+ }
+
+ ///
+ /// Получение РТК по телеметрии
+ ///
+ /// Уникальный ключ телеметрии
+ /// Дата с которой требуется получить РТК
+ ///
+ ///
+ [HttpGet("/api/[controller]/telemetry/{uid}")]
+ [ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
+ [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
+ public async Task GetProcessMapPlanByTelemetry(string uid, DateTime updateFrom, CancellationToken cancellationToken)
+ {
+ var idWell = telemetryService.GetIdWellByTelemetryUid(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);
+
+ return Ok(wellDrillingProcessMaps);
}
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 wellDrillingProcessMaps = await repository.GetByIdWellAsync(idWell, cancellationToken);
+
+ await telemetryHubContext.Clients
+ .Group($"{SignalRMethod}_{idWell}")
+ .SendAsync("UpdateProcessMap", wellDrillingProcessMaps, cancellationToken);
}
private async Task CheckIsExistsWellSectionTypeAsync(int idWellSectionType, CancellationToken cancellationToken)
diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs
index e6126744..d37869e3 100644
--- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs
+++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs
@@ -4,11 +4,10 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
-using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudApp.Services.ProcessMaps;
-using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
+using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -18,74 +17,26 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
public class ProcessMapWellDrillingController : ProcessMapBaseController
{
- private readonly IHubContext telemetryHubContext;
+ private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingService;
+ private readonly IProcessMapReportWellDrillingExportService processMapReportWellDrillingExportService;
+ private readonly IProcessMapPlanImportService processMapPlanImportService;
- private readonly IProcessMapReportWellDrillingService wellDrillingProcessMapReportService;
- private readonly IProcessMapReportExportService wellDrillingProcessMapReportExportService;
- private readonly IProcessMapImportService wellDrillingProcessMapImportService;
+ public override string SignalRMethod => "ProcessMapWellDrilling";
public ProcessMapWellDrillingController(IWellService wellService,
IProcessMapPlanRepository repository,
IUserRepository userRepository,
+ IProcessMapReportWellDrillingExportService processMapReportWellDrillingExportService,
+ IProcessMapPlanImportService processMapPlanImportService,
+ IProcessMapReportWellDrillingService processMapReportWellDrillingService,
+ ICrudRepository wellSectionRepository,
IHubContext telemetryHubContext,
- IProcessMapReportExportService wellDrillingProcessMapReportExportService,
- IProcessMapImportService wellDrillingProcessMapImportService,
- IProcessMapReportWellDrillingService wellDrillingProcessMapReportService,
- ICrudRepository wellSectionRepository)
- : base(wellService, repository, userRepository, wellSectionRepository)
+ ITelemetryService telemetryService)
+ : base(wellService, repository, userRepository, wellSectionRepository, telemetryHubContext, telemetryService)
{
- this.telemetryHubContext = telemetryHubContext;
- this.wellDrillingProcessMapReportExportService = wellDrillingProcessMapReportExportService;
- this.wellDrillingProcessMapImportService = wellDrillingProcessMapImportService;
- this.wellDrillingProcessMapReportService = wellDrillingProcessMapReportService;
- }
-
- ///
- /// Создание РТК
- ///
- /// Тело запроса
- /// Id скважины
- ///
- ///
- public override async Task InsertAsync(ProcessMapPlanWellDrillingDto processMap, int idWell, CancellationToken cancellationToken)
- {
- var result = await base.InsertAsync(processMap, idWell, cancellationToken);
-
- await NotifyUsersBySignalR(idWell, cancellationToken);
-
- return result;
- }
-
- ///
- /// Обновление РТК
- ///
- /// Тело запроса
- /// Id скважины
- ///
- ///
- public override async Task UpdateAsync(ProcessMapPlanWellDrillingDto processMap, int idWell, CancellationToken cancellationToken)
- {
- var result = await base.UpdateAsync(processMap, idWell, cancellationToken);
-
- await NotifyUsersBySignalR(idWell, cancellationToken);
-
- return result;
- }
-
- ///
- /// Удаление РТК
- ///
- /// Id удаляемой РТК
- /// Id скважины
- ///
- ///
- public override async Task DeleteAsync(int id, int idWell, CancellationToken cancellationToken)
- {
- var result = await base.DeleteAsync(id, idWell, cancellationToken);
-
- await NotifyUsersBySignalR(idWell, cancellationToken);
-
- return result;
+ this.processMapReportWellDrillingExportService = processMapReportWellDrillingExportService;
+ this.processMapPlanImportService = processMapPlanImportService;
+ this.processMapReportWellDrillingService = processMapReportWellDrillingService;
}
///
@@ -98,7 +49,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController GetReportAsync(int idWell, CancellationToken cancellationToken)
{
- var report = await wellDrillingProcessMapReportService.GetAsync(idWell, cancellationToken);
+ var report = await processMapReportWellDrillingService.GetAsync(idWell, cancellationToken);
return Ok(report);
}
@@ -114,7 +65,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController ExportReportAsync(int idWell, CancellationToken cancellationToken)
{
- var report = await wellDrillingProcessMapReportExportService.ExportAsync(idWell, cancellationToken);
+ var report = await processMapReportWellDrillingExportService.ExportAsync(idWell, cancellationToken);
if (report is null)
return NoContent();
@@ -146,7 +97,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController 0,
stream,
@@ -173,7 +124,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController ExportAsync(int idWell, CancellationToken cancellationToken)
{
- var processMapsFile = await wellDrillingProcessMapImportService.ExportAsync(idWell, cancellationToken);
+ var processMapsFile = await processMapPlanImportService.ExportAsync(idWell, cancellationToken);
return File(processMapsFile.File, "application/octet-stream", processMapsFile.Name);
}
@@ -186,16 +137,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController GetTemplateAsync(CancellationToken cancellationToken)
{
- var template = await wellDrillingProcessMapImportService.GetExcelTemplateStreamAsync(cancellationToken);
+ var template = await processMapPlanImportService.GetExcelTemplateStreamAsync(cancellationToken);
return File(template.File, "application/octet-stream", template.Name);
}
-
- private async Task NotifyUsersBySignalR(int idWell, CancellationToken cancellationToken)
- {
- var wellDrillingProcessMaps = await repository.GetByIdWellAsync(idWell, cancellationToken);
-
- await telemetryHubContext.Clients
- .Group($"well_{idWell}")
- .SendAsync("UpdateProcessMap", wellDrillingProcessMaps, cancellationToken);
- }
}
\ No newline at end of file
diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellReamController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellReamController.cs
index 7236a0ca..1d69041c 100644
--- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellReamController.cs
+++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellReamController.cs
@@ -2,6 +2,8 @@
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
+using AsbCloudWebApi.SignalR;
+using Microsoft.AspNetCore.SignalR;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@@ -10,8 +12,12 @@ public class ProcessMapWellReamController : ProcessMapBaseController repository,
IUserRepository userRepository,
- ICrudRepository wellSectionRepository)
- : base(wellService, repository, userRepository, wellSectionRepository)
+ ICrudRepository wellSectionRepository,
+ IHubContext telemetryHubContext,
+ ITelemetryService telemetryService)
+ : base(wellService, repository, userRepository, wellSectionRepository, telemetryHubContext, telemetryService)
{
}
+
+ public override string SignalRMethod => "ProccessMapWellReam";
}
\ No newline at end of file
diff --git a/AsbCloudWebApi/Controllers/SAUB/TelemetryProcessMapController.cs b/AsbCloudWebApi/Controllers/SAUB/TelemetryProcessMapController.cs
deleted file mode 100644
index ae438b04..00000000
--- a/AsbCloudWebApi/Controllers/SAUB/TelemetryProcessMapController.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using AsbCloudApp.Data.ProcessMaps;
-using AsbCloudApp.Repositories;
-using AsbCloudApp.Requests;
-using AsbCloudApp.Services;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-
-namespace AsbCloudWebApi.Controllers.SAUB;
-
-///
-/// Данные РТК для SAUB
-///
-[ApiController]
-[Route("api/[controller]")]
-public class TelemetryProcessMapController : ControllerBase
-{
- private readonly ITelemetryService telemetryService;
- private readonly IProcessMapPlanRepository processMapPlanWellDrillingRepository;
- private readonly IProcessMapPlanRepository processMapPlanWellReamRepository;
-
- public TelemetryProcessMapController(ITelemetryService telemetryService,
- IProcessMapPlanRepository processMapPlanWellDrillingRepository,
- IProcessMapPlanRepository processMapPlanWellReamRepository)
- {
- this.telemetryService = telemetryService;
- this.processMapPlanWellDrillingRepository = processMapPlanWellDrillingRepository;
- this.processMapPlanWellReamRepository = processMapPlanWellReamRepository;
- }
-
- ///
- /// Получение РТК бурение по Uid телеметрии
- ///
- /// Уникальный Id телеметрии
- /// Дата с которой требуется получить РТК
- ///
- ///
- [HttpGet("processMapPlanWellDrilling")]
- [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
- [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
- public async Task GetProcessMapPlanWellDrillingByUidAsync(string uid, DateTime updateFrom, CancellationToken cancellationToken)
- {
- var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
-
- if (!idWell.HasValue)
- return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}");
-
- var wellDrillingProcessMaps = await processMapPlanWellDrillingRepository.GetAsync(new[] { new ProcessMapPlanRequest
- {
- IdWell = idWell.Value,
- UpdateFrom = updateFrom
- }}, cancellationToken);
-
- return Ok(wellDrillingProcessMaps);
- }
-
- ///
- /// Получение РТК проработки по Uid телеметрии
- ///
- /// Уникальный Id телеметрии
- /// Дата с которой требуется получить РТК
- ///
- ///
- [HttpGet("processMapPlanWellReam")]
- [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
- [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
- public async Task GetProcessMapPlanWellReamByUidAsync(string uid, DateTime updateFrom,
- CancellationToken cancellationToken)
- {
- var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
-
- if (!idWell.HasValue)
- return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}");
-
- var wellReamProcessMaps = await processMapPlanWellReamRepository.GetAsync(new[] { new ProcessMapPlanRequest
- {
- IdWell = idWell.Value,
- UpdateFrom = updateFrom
- }}, cancellationToken);
-
- return Ok(wellReamProcessMaps);
- }
-
-}
\ No newline at end of file