Правки по результатам ревью + создание ChangeLogReposiroryBuilder для разделения запросов к данным и к истории изменений

This commit is contained in:
Olga Nemt 2024-06-04 16:55:44 +05:00
parent 459fc3acb8
commit 46271f2bc2
20 changed files with 202 additions and 90 deletions

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,7 +11,7 @@ namespace AsbCloudApp.Repositories;
/// <summary> /// <summary>
/// Репозиторий для записей с историей /// Репозиторий для записей с историей
/// </summary> /// </summary>
public interface IChangeLogRepository<TDto, TRequest> public interface IChangeLogRepository<TEntity, TDto, TRequest>
where TDto : IId where TDto : IId
{ {
/// <summary> /// <summary>
@ -93,12 +94,11 @@ public interface IChangeLogRepository<TDto, TRequest>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token); Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token);
/// <summary> /// <summary>
/// Получение измененных записей за определенный момент времени /// Получение объекта, реализующего интерфейс IChangeLogRepositoryBuilder
/// для последующих вызовов методов фильтрации по запросам
/// </summary> /// </summary>
/// <param name="changeLogRequest">фильтр по changeLog</param>
/// <param name="dataRequest">фильтр по данным внутри changeLog</param>
/// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogByMoment(ChangeLogRequest changeLogRequest, TRequest dataRequest, CancellationToken token); IChangeLogRepositoryBuilder<TDto, TRequest> GetRequestBuilder(ChangeLogRequest request);
} }

View File

@ -0,0 +1,40 @@
using AsbCloudApp.Data;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories;
/// <summary>
/// Интерфейс для работы с объектами, содержащими историю изменений
/// </summary>
/// <typeparam name="TDto"></typeparam>
/// <typeparam name="TRequest"></typeparam>
public interface IChangeLogRepositoryBuilder<TDto, TRequest>
where TDto : IId
{
/// <summary>
/// Применение запроса
/// </summary>
/// <param name="request">Запрос</param>
/// <param name="token"></param>
/// <returns></returns>
IChangeLogRepositoryBuilder<TDto, TRequest> ApplyRequest(TRequest request, CancellationToken token);
/// <summary>
/// Материализация записей
/// </summary>
/// <param name="offset"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TDto>> GetData(TimeSpan offset, CancellationToken token);
/// <summary>
/// Материализация записей с историей
/// </summary>
/// <param name="offset"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogData(TimeSpan offset, CancellationToken token);
}

View File

