Рефакторинг репозиториев

1. Сделан один общий репозиторий для РТК план
2. Переименованы поля
3. Добавил регитсрацию зависимостей
This commit is contained in:
Степанов Дмитрий 2023-10-12 15:21:41 +05:00
parent 888154dd31
commit ba94db08b0
13 changed files with 354 additions and 474 deletions

View File

@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
namespace AsbCloudApp.Repositories;
/// <summary>
/// РТК план
/// </summary>
public interface IProcessMapPlanRepository<TDto> : IRepositoryWellRelated<TDto>
where TDto : ProcessMapPlanBaseDto
{
/// <summary>
/// Получить РТК по коллекции параметров
/// </summary>
/// <param name="requests"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<TDto>> GetAsync(IEnumerable<ProcessMapPlanRequest> requests, CancellationToken cancellationToken);
/// <summary>
/// Удалить РТК по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<int> RemoveByWellAsync(int idWell, CancellationToken cancellationToken);
}

View File

@ -29,11 +29,11 @@ namespace AsbCloudApp.Repositories
Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token);
/// <summary>
/// Получение РТК бурение по композитной скважине
/// Получение РТК-план бурение по композитной скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<WellDrillingProcessMapDto>> GetCompositeProcessMap(int idWell, CancellationToken token);
Task<IEnumerable<ProcessMapPlanWellDrillingDto>> GetCompositeProcessMap(int idWell, CancellationToken token);
}
}

View File

@ -1,30 +0,0 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
namespace AsbCloudApp.Repositories;
/// <summary>
/// РТК бурение скважины
/// </summary>
public interface IWellDrillingProcessMapRepository : IRepositoryWellRelated<WellDrillingProcessMapDto>
{
/// <summary>
/// Получить РТК бурение по параметрам
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<WellDrillingProcessMapDto>> GetAsync(WellDrillingProcessMapRequest request, CancellationToken cancellationToken);
/// <summary>
/// Получить РТК бурение по коллекции параметров
/// </summary>
/// <param name="requests"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<WellDrillingProcessMapDto>> GetAsync(IEnumerable<WellDrillingProcessMapRequest> requests, CancellationToken cancellationToken);
}

View File

@ -1,22 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
namespace AsbCloudApp.Repositories;
/// <summary>
/// РТК проработки
/// </summary>
public interface IWellReamProcessMapRepository : IRepositoryWellRelated<WellReamProcessMapDto>
{
/// <summary>
/// Получить РТК проработки по параметрам
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<WellReamProcessMapDto>> GetAsync(WellReamProcessMapRequest request, CancellationToken cancellationToken);
}

View File

