Рефакторинг

This commit is contained in:
Оля Бизюкова 2023-11-22 10:31:41 +05:00
parent 0817dbc689
commit 81bd89aafc
7 changed files with 20 additions and 139 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AsbCloudApp.Repositories
{
/// <summary>
/// CRUD для работы с плановой траекторией из клиента
/// CRUD-репозиторий для работы с траекторией из клиента (плановой и фактической)
/// </summary>
/// <returns></returns>
//TrajectoryGeoPlanDto

View File

@ -1,13 +1,9 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.WITS;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories
{
/// <summary>
/// CRUD для работы с фактической траекторией из клиента
/// репозиторий для работы с траекторией из ннб (фактической)
/// </summary>
/// <returns></returns>
public interface ITrajectoryNnbRepository : ITrajectoryRepository<TrajectoryGeoFactDto>

View File

@ -1,8 +1,5 @@
using AsbCloudApp.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@ -15,7 +12,7 @@ namespace AsbCloudApp.Repositories
where T : TrajectoryGeoDto
{
/// <summary>
/// Получить все добавленные по скважине координаты плановой траектории
/// Получить все добавленные по скважине координаты траектории
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>

View File

@ -255,8 +255,8 @@ namespace AsbCloudInfrastructure
services.AddTransient<ILimitingParameterRepository, LimitingParameterRepository>();
services.AddTransient<ITelemetryWirelineRunOutRepository, TelemetryWirelineRunOutRepository>();
services.AddTransient<IWellFinalDocumentsRepository, WellFinalDocumentsRepository>();
services.AddTransient<ITrajectoryEditableRepository<TrajectoryGeoPlanDto>, TrajectoryPlanRepository<PlannedTrajectory, TrajectoryGeoPlanDto>>();
services.AddTransient<ITrajectoryEditableRepository<TrajectoryGeoFactDto>, TrajectoryPlanRepository<PlannedTrajectory, TrajectoryGeoFactDto>>();
services.AddTransient<ITrajectoryEditableRepository<TrajectoryGeoPlanDto>, TrajectoryEditableRepository<PlannedTrajectory, TrajectoryGeoPlanDto>>();
services.AddTransient<ITrajectoryEditableRepository<TrajectoryGeoFactDto>, TrajectoryEditableRepository<FactTrajectory, TrajectoryGeoFactDto>>();
services.AddTransient<ITrajectoryNnbRepository, TrajectoryNnbRepository>();
services.AddTransient<IFaqRepository, FaqRepository>();
services.AddTransient<ISlipsStatService, SlipsStatService>();

View File

@ -14,14 +14,18 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
public class TrajectoryPlanRepository<TEntity, Tdto> : ITrajectoryEditableRepository<Tdto>
/// <summary>
/// CRUD-репозиторий для работы с траекториями (плановыми и фактическими)
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="Tdto"></typeparam>
public class TrajectoryEditableRepository<TEntity, Tdto> : ITrajectoryEditableRepository<Tdto>
where TEntity : Trajectory
where Tdto : TrajectoryGeoDto
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
public TrajectoryPlanRepository(IAsbCloudDbContext db, IWellService wellService)
public TrajectoryEditableRepository(IAsbCloudDbContext db, IWellService wellService)
{
this.db = db;
this.wellService = wellService;

View File

@ -1,116 +0,0 @@
//using AsbCloudApp.Data;
//using AsbCloudApp.Exceptions;
//using AsbCloudApp.Repositories;
//using AsbCloudApp.Services;
//using AsbCloudDb.Model;
//using Mapster;
//using Microsoft.EntityFrameworkCore;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Threading;
//using System.Threading.Tasks;
//namespace AsbCloudInfrastructure.Repository
//{
// internal class TrajectoryFactRepository : ITrajectoryEditableRepository<TrajectoryGeoFactDto>
// {
// private readonly IAsbCloudDbContext db;
// private readonly IWellService wellService;
// public TrajectoryFactRepository(IAsbCloudDbContext db, IWellService wellService)
// {
// this.db = db;
// this.wellService = wellService;
// }
// public async Task<int> AddAsync(TrajectoryGeoFactDto importedFactTrajectoryRow, CancellationToken token)
// {
// var offsetHours = wellService.GetTimezone(importedFactTrajectoryRow.IdWell).Hours;
// var entity = Convert(importedFactTrajectoryRow, offsetHours);
// entity.Id = 0;
// db.FactTrajectories.Add(entity);
// return await db.SaveChangesAsync(token)
// .ConfigureAwait(false);
// }
// public async Task<int> AddRangeAsync(IEnumerable<TrajectoryGeoFactDto> trajectoryRows, CancellationToken token)
// {
// var idWell = trajectoryRows.First().IdWell;
// if (!trajectoryRows.All(r => r.IdWell == idWell))
// throw new ArgumentInvalidException(nameof(trajectoryRows), "Все строки должны относиться к одной скважине");
// var offsetHours = wellService.GetTimezone(idWell).Hours;
// var entities = trajectoryRows
// .Select(e =>
// {
// var entity = Convert(e, offsetHours);
// entity.Id = 0;
// return entity;
// });
// db.FactTrajectories.AddRange(entities);
// return await db.SaveChangesAsync(token)
// .ConfigureAwait(false);
// }
// public async Task<int> DeleteByIdWellAsync(int idWell, CancellationToken token)
// {
// var query = db.FactTrajectories
// .Where(e => e.IdWell == idWell);
// db.FactTrajectories.RemoveRange(query);
// return await db.SaveChangesAsync(token)
// .ConfigureAwait(false);
// }
// public async Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token)
// {
// var query = db.FactTrajectories
// .Where(e => ids.Contains(e.Id));
// db.FactTrajectories.RemoveRange(query);
// return await db.SaveChangesAsync(token)
// .ConfigureAwait(false);
// }
// public async Task<IEnumerable<TrajectoryGeoFactDto>> GetAsync(int idWell, CancellationToken token)
// {
// var well = wellService.GetOrDefault(idWell)
// ?? throw new ArgumentInvalidException(nameof(idWell), "idWell doesn`t exist");
// var offsetHours = well.Timezone.Hours;
// var query = db.FactTrajectories
// .AsNoTracking()
// .Where(x => x.IdWell == idWell);
// var entities = await query
// .OrderBy(e => e.WellboreDepth)
// .ToArrayAsync(token);
// var result = entities
// .Select(r => Convert(r, offsetHours));
// return result;
// }
// public async Task<int> UpdateAsync(TrajectoryGeoFactDto row, CancellationToken token)
// {
// var offsetHours = wellService.GetTimezone(row.IdWell).Hours;
// var entity = Convert(row, offsetHours);
// db.FactTrajectories.Update(entity);
// return await db.SaveChangesAsync(token)
// .ConfigureAwait(false);
// }
// private TrajectoryGeoFactDto Convert(FactTrajectory entity, double offsetHours)
// {
// var dto = entity.Adapt<TrajectoryGeoFactDto>();
// dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(offsetHours);
// return dto;
// }
// private FactTrajectory Convert(TrajectoryGeoFactDto dto, double offsetHours)
// {
// var entity = dto.Adapt<FactTrajectory>();
// entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours);
// return entity;
// }
// }
//}

View File

@ -21,7 +21,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
[Route("api/well/{idWell}/[controller]")]
public class FactTrajectoryController : ControllerBase
{
private readonly ITrajectoryEditableRepository<TrajectoryGeoFactDto> trajectoryFactRepository;
private readonly ITrajectoryEditableRepository<TrajectoryGeoFactDto> factTrajectoryRepository;
private readonly IWellService wellService;
private readonly FactTrajectoryImportService factTrajectoryImportService;
@ -30,7 +30,7 @@ public class FactTrajectoryController : ControllerBase
IWellService wellService,
FactTrajectoryImportService factTrajectoryImportService)
{
this.trajectoryFactRepository = trajectoryFactRepository;
this.factTrajectoryRepository = trajectoryFactRepository;
this.wellService = wellService;
this.factTrajectoryImportService = factTrajectoryImportService;
}
@ -46,7 +46,7 @@ public class FactTrajectoryController : ControllerBase
public async Task<IActionResult> GetRowsAsync([FromRoute] int idWell,
CancellationToken cancellationToken)
{
var importedFactTrajectories = await trajectoryFactRepository.GetAsync(idWell,
var importedFactTrajectories = await factTrajectoryRepository.GetAsync(idWell,
cancellationToken);
return Ok(importedFactTrajectories);
@ -71,7 +71,7 @@ public class FactTrajectoryController : ControllerBase
return Forbid();
row.IdUser = idUser.Value;
row.IdWell = idWell;
var result = await trajectoryFactRepository.AddAsync(row, token);
var result = await factTrajectoryRepository.AddAsync(row, token);
return Ok(result);
}
@ -96,7 +96,7 @@ public class FactTrajectoryController : ControllerBase
row.Id = idRow;
row.IdUser = idUser.Value;
row.IdWell = idWell;
var result = await trajectoryFactRepository.UpdateAsync(row, token);
var result = await factTrajectoryRepository.UpdateAsync(row, token);
return Ok(result);
}
@ -115,7 +115,7 @@ public class FactTrajectoryController : ControllerBase
token).ConfigureAwait(false))
return Forbid();
var result = await trajectoryFactRepository.DeleteRangeAsync(new int[] { idRow }, token);
var result = await factTrajectoryRepository.DeleteRangeAsync(new int[] { idRow }, token);
return Ok(result);
}
@ -188,9 +188,9 @@ public class FactTrajectoryController : ControllerBase
var trajectoryRows = await factTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, token);
if (deleteBeforeImport)
await trajectoryFactRepository.DeleteByIdWellAsync(idWell, token);
await factTrajectoryRepository.DeleteByIdWellAsync(idWell, token);
var rowsCount = await trajectoryFactRepository.AddRangeAsync(trajectoryRows, token);
var rowsCount = await factTrajectoryRepository.AddRangeAsync(trajectoryRows, token);
return Ok(rowsCount);
}