Правки по ревью

This commit is contained in:
Olga Nemt 2024-05-31 11:53:58 +05:00
parent 63280b60e2
commit c129825eaa
7 changed files with 58 additions and 53 deletions

View File

@ -12,12 +12,11 @@ namespace AsbCloudApp.Repositories;
/// </summary>
public interface IChangeLogRepository<TDto, TRequest>
where TDto : AsbCloudApp.Data.IId
where TRequest : ChangeLogBaseRequest
{
/// <summary>
/// Добавление записей
/// </summary>
/// <param name="idUser"></param>
/// <param name="idUser">пользователь, который добавляет</param>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
@ -26,7 +25,7 @@ public interface IChangeLogRepository<TDto, TRequest>
/// <summary>
/// Редактирование записей
/// </summary>
/// <param name="idUser"></param>
/// <param name="idUser">пользователь, который редактирует</param>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
@ -35,17 +34,17 @@ public interface IChangeLogRepository<TDto, TRequest>
/// <summary>
/// Добавляет Dto у которых id == 0, изменяет dto у которых id != 0
/// </summary>
/// <param name="idUser"></param>
/// <param name="idUser">пользователь, который редактирует или добавляет</param>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token);
/// <summary>
/// Добавление записей с удалением старых (для импорта)
/// Помечает записи как удаленные
/// </summary>
/// <param name="idUser"></param>
/// <param name="request"></param>
/// <param name="idUser">пользователь, который чистит</param>
/// <param name="request">Фильтр по свойствам конкретной сущности</param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> Clear(int idUser, TRequest request, CancellationToken token);
@ -87,10 +86,10 @@ public interface IChangeLogRepository<TDto, TRequest>
Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLog(TRequest request, DateOnly? date, CancellationToken token);
/// <summary>
/// Получение записей по параметрам
/// Получение текущих сейчас записей по параметрам
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TDto>> Get(TRequest request, CancellationToken token);
Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token);
}

View File

@ -1,5 +1,4 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
@ -235,28 +234,46 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
query = createdQuery.Union(editedQuery);
}
var dtos = await CreateChangeLogDto(query, offset, token);
return dtos;
}
private async Task<IEnumerable<ChangeLogDto<TDto>>> CreateChangeLogDto(IQueryable<TEntity> query, TimeSpan offset, CancellationToken token)
{
var entities = await query
.OrderBy(e => e.Creation)
.ThenBy(e => e.Obsolete)
.ThenBy(e => e.Id)
.ToListAsync(token);
var dtos = entities.Select(e => ConvertChangeLogDto(e, offset));
return dtos;
}
public async Task<IEnumerable<ChangeLogDto<TDto>>> Get(TRequest request, DateTimeOffset? moment, CancellationToken token)
{
var query = BuildQuery(request);
if (moment.HasValue)
{
var momentUtc = moment.Value.ToUniversalTime();
query = query
.Where(e => e.Creation <= momentUtc)
.Where(e => e.Obsolete == null || e.Obsolete >= momentUtc);
}
TimeSpan offset = GetTimezoneOffset(request);
var dtos = await CreateChangeLogDto(query, offset, token);
return dtos;
}
public async Task<IEnumerable<TDto>> Get(TRequest request, CancellationToken token)
public async Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token)
{
var query = BuildQuery(request);
var entities = await query
.Where(e => e.Obsolete == null)
.OrderBy(e => e.Creation)
.ThenBy(e => e.Id)
.ToArrayAsync(token);
TimeSpan offset = GetTimezoneOffset(request);
var dtos = entities.Select(e => Convert(e, offset));
return dtos;
var moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero);
var entities = await Get(request, moment, token);
var result = entities.Select(e => e.Item);
return result;
}
protected abstract TimeSpan GetTimezoneOffset(TRequest request);
@ -268,7 +285,7 @@ public abstract class ChangeLogRepositoryAbstract<TDto, TEntity, TRequest> : ICh
var entity = dto.Adapt<TEntity>();
entity.Creation = entity.Creation.ToUniversalTime();
if(entity.Obsolete.HasValue)
if (entity.Obsolete.HasValue)
entity.Obsolete = entity.Obsolete.Value.ToUniversalTime();
return entity;

