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

View File

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

View File

@ -3,9 +3,12 @@ using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudDb.Model;
using iText.Signatures;
using iText.StyledXmlParser.Jsoup.Nodes;
using Mapster;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,10 +17,9 @@ using System.Threading.Tasks;
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 TEntity : ChangeLogAbstract
where TRequest : ChangeLogRequest
{
protected readonly IAsbCloudDbContext db;
@ -26,6 +28,57 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
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)
{
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)
{
var updateTime = DateTimeOffset.UtcNow;
var query = BuildQuery(request);
query = query.Where(e => e.Obsolete == null);
@ -239,7 +293,7 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
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
.OrderBy(e => e.Creation)
@ -251,37 +305,25 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
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)
{
var changeLogRequest = new ChangeLogRequest()
{
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);
return result;
var builder = new ChangeLogRepositoryBuilder<TEntity, TDto, TRequest>(this, changeLogRequest);
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 IQueryable<TEntity> BuildQuery(TRequest request);
protected abstract IQueryable<TEntity> BuildQuery(TRequest request, IQueryable<TEntity>? query = null);
protected virtual TEntity Convert(TDto dto)
{
@ -332,4 +374,5 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
if (pgException.SqlState == PostgresErrorCodes.ForeignKeyViolation)
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;
public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAbstract<TDto, TEntity, ProcessMapPlanBaseRequestWithWell>
public class ProcessMapPlanBaseRepository<TEntity, TDto> : ChangeLogRepositoryAbstract<TEntity, TDto, ProcessMapPlanBaseRequestWithWell>
where TDto : ProcessMapPlanBaseDto
where TEntity : ProcessMapPlanBase
{
@ -21,15 +21,18 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
this.wellService = wellService;
}
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request)
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request, IQueryable<TEntity>? query = null)
{
var query = db
.Set<TEntity>()
.Include(e => e.Author)
.Include(e => e.Editor)
.Include(e => e.Well)
.Include(e => e.WellSectionType)
.Where(e => e.IdWell == request.IdWell);
if(query is null)
{
query = db.Set<TEntity>();
}
query = query.Include(e => e.Author)
.Include(e => e.Editor)
.Include(e => e.Well)
.Include(e => e.WellSectionType)
.Where(e => e.IdWell == request.IdWell);
if (request.UpdateFrom.HasValue)
{
@ -37,8 +40,6 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
}
return query;
}

View File

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

View File

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

View File

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

View File

@ -12,14 +12,14 @@ using AsbCloudInfrastructure.Services.ExcelServices;
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
{
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)
{
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)
{
var request = new ProcessMapPlanBaseRequestWithWell(options.IdWell)
{
Moment = DateTimeOffset.UtcNow
};
var request = new ProcessMapPlanBaseRequestWithWell(options.IdWell);
var dtos = await processMapPlanRepository.GetCurrent(request, token);
return dtos;

View File

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

View File

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

View File

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

View File

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

View File

@ -24,13 +24,13 @@ public interface IProcessMapPlanDrillingClient<TDto> where TDto : ProcessMapPlan
[Get(BaseRoute)]
Task<IApiResponse<IEnumerable<TDto>>> Get(int idWell);
[Get($"{BaseRoute}/history")]
[Get($"{BaseRoute}/changelogByMoment")]
Task<IApiResponse<IEnumerable<ChangeLogDto<TDto>>>> Get(int idWell, DateTimeOffset? moment);
[Get("/api/telemetry/{uid}/ProcessMapPlanDrilling")]
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);
[Get($"{BaseRoute}/dates")]

View File

@ -5,10 +5,12 @@ using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMaps.Report;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
@ -22,8 +24,8 @@ public class ProcessMapReportDataSaubStatServiceTest
private IWellService wellService
= Substitute.For<IWellService>();
private IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
= Substitute.For<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
private IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
= Substitute.For<IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
private IWellOperationRepository wellOperationRepository
= Substitute.For<IWellOperationRepository>();
@ -131,6 +133,12 @@ public class ProcessMapReportDataSaubStatServiceTest
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>()
{
new()
@ -257,6 +265,9 @@ public class ProcessMapReportDataSaubStatServiceTest
processMapPlanBaseRepository.GetCurrent(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), Arg.Any<CancellationToken>())
.Returns(processMapPlan);
processMapPlanBaseRepository.GetChangeLogForDate(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), null, Arg.Any<CancellationToken>())
.Returns(processMapPlanChangeLog);
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(operations);

View File

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

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
@ -10,9 +11,9 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
/// <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,
ProcessMapPlanDrillingParser parserService,
ITelemetryService telemetryService,

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
@ -10,9 +11,9 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
/// <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,
ProcessMapPlanReamParser parserService,
ITelemetryService telemetryService,