@ -5,7 +5,7 @@ namespace AsbCloudApp.Requests;
/// <summary> /// <summary>
/// Запрос для получения РТК план /// Запрос для получения РТК план
/// </summary> /// </summary>
public class ProcessMapPlanBaseRequest : ChangeLogRequest public class ProcessMapPlanBaseRequest
{ {
/// <summary> /// <summary>
/// Вернуть данные, которые поменялись с указанной даты /// Вернуть данные, которые поменялись с указанной даты
@ -24,7 +24,7 @@ public class ProcessMapPlanBaseRequest : ChangeLogRequest
/// Копирующий конструктор /// Копирующий конструктор
/// </summary> /// </summary>
/// <param name="request">Параметры запроса</param> /// <param name="request">Параметры запроса</param>
public ProcessMapPlanBaseRequest(ProcessMapPlanBaseRequest request) : base(request) public ProcessMapPlanBaseRequest(ProcessMapPlanBaseRequest request)
{ {
UpdateFrom = request.UpdateFrom; UpdateFrom = request.UpdateFrom;
} }

View File

@ -196,12 +196,12 @@ namespace AsbCloudInfrastructure
services.AddTransient<IDataSaubStatRepository, DataSaubStatRepository>(); services.AddTransient<IDataSaubStatRepository, DataSaubStatRepository>();
services.AddTransient< services.AddTransient<
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>, IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>,
ProcessMapPlanBaseRepository<ProcessMapPlanDrillingDto, ProcessMapPlanDrilling>>(); ProcessMapPlanBaseRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto>>();
services.AddTransient< services.AddTransient<
IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell>, IChangeLogRepository<ProcessMapPlanReam, ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell>,
ProcessMapPlanBaseRepository<ProcessMapPlanReamDto, ProcessMapPlanReam>>(); ProcessMapPlanBaseRepository<ProcessMapPlanReam, ProcessMapPlanReamDto>>();
services.AddTransient<IProcessMapReportDrillingService, ProcessMapReportDrillingService>(); services.AddTransient<IProcessMapReportDrillingService, ProcessMapReportDrillingService>();

View File

@ -3,9 +3,12 @@ using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using iText.Signatures;
using iText.StyledXmlParser.Jsoup.Nodes;
using Mapster; using Mapster;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Npgsql; using Npgsql;
using Org.BouncyCastle.Asn1.Ocsp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -14,10 +17,9 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository; namespace AsbCloudInfrastructure.Repository;
public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : IChangeLogRepository<TDto, TRequest> public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : IChangeLogRepository<TEntity, TDto, TRequest>
where TDto : AsbCloudApp.Data.IId where TDto : AsbCloudApp.Data.IId
where TEntity : ChangeLogAbstract where TEntity : ChangeLogAbstract
where TRequest : ChangeLogRequest
{ {
protected readonly IAsbCloudDbContext db; protected readonly IAsbCloudDbContext db;
@ -26,6 +28,57 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
this.db = db; this.db = db;
} }
private class ChangeLogRepositoryBuilder<TEntityChangeLog, TDtoChangeLog, TRequestChangeLog> : IChangeLogRepositoryBuilder<TDto, TRequest>
{
private readonly ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> Repository;
private IQueryable<TEntity> Query;
public ChangeLogRepositoryBuilder(
ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> repository,
ChangeLogRequest request)
{
this.Repository = repository;
this.Query = repository.db.Set<TEntity>();
if (request.Moment.HasValue)
{
var momentUtc = request.Moment.Value.ToUniversalTime();
this.Query = this.Query
.Where(e => e.Creation <= momentUtc)
.Where(e => e.Obsolete == null || e.Obsolete >= momentUtc);
}
}
public IChangeLogRepositoryBuilder<TDto, TRequest> ApplyRequest(TRequest request, CancellationToken token)
{
this.Query = Repository.BuildQuery(request, Query);
return this;
}
public async Task<IEnumerable<TDto>> GetData(TimeSpan offset, CancellationToken token)
{
var dtos = await this.Query.Select(e => Repository.Convert(e, offset))
.ToArrayAsync(token);
return dtos;
}
public async Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogData(TimeSpan offset, CancellationToken token)
{
var dtos = await this.Query.Select(e => Repository.ConvertChangeLogDto(e, offset))
.ToArrayAsync(token);
return dtos;
}
}
public IChangeLogRepositoryBuilder<TDto, TRequest> GetRequestBuilder(ChangeLogRequest request)
{
var builder = new ChangeLogRepositoryBuilder<TEntity, TDto, TRequest>(this, request);
return builder;
}
public async Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token) public async Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{ {
var result = 0; var result = 0;
@ -134,6 +187,7 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
public async Task<int> Clear(int idUser, TRequest request, CancellationToken token) public async Task<int> Clear(int idUser, TRequest request, CancellationToken token)
{ {
var updateTime = DateTimeOffset.UtcNow; var updateTime = DateTimeOffset.UtcNow;
var query = BuildQuery(request); var query = BuildQuery(request);
query = query.Where(e => e.Obsolete == null); query = query.Where(e => e.Obsolete == null);
@ -239,7 +293,7 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
return dtos; return dtos;
} }
private async Task<IEnumerable<ChangeLogDto<TDto>>> CreateChangeLogDto(IQueryable<TEntity> query, TimeSpan offset, CancellationToken token) public async Task<IEnumerable<ChangeLogDto<TDto>>> CreateChangeLogDto(IQueryable<TEntity> query, TimeSpan offset, CancellationToken token)
{ {
var entities = await query var entities = await query
.OrderBy(e => e.Creation) .OrderBy(e => e.Creation)
@ -251,37 +305,25 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
return dtos; return dtos;
} }
public async Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogByMoment(ChangeLogRequest changeLogRequest, TRequest dataRequest, CancellationToken token)
{
var query = BuildQuery(dataRequest);
if (changeLogRequest.Moment.HasValue)
{
var momentUtc = changeLogRequest.Moment.Value.ToUniversalTime();
query = query
.Where(e => e.Creation <= momentUtc)
.Where(e => e.Obsolete == null || e.Obsolete >= momentUtc);
}
TimeSpan offset = GetTimezoneOffset(dataRequest);
var dtos = await CreateChangeLogDto(query, offset, token);
return dtos;
}
public async Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token) public async Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token)
{ {
var changeLogRequest = new ChangeLogRequest() var changeLogRequest = new ChangeLogRequest()
{ {
Moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero) Moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero)
}; };
var entities = await GetChangeLogByMoment(changeLogRequest, request, token);
var result = entities.Select(e => e.Item); var builder = new ChangeLogRepositoryBuilder<TEntity, TDto, TRequest>(this, changeLogRequest);
return result; builder.ApplyRequest(request, token);
var offset = GetTimezoneOffset(request);
var dtos = await builder.GetData(offset, token);
return dtos;
} }
protected abstract TimeSpan GetTimezoneOffset(TRequest request); protected abstract TimeSpan GetTimezoneOffset(TRequest request);
protected abstract IQueryable<TEntity> BuildQuery(TRequest request); protected abstract IQueryable<TEntity> BuildQuery(TRequest request, IQueryable<TEntity>? query = null);
protected virtual TEntity Convert(TDto dto) protected virtual TEntity Convert(TDto dto)
{ {
@ -332,4 +374,5 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
if (pgException.SqlState == PostgresErrorCodes.ForeignKeyViolation) if (pgException.SqlState == PostgresErrorCodes.ForeignKeyViolation)
throw new ArgumentInvalidException("dtos", pgException.Message + "\r\n" + pgException.Detail); throw new ArgumentInvalidException("dtos", pgException.Message + "\r\n" + pgException.Detail);
} }
} }