View File

@ -37,13 +37,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
}
if (request.Moment.HasValue)
{
var moment = request.Moment.Value.ToUniversalTime();
query = query
.Where(e => e.Creation <= moment)
.Where(e => e.Obsolete == null || e.Obsolete >= moment);
}
return query;
}

View File

@ -33,7 +33,7 @@ public abstract class ProcessMapPlanExportService<TDto> : ExportExcelService<TDt
Moment = DateTimeOffset.UtcNow
};
var dtos = await processMapPlanRepository.Get(request, token);
var dtos = await processMapPlanRepository.GetCurrent(request, token);
return dtos;
}
}

View File

@ -50,7 +50,7 @@ public class WellInfoService
var processMapPlanWellDrillings = new List<ProcessMapPlanDrillingDto>();
foreach (var processMapPlanWellDrillingRequest in processMapPlanWellDrillingRequests)
{
var processMaps = await processMapPlanWellDrillingRepository.Get(processMapPlanWellDrillingRequest, token);
var processMaps = await processMapPlanWellDrillingRepository.GetCurrent(processMapPlanWellDrillingRequest, token);
processMapPlanWellDrillings.AddRange(processMaps);
}

View File

@ -1,21 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMaps.Report;
using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Spreadsheet;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.Services.ProcessMaps;
@ -24,27 +19,27 @@ public class ProcessMapReportDataSaubStatServiceTest
{
private IWellService wellService
private IWellService wellService
= Substitute.For<IWellService>();
private IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
private IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanBaseRepository
= Substitute.For<IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell>>();
private IWellOperationRepository wellOperationRepository
private IWellOperationRepository wellOperationRepository
= Substitute.For<IWellOperationRepository>();
private IWellOperationCategoryRepository wellOperationCategoryRepository
private IWellOperationCategoryRepository wellOperationCategoryRepository
= Substitute.For<IWellOperationCategoryRepository>();
private IDataSaubStatRepository dataSaubStatRepository
private IDataSaubStatRepository dataSaubStatRepository
= Substitute.For<IDataSaubStatRepository>();
private ProcessMapReportDrillingService service;
private readonly static SimpleTimezoneDto timezone = new() { Hours = 2 };
private static readonly DateTimeOffset dateStart = new (2024, 01, 01, 00, 11, 11, timezone.Offset);
private readonly static WellDto well = new()
{
private static readonly DateTimeOffset dateStart = new(2024, 01, 01, 00, 11, 11, timezone.Offset);
private readonly static WellDto well = new()
{
Id = 1,
IdTelemetry = 1,
Timezone = timezone
@ -52,7 +47,7 @@ public class ProcessMapReportDataSaubStatServiceTest
private readonly static IEnumerable<ProcessMapPlanDrillingDto> processMapPlan = new List<ProcessMapPlanDrillingDto>()
{
new() {
DepthStart = 0,
DepthStart = 0,
DepthEnd = 100,
IdMode = 1,
IdWell = well.Id,
@ -253,13 +248,13 @@ public class ProcessMapReportDataSaubStatServiceTest
HasOscillation = false,
}
};
public ProcessMapReportDataSaubStatServiceTest()
{
wellService.GetOrDefaultAsync(Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(well);
processMapPlanBaseRepository.Get(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), Arg.Any<CancellationToken>())
processMapPlanBaseRepository.GetCurrent(Arg.Any<ProcessMapPlanBaseRequestWithWell>(), Arg.Any<CancellationToken>())
.Returns(processMapPlan);
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())

View File

@ -144,7 +144,7 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
await AssertUserHasAccessToWell(idWell, token);
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
var result = await repository.Get(serviceRequest, token);
var result = await repository.GetCurrent(serviceRequest, token);
return Ok(result);
}