Правки по результатам ревью

This commit is contained in:
Olga Nemt 2024-06-05 12:08:38 +05:00
parent 46271f2bc2
commit 9322d2874b
20 changed files with 93 additions and 117 deletions

View File

@ -2,7 +2,6 @@
using AsbCloudApp.Requests;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -11,7 +10,7 @@ namespace AsbCloudApp.Repositories;
/// <summary>
/// Репозиторий для записей с историей
/// </summary>
public interface IChangeLogRepository<TEntity, TDto, TRequest>
public interface IChangeLogRepository<TDto, TRequest>
where TDto : IId
{
/// <summary>

View File

@ -86,4 +86,10 @@ public abstract class ChangeLogAbstract
/// </summary>
[Column("id_previous"), Comment("ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная")]
public int? IdPrevious { get; set; }
[ForeignKey(nameof(IdAuthor))]
public virtual User Author { get; set; } = null!;
[ForeignKey(nameof(IdEditor))]
public virtual User? Editor { get; set; }
}

View File

@ -20,12 +20,6 @@ public abstract class ProcessMapPlanBase : ChangeLogAbstract, IId, IWellRelated
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; } = null!;
[ForeignKey(nameof(IdAuthor))]
public virtual User Author { get; set; } = null!;
[ForeignKey(nameof(IdEditor))]
public virtual User? Editor { get; set; }
[ForeignKey(nameof(IdWellSectionType))]
public virtual WellSectionType WellSectionType { get; set; } = null!;
}

View File

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

View File

@ -3,12 +3,9 @@ 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;
@ -17,7 +14,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository;
public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : IChangeLogRepository<TEntity, TDto, TRequest>
public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : IChangeLogRepository<TDto, TRequest>
where TDto : AsbCloudApp.Data.IId
where TEntity : ChangeLogAbstract
{
@ -38,7 +35,9 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
ChangeLogRequest request)
{
this.Repository = repository;
this.Query = repository.db.Set<TEntity>();
this.Query = repository.db.Set<TEntity>()
.Include(e => e.Author)
.Include(e => e.Editor);
if (request.Moment.HasValue)
{
@ -323,7 +322,12 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
protected abstract TimeSpan GetTimezoneOffset(TRequest request);
protected abstract IQueryable<TEntity> BuildQuery(TRequest request, IQueryable<TEntity>? query = null);
private IQueryable<TEntity> BuildQuery(TRequest request) =>
BuildQuery(request, db.Set<TEntity>()
.Include(e => e.Author)
.Include(e => e.Editor));
protected abstract IQueryable<TEntity> BuildQuery(TRequest request, IQueryable<TEntity> query);
protected virtual TEntity Convert(TDto dto)
{

View File

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

View File

@ -21,15 +21,9 @@ public class ProcessMapPlanBaseRepository<TEntity, TDto> : ChangeLogRepositoryAb
this.wellService = wellService;
}
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request, IQueryable<TEntity>? query = null)
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request, IQueryable<TEntity> query)
{
if(query is null)
{
query = db.Set<TEntity>();
}
query = query.Include(e => e.Author)
.Include(e => e.Editor)
query = query
.Include(e => e.Well)
.Include(e => e.WellSectionType)
.Where(e => e.IdWell == request.IdWell);
@ -60,8 +54,6 @@ public class ProcessMapPlanBaseRepository<TEntity, TDto> : ChangeLogRepositoryAb
protected override TEntity Convert(TDto dto)
{
var entity = base.Convert(dto);
//entity.Author = null;
//entity.Editor = null;
return entity;
}
}

View File

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

View File

