forked from ddrilling/AsbCloudServer
Правки после ревью
This commit is contained in:
parent
7f4966a0bd
commit
72bb234179
@ -6,7 +6,7 @@ namespace AsbCloudApp.Data.ProcessMaps;
|
||||
/// <summary>
|
||||
/// РТК план проработка скважины
|
||||
/// </summary>
|
||||
public class ProcessMapPlanWellReamDto : ProcessMapPlanBaseDto
|
||||
public class ProcessMapPlanWellReamDto : ProcessMapPlanBaseDto, IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Количество повторений
|
||||
|
@ -25,7 +25,6 @@ public interface IProcessMapPlanRepository<TDto> : IRepositoryWellRelated<TDto>
|
||||
/// Удалить РТК по скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> RemoveByWellAsync(int idWell, CancellationToken cancellationToken);
|
||||
Task<int> RemoveByWellAsync(int idWell);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace AsbCloudApp.Services.ProcessMaps;
|
||||
/// <summary>
|
||||
/// Сервис импорта РТК
|
||||
/// </summary>
|
||||
public interface IProcessMapImportService
|
||||
public interface IProcessMapPlanImportService
|
||||
{
|
||||
/// <summary>
|
||||
/// Загрузить данные из файла
|
@ -2,12 +2,12 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace AsbCloudApp.Services.ProcessMaps;
|
||||
namespace AsbCloudApp.Services.ProcessMaps.WellDrilling;
|
||||
|
||||
/// <summary>
|
||||
/// Сервис экспорт РТК
|
||||
/// </summary>
|
||||
public interface IProcessMapReportExportService
|
||||
public interface IProcessMapReportWellDrillingExportService
|
||||
{
|
||||
/// <summary>
|
||||
/// Сформировать файл с данными
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Сервис формирования отчёта РТК
|
||||
/// Сервис формирования отчёта РТК бурение
|
||||
/// </summary>
|
||||
public interface IProcessMapReportWellDrillingService
|
||||
{
|
@ -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<ITimezoneService, TimezoneService>();
|
||||
services.AddTransient<IWellService, WellService>();
|
||||
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
||||
services.AddTransient<IProcessMapReportExportService, WellDrillingProcessMapReportExportService>();
|
||||
services.AddTransient<IProcessMapReportWellDrillingExportService, ProcessMapReportWellDrillingExportService>();
|
||||
services.AddTransient<IPlannedTrajectoryImportService, PlannedTrajectoryImportService>();
|
||||
services.AddTransient<IWellOperationRepository, WellOperationRepository>();
|
||||
services.AddTransient<IScheduleReportService, ScheduleReportService>();
|
||||
@ -196,8 +196,8 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IWellFinalDocumentsService, WellFinalDocumentsService>();
|
||||
services.AddTransient<IFileCategoryService, FileCategoryService>();
|
||||
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
|
||||
services.AddTransient<IProcessMapReportWellDrillingService, WellDrillingProcessMapReportService>();
|
||||
services.AddTransient<IProcessMapImportService, WellDrillingProcessMapImportService>();
|
||||
services.AddTransient<IProcessMapReportWellDrillingService, ProcessMapReportWellDrillingService>();
|
||||
services.AddTransient<IProcessMapPlanImportService, ProcessMapPlanWellDrillingImportService>();
|
||||
services.AddTransient<WellInfoService>();
|
||||
services.AddTransient<IHelpPageService, HelpPageService>();
|
||||
|
||||
|
@ -32,20 +32,6 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<int> 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<IEnumerable<TDto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
|
||||
{
|
||||
if (!idsWells.Any())
|
||||
|
@ -30,19 +30,20 @@ public class ProcessMapPlanRepository<TDto, TEntity> : CrudWellRelatedRepository
|
||||
|
||||
public async Task<IEnumerable<TDto>> GetAsync(IEnumerable<ProcessMapPlanRequest> 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<int> RemoveByWellAsync(int idWell, CancellationToken cancellationToken)
|
||||
public Task<int> 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<TEntity> BuildQuery(IEnumerable<ProcessMapPlanRequest> requests)
|
||||
|
@ -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<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository;
|
||||
private readonly ICrudRepository<WellSectionTypeDto> wellSectionTypeRepository;
|
||||
@ -49,7 +49,7 @@ public class WellDrillingProcessMapImportService : IProcessMapImportService
|
||||
|
||||
private WellSectionTypeDto[] sections = null!;
|
||||
|
||||
public WellDrillingProcessMapImportService(IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
|
||||
public ProcessMapPlanWellDrillingImportService(IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
|
||||
ICrudRepository<WellSectionTypeDto> 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)
|
||||
{
|
@ -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<TelemetryDataSaubStatDto, double> getterSp;
|
||||
private readonly Func<TelemetryDataSaubStatDto, double> getterPv;
|
||||
private readonly Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> getterSp,
|
||||
Func<TelemetryDataSaubStatDto, double> getterPv,
|
||||
Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> 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;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling.Report.Data;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report.Data;
|
||||
|
@ -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;
|
@ -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<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository;
|
||||
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
|
||||
public WellDrillingProcessMapReportService(IWellService wellService,
|
||||
public ProcessMapReportWellDrillingService(IWellService wellService,
|
||||
IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
|
||||
ITelemetryDataSaubService telemetryDataSaubService,
|
||||
IWellOperationRepository wellOperationRepository)
|
@ -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<TelemetryDataSaubStatDto, double> getterSp;
|
||||
private readonly Func<TelemetryDataSaubStatDto, double> getterPv;
|
||||
private readonly Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> getterSp,
|
||||
Func<TelemetryDataSaubStatDto, double> getterPv,
|
||||
Func<TelemetryDataSaubStatDto, double>? 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<TelemetryDataSaubStatDto, double> 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;
|
||||
}
|
||||
}
|
@ -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,6 +24,11 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
|
||||
public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
where T : ProcessMapPlanBaseDto
|
||||
{
|
||||
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
|
||||
public abstract string SignalRMethod { get; }
|
||||
|
||||
protected int IdUser
|
||||
{
|
||||
get
|
||||
@ -38,21 +46,25 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
private readonly IUserRepository userRepository;
|
||||
private readonly ICrudRepository<WellSectionTypeDto> wellSectionRepository;
|
||||
|
||||
protected readonly IRepositoryWellRelated<T> repository;
|
||||
protected readonly IProcessMapPlanRepository<T> repository;
|
||||
|
||||
protected ProcessMapBaseController(IWellService wellService,
|
||||
IProcessMapPlanRepository<T> repository,
|
||||
IUserRepository userRepository,
|
||||
ICrudRepository<WellSectionTypeDto> wellSectionRepository)
|
||||
ICrudRepository<WellSectionTypeDto> wellSectionRepository,
|
||||
IHubContext<TelemetryHub> telemetryHubContext,
|
||||
ITelemetryService telemetryService)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
this.repository = repository;
|
||||
this.userRepository = userRepository;
|
||||
this.wellSectionRepository = wellSectionRepository;
|
||||
this.telemetryHubContext = telemetryHubContext;
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание РТК
|
||||
/// Создание плановой РТК
|
||||
/// </summary>
|
||||
/// <param name="processMap">Тело запроса</param>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
@ -73,11 +85,13 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
|
||||
var result = await repository.InsertAsync(processMap, cancellationToken);
|
||||
|
||||
await NotifyUsersBySignalR(idWell, cancellationToken);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление РТК
|
||||
/// Обновление плановой РТК
|
||||
/// </summary>
|
||||
/// <param name="processMap">Тело запроса</param>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
@ -101,11 +115,13 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
if (result == ICrudRepository<T>.ErrorIdNotFound)
|
||||
return this.ValidationBadRequest(nameof(processMap.Id), $"РТК с Id: {processMap.Id} не существует");
|
||||
|
||||
await NotifyUsersBySignalR(idWell, cancellationToken);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление РТК
|
||||
/// Удаление плановой РТК
|
||||
/// </summary>
|
||||
/// <param name="id">Id удаляемой РТК</param>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
@ -113,13 +129,14 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public virtual async Task<IActionResult> DeleteAsync(int id, int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken);
|
||||
|
||||
var result = await repository.DeleteAsync(id, cancellationToken);
|
||||
|
||||
await NotifyUsersBySignalR(idWell, cancellationToken);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -130,7 +147,7 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
var processMaps = await repository.GetByIdWellAsync(idWell, cancellationToken);
|
||||
@ -138,6 +155,32 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
return Ok(processMaps);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение РТК по телеметрии
|
||||
/// </summary>
|
||||
/// <param name="uid">Уникальный ключ телеметрии</param>
|
||||
/// <param name="updateFrom">Дата с которой требуется получить РТК</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/api/[controller]/telemetry/{uid}")]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> 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)
|
||||
@ -153,6 +196,15 @@ public abstract class ProcessMapBaseController<T> : ControllerBase
|
||||
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)
|
||||
{
|
||||
var wellSection = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken);
|
||||
|
@ -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<ProcessMapPlanWellDrillingDto>
|
||||
{
|
||||
private readonly IHubContext<TelemetryHub> 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<ProcessMapPlanWellDrillingDto> repository,
|
||||
IUserRepository userRepository,
|
||||
IProcessMapReportWellDrillingExportService processMapReportWellDrillingExportService,
|
||||
IProcessMapPlanImportService processMapPlanImportService,
|
||||
IProcessMapReportWellDrillingService processMapReportWellDrillingService,
|
||||
ICrudRepository<WellSectionTypeDto> wellSectionRepository,
|
||||
IHubContext<TelemetryHub> telemetryHubContext,
|
||||
IProcessMapReportExportService wellDrillingProcessMapReportExportService,
|
||||
IProcessMapImportService wellDrillingProcessMapImportService,
|
||||
IProcessMapReportWellDrillingService wellDrillingProcessMapReportService,
|
||||
ICrudRepository<WellSectionTypeDto> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание РТК
|
||||
/// </summary>
|
||||
/// <param name="processMap">Тело запроса</param>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IActionResult> InsertAsync(ProcessMapPlanWellDrillingDto processMap, int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await base.InsertAsync(processMap, idWell, cancellationToken);
|
||||
|
||||
await NotifyUsersBySignalR(idWell, cancellationToken);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновление РТК
|
||||
/// </summary>
|
||||
/// <param name="processMap">Тело запроса</param>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IActionResult> UpdateAsync(ProcessMapPlanWellDrillingDto processMap, int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await base.UpdateAsync(processMap, idWell, cancellationToken);
|
||||
|
||||
await NotifyUsersBySignalR(idWell, cancellationToken);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление РТК
|
||||
/// </summary>
|
||||
/// <param name="id">Id удаляемой РТК</param>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IActionResult> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -98,7 +49,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController<Process
|
||||
[ProducesResponseType(typeof(ProcessMapPlanWellDrillingDto), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> 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<Process
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public async Task<IActionResult> 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<Process
|
||||
|
||||
try
|
||||
{
|
||||
await wellDrillingProcessMapImportService.ImportAsync(idWell,
|
||||
await processMapPlanImportService.ImportAsync(idWell,
|
||||
IdUser,
|
||||
(options & 1) > 0,
|
||||
stream,
|
||||
@ -173,7 +124,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController<Process
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> 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<Process
|
||||
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
}
|
@ -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<ProcessMapP
|
||||
public ProcessMapWellReamController(IWellService wellService,
|
||||
IProcessMapPlanRepository<ProcessMapPlanWellReamDto> repository,
|
||||
IUserRepository userRepository,
|
||||
ICrudRepository<WellSectionTypeDto> wellSectionRepository)
|
||||
: base(wellService, repository, userRepository, wellSectionRepository)
|
||||
ICrudRepository<WellSectionTypeDto> wellSectionRepository,
|
||||
IHubContext<TelemetryHub> telemetryHubContext,
|
||||
ITelemetryService telemetryService)
|
||||
: base(wellService, repository, userRepository, wellSectionRepository, telemetryHubContext, telemetryService)
|
||||
{
|
||||
}
|
||||
|
||||
public override string SignalRMethod => "ProccessMapWellReam";
|
||||
}
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Данные РТК для SAUB
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TelemetryProcessMapController : ControllerBase
|
||||
{
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository;
|
||||
private readonly IProcessMapPlanRepository<ProcessMapPlanWellReamDto> processMapPlanWellReamRepository;
|
||||
|
||||
public TelemetryProcessMapController(ITelemetryService telemetryService,
|
||||
IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository,
|
||||
IProcessMapPlanRepository<ProcessMapPlanWellReamDto> processMapPlanWellReamRepository)
|
||||
{
|
||||
this.telemetryService = telemetryService;
|
||||
this.processMapPlanWellDrillingRepository = processMapPlanWellDrillingRepository;
|
||||
this.processMapPlanWellReamRepository = processMapPlanWellReamRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение РТК бурение по Uid телеметрии
|
||||
/// </summary>
|
||||
/// <param name="uid">Уникальный Id телеметрии</param>
|
||||
/// <param name="updateFrom">Дата с которой требуется получить РТК</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("processMapPlanWellDrilling")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanWellDrillingDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение РТК проработки по Uid телеметрии
|
||||
/// </summary>
|
||||
/// <param name="uid">Уникальный Id телеметрии</param>
|
||||
/// <param name="updateFrom">Дата с которой требуется получить РТК</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("processMapPlanWellReam")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanWellReamDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user