View File

@ -0,0 +1,5 @@
namespace AsbCloudInfrastructure.Repository;
internal interface IChangeLogReposiroryBuilder
{
}

View File

@ -9,7 +9,7 @@ using System.Linq;
namespace AsbCloudInfrastructure.Repository; namespace AsbCloudInfrastructure.Repository;
public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAbstract<TDto, TEntity, ProcessMapPlanBaseRequestWithWell> public class ProcessMapPlanBaseRepository<TEntity, TDto> : ChangeLogRepositoryAbstract<TEntity, TDto, ProcessMapPlanBaseRequestWithWell>
where TDto : ProcessMapPlanBaseDto where TDto : ProcessMapPlanBaseDto
where TEntity : ProcessMapPlanBase where TEntity : ProcessMapPlanBase
{ {
@ -21,11 +21,14 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
this.wellService = wellService; this.wellService = wellService;
} }
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request) protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request, IQueryable<TEntity>? query = null)
{ {
var query = db if(query is null)
.Set<TEntity>() {
.Include(e => e.Author) query = db.Set<TEntity>();
}
query = query.Include(e => e.Author)
.Include(e => e.Editor) .Include(e => e.Editor)
.Include(e => e.Well) .Include(e => e.Well)
.Include(e => e.WellSectionType) .Include(e => e.WellSectionType)
@ -37,8 +40,6 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
query = query.Where(e => e.Creation >= from || e.Obsolete >= from); query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
} }
return query; return query;
} }

View File