@ -43,10 +43,6 @@ 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,16 +8,15 @@ 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<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto>
public class ProcessMapPlanDrillingExportService : ProcessMapPlanExportService<ProcessMapPlanDrillingDto>
{
public ProcessMapPlanDrillingExportService(
IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
: base(processMapPlanRepository, wellService)
{

View File

@ -1,25 +1,23 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public abstract class ProcessMapPlanExportService<TEntity, TDto> : ExportExcelService<TDto, WellRelatedExportRequest>
public abstract class ProcessMapPlanExportService<TDto> : ExportExcelService<TDto, WellRelatedExportRequest>
where TDto : ProcessMapPlanBaseDto
{
protected readonly IWellService wellService;
private readonly IChangeLogRepository<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository;
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository;
protected ProcessMapPlanExportService(IChangeLogRepository<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
protected ProcessMapPlanExportService(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
{
this.processMapPlanRepository = processMapPlanRepository;

View File

@ -1,22 +1,21 @@
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
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;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanReamExportService : ProcessMapPlanExportService<ProcessMapPlanReam, ProcessMapPlanReamDto>
public class ProcessMapPlanReamExportService : ProcessMapPlanExportService<ProcessMapPlanReamDto>
{
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate();
public ProcessMapPlanReamExportService(
IChangeLogRepository<ProcessMapPlanReam, ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
: base(processMapPlanRepository, wellService)
{

View File

@ -1,6 +1,7 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.ProcessMaps.Report;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Extensions;
using AsbCloudApp.Repositories;
@ -13,21 +14,19 @@ using System.Collections.Generic;
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<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository;
private readonly IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository;
private readonly IDataSaubStatRepository dataSaubStatRepository;
private readonly IWellOperationRepository wellOperationRepository;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
public ProcessMapReportDrillingService(IWellService wellService,
IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository,
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository,
IDataSaubStatRepository dataSaubStatRepository,
IWellOperationRepository wellOperationRepository,
IWellOperationCategoryRepository wellOperationCategoryRepository

View File

@ -7,7 +7,6 @@ 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;
@ -33,7 +32,7 @@ public class WellInfoService
{
var wellService = services.GetRequiredService<IWellService>();
var operationsStatService = services.GetRequiredService<IOperationsStatService>();
var processMapPlanWellDrillingRepository = services.GetRequiredService<IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
var processMapPlanWellDrillingRepository = services.GetRequiredService<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
var subsystemService = services.GetRequiredService<ISubsystemService>();
var telemetryDataSaubCache = services.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();
var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();

View File

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

View File

@ -5,7 +5,6 @@ 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;
@ -24,8 +23,8 @@ public class ProcessMapReportDataSaubStatServiceTest
private IWellService wellService
= Substitute.For<IWellService>();
private IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
= Substitute.For<IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
private IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
= Substitute.For<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
private IWellOperationRepository wellOperationRepository
= Substitute.For<IWellOperationRepository>();

View File

@ -9,10 +9,8 @@ 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;
@ -34,13 +32,13 @@ public abstract class ProcessMapPlanBaseController<TEntity, TDto> : ControllerBa
where TEntity : ProcessMapPlanBase
where TDto : ProcessMapPlanBaseDto
{
private readonly IChangeLogRepository<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> repository;
private readonly IChangeLogRepository<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<TEntity, TDto, ProcessMapPlanBaseRequestWithWell> repository,
protected ProcessMapPlanBaseController(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
IParserService<TDto, WellRelatedParserRequest> parserService,
IExportService<WellRelatedExportRequest> processMapPlanExportService,

View File

@ -13,7 +13,7 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
/// </summary>
public class ProcessMapPlanDrillingController : ProcessMapPlanBaseController<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto>
{
public ProcessMapPlanDrillingController(IChangeLogRepository<ProcessMapPlanDrilling, ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> repository,
public ProcessMapPlanDrillingController(IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ProcessMapPlanDrillingParser parserService,
ITelemetryService telemetryService,

View File

@ -13,7 +13,7 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
/// </summary>
public class ProcessMapPlanReamController : ProcessMapPlanBaseController<ProcessMapPlanReam, ProcessMapPlanReamDto>
{
public ProcessMapPlanReamController(IChangeLogRepository<ProcessMapPlanReam, ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> repository,
public ProcessMapPlanReamController(IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ProcessMapPlanReamParser parserService,
ITelemetryService telemetryService,

View File

@ -79,7 +79,7 @@ namespace AsbCloudWebApi.Controllers
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = wellCompositeRepository.GetCompositeProcessMap(idWell, token);
var result = await wellCompositeRepository.GetCompositeProcessMap(idWell, token).ConfigureAwait(false);
return Ok(result);
}