@ -3,9 +3,9 @@
namespace AsbCloudApp.Requests;
/// <summary>
/// Запрос для получения РТК бурение
/// Запрос для получения РТК план
/// </summary>
public class WellDrillingProcessMapRequest
public class ProcessMapPlanRequest
{
/// <summary>
/// Идентификатор скважины

View File

@ -1,19 +0,0 @@
using System;
namespace AsbCloudApp.Requests;
/// <summary>
/// Запрос для получения РТК проработки
/// </summary>
public class WellReamProcessMapRequest
{
/// <summary>
/// Идентификатор скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// Дата обновления
/// </summary>
public DateTime? UpdateFrom { get; set; }
}

View File

@ -21,14 +21,6 @@ namespace AsbCloudApp.Services
/// <returns>emptyList if nothing found</returns>
Task<IEnumerable<Tdto>> GetByIdWellAsync(int idWell, CancellationToken token);
/// <summary>
/// Удалить записи связанных со скважиной
/// </summary>
/// <param name="idWell"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<int> RemoveByWellAsync(int idWell, CancellationToken cancellationToken);
/// <summary>
/// Получение всех записей по нескольким скважинам
/// </summary>

View File

@ -1,41 +1,42 @@
using AsbCloudApp.Data;
using System;
using AsbCloudApp.Data;
using AsbCloudApp.Data.Manuals;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Data.Subsystems;
using AsbCloudApp.Data.WellOperationImport.Options;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudApp.Services.AutoGeneratedDailyReports;
using AsbCloudApp.Services.Notifications;
using AsbCloudApp.Services.ProcessMaps;
using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
using AsbCloudApp.Services.Subsystems;
using AsbCloudApp.Services.WellOperationImport;
using AsbCloudDb.Model;
using AsbCloudDb.Model.Manuals;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudDb.Model.Subsystems;
using AsbCloudInfrastructure.Background;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
using AsbCloudInfrastructure.Services.DailyReport;
using AsbCloudInfrastructure.Services.DetectOperations;
using AsbCloudInfrastructure.Services.DrillingProgram;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
using AsbCloudInfrastructure.Services.SAUB;
using AsbCloudInfrastructure.Services.Subsystems;
using AsbCloudInfrastructure.Services.Trajectory;
using AsbCloudInfrastructure.Services.WellOperationImport;
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
using AsbCloudInfrastructure.Services.WellOperationService;
using Mapster;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using AsbCloudApp.Data.Manuals;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Services.AutoGeneratedDailyReports;
using AsbCloudApp.Services.Notifications;
using AsbCloudDb.Model.Manuals;
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
using AsbCloudApp.Services.WellOperationImport;
using AsbCloudInfrastructure.Services.WellOperationImport;
using AsbCloudApp.Data.WellOperationImport.Options;
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
using AsbCloudApp.Services.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap;
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
namespace AsbCloudInfrastructure
{
@ -100,12 +101,53 @@ namespace AsbCloudInfrastructure
.ForType<NotificationDto, Notification>()
.Ignore(dst => dst.NotificationCategory,
dst => dst.User);
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<ProcessMapWellDrilling, ProcessMapPlanWellDrillingDto>()
.Map(dest => dest.AxialLoad, src => new PlanLimitDto
{
LimitMax = src.AxialLoadLimitMax,
Plan = src.AxialLoadPlan
})
.Map(dest => dest.Flow, src => new PlanLimitDto
{
LimitMax = src.FlowLimitMax,
Plan = src.FlowPlan
})
.Map(dest => dest.Pressure, src => new PlanLimitDto
{
LimitMax = src.PressureLimitMax,
Plan = src.PressurePlan
})
.Map(dest => dest.TopDriveSpeed, src => new PlanLimitDto
{
LimitMax = src.TopDriveSpeedLimitMax,
Plan = src.TopDriveSpeedPlan
})
.Map(dest => dest.TopDriveTorque, src => new PlanLimitDto
{
LimitMax = src.TopDriveTorqueLimitMax,
Plan = src.TopDriveTorquePlan
});
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType<ProcessMapPlanWellDrillingDto, ProcessMapWellDrilling>()
.Map(dest => dest.AxialLoadPlan, src => src.AxialLoad.Plan)
.Map(dest => dest.AxialLoadLimitMax, src => src.AxialLoad.LimitMax)
.Map(dest => dest.FlowPlan, src => src.Flow.Plan)
.Map(dest => dest.FlowLimitMax, src => src.Flow.LimitMax)
.Map(dest => dest.PressurePlan, src => src.Pressure.Plan)
.Map(dest => dest.PressureLimitMax, src => src.Pressure.LimitMax)
.Map(dest => dest.TopDriveSpeedPlan, src => src.TopDriveSpeed.Plan)
.Map(dest => dest.TopDriveSpeedLimitMax, src => src.TopDriveSpeed.LimitMax)
.Map(dest => dest.TopDriveTorquePlan, src => src.TopDriveTorque.Plan)
.Map(dest => dest.TopDriveTorqueLimitMax, src => src.TopDriveTorque.LimitMax);
}
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
MapsterSetup();
var connectionStringName = "DefaultConnection";
string connectionStringName = "DefaultConnection";
#if DEBUG
connectionStringName = "DebugConnection";
#endif
@ -125,8 +167,8 @@ namespace AsbCloudInfrastructure
services.AddSingleton<IReduceSamplingService>(provider => ReduceSamplingService.GetInstance(configuration));
services.AddTransient<IAuthService, AuthService>();
services.AddTransient<IWellDrillingProcessMapRepository, WellDrillingProcessMapRepository>();
services.AddTransient<IWellReamProcessMapRepository, WellReamProcessMapRepository>();
services.AddTransient<IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto>, ProcessMapPlanRepository<ProcessMapPlanWellDrillingDto, ProcessMapWellDrilling>>();
services.AddTransient<IProcessMapPlanRepository<ProcessMapPlanWellReamDto>, ProcessMapPlanRepository<ProcessMapPlanWellReamDto, ProcessMapWellReam>>();
services.AddTransient<IDepositRepository, DepositRepository>();
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
services.AddTransient<IEventService, EventService>();
@ -154,7 +196,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<IWellFinalDocumentsService, WellFinalDocumentsService>();
services.AddTransient<IFileCategoryService, FileCategoryService>();
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
services.AddTransient<IWellDrillingProcessMapReportService, WellDrillingProcessMapReportService>();
services.AddTransient<IProcessMapReportWellDrillingService, WellDrillingProcessMapReportService>();
services.AddTransient<IProcessMapImportService, WellDrillingProcessMapImportService>();
services.AddTransient<WellInfoService>();
services.AddTransient<IHelpPageService, HelpPageService>();

View File

@ -29,15 +29,6 @@ namespace AsbCloudInfrastructure.Repository
return dtos;
}
public Task<int> RemoveByWellAsync(int idWell, CancellationToken cancellationToken)
{
var query = GetQuery().Where(x => x.IdWell == idWell);
dbSet.RemoveRange(query);
return dbContext.SaveChangesAsync(cancellationToken);
}
public async Task<IEnumerable<TDto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
{
if (!idsWells.Any())

View File

@ -0,0 +1,72 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudDb.Model.ProcessMaps;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Repository;
public class ProcessMapPlanRepository<TDto, TEntity> : CrudWellRelatedRepositoryBase<TDto, TEntity>,
IProcessMapPlanRepository<TDto>
where TDto : ProcessMapPlanBaseDto
where TEntity : ProcessMapBase
{
private readonly IWellService wellService;
public ProcessMapPlanRepository(IAsbCloudDbContext context, IWellService wellService)
: base(context, dbSet =>
dbSet
.Include(p => p.WellSectionType)
.Include(p => p.Well))
{
this.wellService = wellService;
}
public async Task<IEnumerable<TDto>> GetAsync(IEnumerable<ProcessMapPlanRequest> requests, CancellationToken cancellationToken)
{
var entities = await BuildQuery(requests)
.ToArrayAsync(cancellationToken);
return entities.Select(Convert);
}
public Task<int> RemoveByWellAsync(int idWell, CancellationToken cancellationToken)
{
var query = GetQuery().Where(x => x.IdWell == idWell);
dbSet.RemoveRange(query);
return dbContext.SaveChangesAsync(cancellationToken);
}
private IQueryable<TEntity> BuildQuery(IEnumerable<ProcessMapPlanRequest> requests)
{
var query = GetQuery();
foreach (var request in requests)
{
query = query.Where(p => p.IdWell == request.IdWell);
if (request.IdWellSectionType is not null)
query = query.Where(p => p.IdWellSectionType == request.IdWellSectionType);
if (request.UpdateFrom is not null)
{
var timezone = wellService.GetTimezone(request.IdWell);
var updateFromUtc = request.UpdateFrom?.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(p => p.LastUpdate >= updateFromUtc);
}
}
return query.OrderBy(e => e.DepthStart)
.ThenBy(e => e.Id)
.AsNoTracking();
}
}

View File

@ -17,12 +17,12 @@ namespace AsbCloudInfrastructure.Repository
public class WellCompositeRepository : IWellCompositeRepository
{
private readonly IAsbCloudDbContext db;
private readonly IWellDrillingProcessMapRepository wellDrillingProcessMapRepository;
private readonly IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository;
public WellCompositeRepository(IAsbCloudDbContext db, IWellDrillingProcessMapRepository wellDrillingProcessMapRepository)
public WellCompositeRepository(IAsbCloudDbContext db, IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> processMapPlanWellDrillingRepository)
{
this.db = db;
this.wellDrillingProcessMapRepository = wellDrillingProcessMapRepository;
this.processMapPlanWellDrillingRepository = processMapPlanWellDrillingRepository;
}
/// <inheritdoc/>
@ -50,16 +50,16 @@ namespace AsbCloudInfrastructure.Repository
}
/// <inheritdoc/>
public async Task<IEnumerable<WellDrillingProcessMapDto>> GetCompositeProcessMap(int idWell, CancellationToken token)
public async Task<IEnumerable<ProcessMapPlanWellDrillingDto>> GetCompositeProcessMap(int idWell, CancellationToken token)
{
var dtos = await GetAsync(idWell, token);
var requests = dtos.Select(x => new WellDrillingProcessMapRequest {
var requests = dtos.Select(x => new ProcessMapPlanRequest {
IdWell = x.IdWellSrc,
IdWellSectionType = x.IdWellSectionType
});
var result = await wellDrillingProcessMapRepository.GetAsync(requests, token);
var result = await processMapPlanWellDrillingRepository.GetAsync(requests, token);
return result;
}

View File

@ -1,129 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudDb.Model.ProcessMaps;
using Mapster;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Repository;
public class WellDrillingProcessMapRepository : CrudWellRelatedRepositoryBase<WellDrillingProcessMapDto, WellDrillingProcessMap>,
IWellDrillingProcessMapRepository
{
private readonly IWellService wellService;
public WellDrillingProcessMapRepository(IAsbCloudDbContext context, IWellService wellService)
: base(context, dbSet =>
dbSet
.Include(p => p.WellSectionType)
.Include(p => p.Well))
{
this.wellService = wellService;
}
public async Task<IEnumerable<WellDrillingProcessMapDto>> GetAsync(WellDrillingProcessMapRequest request,
CancellationToken cancellationToken)
{
var requests = new[] { request };
var entities = await BuildQuery(requests)
.ToArrayAsync(cancellationToken);
return entities.Select(Convert);
}
public async Task<IEnumerable<WellDrillingProcessMapDto>> GetAsync(
IEnumerable<WellDrillingProcessMapRequest> requests,
CancellationToken cancellationToken)
{
var entities = await BuildQuery(requests)
.ToArrayAsync(cancellationToken);
return entities.Select(Convert);
}
private IQueryable<WellDrillingProcessMap> BuildQuery(IEnumerable<WellDrillingProcessMapRequest> requests)
{
var query = GetQuery();
foreach (var request in requests)
{
query = query.Where(p => p.IdWell == request.IdWell);
if (request.IdWellSectionType is not null)
query = query.Where(p => p.IdWellSectionType == request.IdWellSectionType);
if (request.UpdateFrom is not null)
{
var timezone = wellService.GetTimezone(request.IdWell);
var updateFromUtc = request.UpdateFrom?.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(p => p.LastUpdate >= updateFromUtc);
}
}
return query.OrderBy(e => e.DepthStart)
.ThenBy(e => e.Id)
.AsNoTracking();
}
protected override WellDrillingProcessMapDto Convert(WellDrillingProcessMap entity)
{
var dto = entity.Adapt<WellDrillingProcessMapDto>();
dto.LastUpdate = entity.LastUpdate.ToRemoteDateTime(entity.Well.Timezone.Hours);
dto.AxialLoad = new PlanLimitDto
{
LimitMax = entity.AxialLoadLimitMax,
Plan = entity.AxialLoadPlan
};
dto.Flow = new PlanLimitDto
{
LimitMax = entity.FlowLimitMax,
Plan = entity.FlowPlan
};
dto.Pressure = new PlanLimitDto
{
LimitMax = entity.PressureLimitMax,
Plan = entity.PressurePlan
};
dto.TopDriveSpeed = new PlanLimitDto
{
LimitMax = entity.TopDriveSpeedLimitMax,
Plan = entity.TopDriveSpeedPlan
};
dto.TopDriveTorque = new PlanLimitDto
{
LimitMax = entity.TopDriveTorqueLimitMax,
Plan = entity.TopDriveTorquePlan
};
return dto;
}
protected override WellDrillingProcessMap Convert(WellDrillingProcessMapDto dto)
{
var entity = dto.Adapt<WellDrillingProcessMap>();
entity.AxialLoadPlan = dto.AxialLoad.Plan;
entity.AxialLoadLimitMax = dto.AxialLoad.LimitMax;
entity.FlowPlan = dto.Flow.Plan;
entity.FlowLimitMax = dto.Flow.LimitMax;
entity.PressurePlan = dto.Pressure.Plan;
entity.PressureLimitMax = dto.Pressure.LimitMax;
entity.TopDriveSpeedPlan = dto.TopDriveSpeed.Plan;
entity.TopDriveSpeedLimitMax = dto.TopDriveSpeed.LimitMax;
entity.TopDriveTorquePlan = dto.TopDriveTorque.Plan;
entity.TopDriveTorqueLimitMax = dto.TopDriveTorque.LimitMax;
return entity;
}
}

View File

@ -1,48 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudDb.Model.ProcessMaps;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Repository;
internal class WellReamProcessMapRepository : CrudWellRelatedRepositoryBase<WellReamProcessMapDto, WellReamProcessMap>,
IWellReamProcessMapRepository
{
private readonly IWellService wellService;
public WellReamProcessMapRepository(IAsbCloudDbContext context, IWellService wellService)
: base(context, dbSet =>
dbSet.Include(p => p.Well))
{
this.wellService = wellService;
}
public async Task<IEnumerable<WellReamProcessMapDto>> GetAsync(WellReamProcessMapRequest request,
CancellationToken cancellationToken)
{
var query = GetQuery()
.Where(p => p.IdWell == request.IdWell);
if (request.UpdateFrom is not null)
{
var timezone = wellService.GetTimezone(request.IdWell);
var updateFromUtc = request.UpdateFrom?.ToUtcDateTimeOffset(timezone.Hours);
query = query.Where(p => p.LastUpdate >= updateFromUtc);
}
var entities = await query.OrderBy(e => e.DepthStart)
.ThenBy(e => e.Id)
.AsNoTracking()
.ToArrayAsync(cancellationToken);
return entities.Select(Convert);
}
}