@ -3,6 +3,7 @@ using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using AsbCloudDb.Model.ProcessMaps;
using Mapster; using Mapster;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
@ -16,11 +17,11 @@ namespace AsbCloudInfrastructure.Repository;
public class WellCompositeRepository : IWellCompositeRepository public class WellCompositeRepository : IWellCompositeRepository
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository; private readonly IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository;
public WellCompositeRepository( public WellCompositeRepository(
IAsbCloudDbContext db, IAsbCloudDbContext db,
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository) IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanDrillingRepository)
{ {
this.db = db; this.db = db;
this.processMapPlanDrillingRepository = processMapPlanDrillingRepository; this.processMapPlanDrillingRepository = processMapPlanDrillingRepository;

View File

@ -43,6 +43,10 @@ public class WorkOperationDetection: Work
var telemetryId = telemetryIds[i]; var telemetryId = telemetryIds[i];
var beginDate = lastDetectedDates.TryGetValue(telemetryId, out var date) ? date : (DateTimeOffset?)null; var beginDate = lastDetectedDates.TryGetValue(telemetryId, out var date) ? date : (DateTimeOffset?)null;
if(telemetryId == 939)
{
;
}
onProgressCallback($"Start detecting telemetry: {telemetryId} from {beginDate}", i / telemetryIds.Length); onProgressCallback($"Start detecting telemetry: {telemetryId} from {beginDate}", i / telemetryIds.Length);
var detectedOperations = await detectedOperationService.DetectOperationsAsync(telemetryId, beginDate, token); var detectedOperations = await detectedOperationService.DetectOperationsAsync(telemetryId, beginDate, token);

View File

@ -8,15 +8,16 @@ using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions; using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ExcelServices.Templates; using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates; using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export; namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanDrillingExportService : ProcessMapPlanExportService<ProcessMapPlanDrillingDto> public class ProcessMapPlanDrillingExportService : ProcessMapPlanExportService<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto>
{ {
public ProcessMapPlanDrillingExportService( public ProcessMapPlanDrillingExportService(
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository, IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService) IWellService wellService)
: base(processMapPlanRepository, wellService) : base(processMapPlanRepository, wellService)
{ {

View File

@ -12,14 +12,14 @@ using AsbCloudInfrastructure.Services.ExcelServices;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export; namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public abstract class ProcessMapPlanExportService<TDto> : ExportExcelService<TDto, WellRelatedExportRequest> public abstract class ProcessMapPlanExportService<TEntity, TDto> : ExportExcelService<TDto, WellRelatedExportRequest>
where TDto : ProcessMapPlanBaseDto where TDto : ProcessMapPlanBaseDto
{ {
protected readonly IWellService wellService; protected readonly IWellService wellService;
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository; private readonly IChangeLogRepository<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository;
protected ProcessMapPlanExportService(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository, protected ProcessMapPlanExportService(IChangeLogRepository<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService) IWellService wellService)
{ {
this.processMapPlanRepository = processMapPlanRepository; this.processMapPlanRepository = processMapPlanRepository;
@ -28,10 +28,7 @@ public abstract class ProcessMapPlanExportService<TDto> : ExportExcelService<TDt
protected override async Task<IEnumerable<TDto>> GetDtosAsync(WellRelatedExportRequest options, CancellationToken token) protected override async Task<IEnumerable<TDto>> GetDtosAsync(WellRelatedExportRequest options, CancellationToken token)
{ {
var request = new ProcessMapPlanBaseRequestWithWell(options.IdWell) var request = new ProcessMapPlanBaseRequestWithWell(options.IdWell);
{
Moment = DateTimeOffset.UtcNow
};
var dtos = await processMapPlanRepository.GetCurrent(request, token); var dtos = await processMapPlanRepository.GetCurrent(request, token);
return dtos; return dtos;

View File

@ -5,17 +5,18 @@ using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions; using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ExcelServices.Templates; using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates; using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export; namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanReamExportService : ProcessMapPlanExportService<ProcessMapPlanReamDto> public class ProcessMapPlanReamExportService : ProcessMapPlanExportService<ProcessMapPlanReam, ProcessMapPlanReamDto>
{ {
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate(); protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate();
public ProcessMapPlanReamExportService( public ProcessMapPlanReamExportService(
IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository, IChangeLogRepository<ProcessMapPlanReam, ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService) IWellService wellService)
: base(processMapPlanRepository, wellService) : base(processMapPlanRepository, wellService)
{ {

View File

@ -14,19 +14,20 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Data.WellOperation;
using AsbCloudDb.Model.ProcessMaps;
namespace AsbCloudInfrastructure.Services.ProcessMaps.Report; namespace AsbCloudInfrastructure.Services.ProcessMaps.Report;
public class ProcessMapReportDrillingService : IProcessMapReportDrillingService public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
{ {
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository; private readonly IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository;
private readonly IDataSaubStatRepository dataSaubStatRepository; private readonly IDataSaubStatRepository dataSaubStatRepository;
private readonly IWellOperationRepository wellOperationRepository; private readonly IWellOperationRepository wellOperationRepository;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository; private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
public ProcessMapReportDrillingService(IWellService wellService, public ProcessMapReportDrillingService(IWellService wellService,
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository, IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository,
IDataSaubStatRepository dataSaubStatRepository, IDataSaubStatRepository dataSaubStatRepository,
IWellOperationRepository wellOperationRepository, IWellOperationRepository wellOperationRepository,
IWellOperationCategoryRepository wellOperationCategoryRepository IWellOperationCategoryRepository wellOperationCategoryRepository

View File

@ -7,6 +7,7 @@ using AsbCloudApp.IntegrationEvents.Interfaces;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Background; using AsbCloudInfrastructure.Background;
using Mapster; using Mapster;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -32,7 +33,7 @@ public class WellInfoService
{ {
var wellService = services.GetRequiredService<IWellService>(); var wellService = services.GetRequiredService<IWellService>();
var operationsStatService = services.GetRequiredService<IOperationsStatService>(); var operationsStatService = services.GetRequiredService<IOperationsStatService>();
var processMapPlanWellDrillingRepository = services.GetRequiredService<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>(); var processMapPlanWellDrillingRepository = services.GetRequiredService<IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
var subsystemService = services.GetRequiredService<ISubsystemService>(); var subsystemService = services.GetRequiredService<ISubsystemService>();
var telemetryDataSaubCache = services.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>(); var telemetryDataSaubCache = services.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();
var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>(); var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();
@ -43,10 +44,7 @@ public class WellInfoService
var wellsIds = activeWells.Select(w => w.Id); var wellsIds = activeWells.Select(w => w.Id);
var processMapPlanWellDrillingRequests = wellsIds.Select(id => new ProcessMapPlanBaseRequestWithWell(id) var processMapPlanWellDrillingRequests = wellsIds.Select(id => new ProcessMapPlanBaseRequestWithWell(id));
{
Moment = DateTimeOffset.UtcNow.AddDays(1)
});
var processMapPlanWellDrillings = new List<ProcessMapPlanDrillingDto>(); var processMapPlanWellDrillings = new List<ProcessMapPlanDrillingDto>();
foreach (var processMapPlanWellDrillingRequest in processMapPlanWellDrillingRequests) foreach (var processMapPlanWellDrillingRequest in processMapPlanWellDrillingRequests)
{ {

View File

@ -30,11 +30,11 @@ namespace AsbCloudInfrastructure
var backgroundWorker = provider.GetRequiredService<PeriodicBackgroundWorker>(); var backgroundWorker = provider.GetRequiredService<PeriodicBackgroundWorker>();
backgroundWorker.Add<WorkToDeleteOldReports>(TimeSpan.FromDays(1)); backgroundWorker.Add<WorkToDeleteOldReports>(TimeSpan.FromDays(1));
backgroundWorker.Add<WellInfoService.WorkWellInfoUpdate>(TimeSpan.FromMinutes(30)); backgroundWorker.Add<WellInfoService.WorkWellInfoUpdate>(TimeSpan.FromMinutes(0));
backgroundWorker.Add<WorkOperationDetection>(TimeSpan.FromMinutes(15)); backgroundWorker.Add<WorkOperationDetection>(TimeSpan.FromMinutes(0));
backgroundWorker.Add<WorkDataSaubStat>(TimeSpan.FromMinutes(15)); backgroundWorker.Add<WorkDataSaubStat>(TimeSpan.FromMinutes(0));
backgroundWorker.Add<WorkLimitingParameterCalc>(TimeSpan.FromMinutes(30)); backgroundWorker.Add<WorkLimitingParameterCalc>(TimeSpan.FromMinutes(0));
backgroundWorker.Add(MakeMemoryMonitoringWork(), TimeSpan.FromMinutes(1)); backgroundWorker.Add(MakeMemoryMonitoringWork(), TimeSpan.FromMinutes(0));
var notificationBackgroundWorker = provider.GetRequiredService<NotificationBackgroundWorker>(); var notificationBackgroundWorker = provider.GetRequiredService<NotificationBackgroundWorker>();
} }

View File

@ -24,13 +24,13 @@ public interface IProcessMapPlanDrillingClient<TDto> where TDto : ProcessMapPlan
[Get(BaseRoute)] [Get(BaseRoute)]
Task<IApiResponse<IEnumerable<TDto>>> Get(int idWell); Task<IApiResponse<IEnumerable<TDto>>> Get(int idWell);
[Get($"{BaseRoute}/history")] [Get($"{BaseRoute}/changelogByMoment")]
Task<IApiResponse<IEnumerable<ChangeLogDto<TDto>>>> Get(int idWell, DateTimeOffset? moment); Task<IApiResponse<IEnumerable<ChangeLogDto<TDto>>>> Get(int idWell, DateTimeOffset? moment);
[Get("/api/telemetry/{uid}/ProcessMapPlanDrilling")] [Get("/api/telemetry/{uid}/ProcessMapPlanDrilling")]
Task<IApiResponse<IEnumerable<ChangeLogDto<TDto>>>> Get(string uid, DateTimeOffset? updateFrom); Task<IApiResponse<IEnumerable<ChangeLogDto<TDto>>>> Get(string uid, DateTimeOffset? updateFrom);
[Get($"{BaseRoute}/changeLog")] [Get($"{BaseRoute}/changeLogForDate")]
Task<IApiResponse<IEnumerable<TDto>>> GetChangeLog(int idWell, DateOnly? date); Task<IApiResponse<IEnumerable<TDto>>> GetChangeLog(int idWell, DateOnly? date);
[Get($"{BaseRoute}/dates")] [Get($"{BaseRoute}/dates")]

View File

@ -5,10 +5,12 @@ using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMaps.Report; using AsbCloudInfrastructure.Services.ProcessMaps.Report;
using NSubstitute; using NSubstitute;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xunit; using Xunit;
@ -22,8 +24,8 @@ public class ProcessMapReportDataSaubStatServiceTest
private IWellService wellService private IWellService wellService
= Substitute.For<IWellService>(); = Substitute.For<IWellService>();
private IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository private IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
= Substitute.For<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>(); = Substitute.For<IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
private IWellOperationRepository wellOperationRepository private IWellOperationRepository wellOperationRepository
= Substitute.For<IWellOperationRepository>(); = Substitute.For<IWellOperationRepository>();
@ -131,6 +133,12 @@ public class ProcessMapReportDataSaubStatServiceTest
Comment = "s", Comment = "s",
}, },
}; };
private readonly static IEnumerable<ChangeLogDto<ProcessMapPlanDrillingDto>> processMapPlanChangeLog = processMapPlan.Select(p => new ChangeLogDto<ProcessMapPlanDrillingDto>()
{
Item = p,
});
private readonly static IEnumerable<WellOperationDto> operations = new List<WellOperationDto>() private readonly static IEnumerable<WellOperationDto> operations = new List<WellOperationDto>()
{ {
new() new()
@ -257,6 +265,9 @@ public class ProcessMapReportDataSaubStatServiceTest
processMapPlanBaseRepository.GetCurrent(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), Arg.Any<CancellationToken>()) processMapPlanBaseRepository.GetCurrent(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), Arg.Any<CancellationToken>())
.Returns(processMapPlan); .Returns(processMapPlan);
processMapPlanBaseRepository.GetChangeLogForDate(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), null, Arg.Any<CancellationToken>())
.Returns(processMapPlanChangeLog);
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>()) wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(operations); .Returns(operations);

View File

@ -8,8 +8,11 @@ using AsbCloudApp.Requests.ParserOptions;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudApp.Services.Export; using AsbCloudApp.Services.Export;
using AsbCloudApp.Services.Parsers; using AsbCloudApp.Services.Parsers;
using AsbCloudDb.Model.ProcessMapPlan;
using DocumentFormat.OpenXml.Drawing;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -27,16 +30,17 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
[ApiController] [ApiController]
[Route("api/well/{idWell}/[controller]")] [Route("api/well/{idWell}/[controller]")]
[Authorize] [Authorize]
public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase public abstract class ProcessMapPlanBaseController<TEntity, TDto> : ControllerBase
where TEntity : ProcessMapPlanBase
where TDto : ProcessMapPlanBaseDto where TDto : ProcessMapPlanBaseDto
{ {
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository; private readonly IChangeLogRepository<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> repository;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IParserService<TDto, WellRelatedParserRequest> parserService; private readonly IParserService<TDto, WellRelatedParserRequest> parserService;
private readonly ITelemetryService telemetryService; private readonly ITelemetryService telemetryService;
private readonly IExportService<WellRelatedExportRequest> processMapPlanExportService; private readonly IExportService<WellRelatedExportRequest> processMapPlanExportService;
protected ProcessMapPlanBaseController(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository, protected ProcessMapPlanBaseController(IChangeLogRepository<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService, IWellService wellService,
IParserService<TDto, WellRelatedParserRequest> parserService, IParserService<TDto, WellRelatedParserRequest> parserService,
IExportService<WellRelatedExportRequest> processMapPlanExportService, IExportService<WellRelatedExportRequest> processMapPlanExportService,
@ -144,6 +148,7 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
await AssertUserHasAccessToWell(idWell, token); await AssertUserHasAccessToWell(idWell, token);
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell); var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
var result = await repository.GetCurrent(serviceRequest, token); var result = await repository.GetCurrent(serviceRequest, token);
return Ok(result); return Ok(result);
} }
@ -162,18 +167,20 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
{ {
await AssertUserHasAccessToWell(idWell, token); await AssertUserHasAccessToWell(idWell, token);
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell) var dataRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
{
Moment = moment,
};
var changeLogRequest = new ChangeLogRequest() var changeLogRequest = new ChangeLogRequest()
{ {
Moment = moment Moment = moment
}; };
var result = await repository.GetChangeLogByMoment(changeLogRequest, serviceRequest, token); var builder = repository.GetRequestBuilder(changeLogRequest);
return Ok(result); builder.ApplyRequest(dataRequest, token);
var offset = wellService.GetTimezone(idWell).Offset;
var dtos = await builder.GetChangeLogData(offset, token);
return Ok(dtos);
} }
/// <summary> /// <summary>

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export; using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser; using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
@ -10,9 +11,9 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
/// <summary> /// <summary>
/// РТК план бурения /// РТК план бурения
/// </summary> /// </summary>
public class ProcessMapPlanDrillingController : ProcessMapPlanBaseController<ProcessMapPlanDrillingDto> public class ProcessMapPlanDrillingController : ProcessMapPlanBaseController<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto>
{ {
public ProcessMapPlanDrillingController(IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> repository, public ProcessMapPlanDrillingController(IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService, IWellService wellService,
ProcessMapPlanDrillingParser parserService, ProcessMapPlanDrillingParser parserService,
ITelemetryService telemetryService, ITelemetryService telemetryService,

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export; using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser; using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
@ -10,9 +11,9 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
/// <summary> /// <summary>
/// РТК план проработка /// РТК план проработка
/// </summary> /// </summary>
public class ProcessMapPlanReamController : ProcessMapPlanBaseController<ProcessMapPlanReamDto> public class ProcessMapPlanReamController : ProcessMapPlanBaseController<ProcessMapPlanReam, ProcessMapPlanReamDto>
{ {
public ProcessMapPlanReamController(IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> repository, public ProcessMapPlanReamController(IChangeLogRepository<ProcessMapPlanReam, ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService, IWellService wellService,
ProcessMapPlanReamParser parserService, ProcessMapPlanReamParser parserService,
ITelemetryService telemetryService, ITelemetryService telemetryService,