This commit is contained in:
ngfrolov 2024-04-24 15:21:16 +05:00
parent 811a24a085
commit 7dbe43a72a
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
3 changed files with 22 additions and 21 deletions

View File

@ -54,7 +54,7 @@ namespace AsbCloudApp.Repositories
/// <summary>
/// Обновить существующую операцию
/// </summary>
/// <param name="dto"></param>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> UpdateRangeAsync(IEnumerable<WellOperationDto> dtos, CancellationToken token);

View File

@ -72,15 +72,15 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
{
var query = BuildQuery(request, token);
var entities = (await query)
var query = BuildQuery(request);
var entities = await query
.Select(o => new
{
o.IdCategory,
DurationMinutes = o.DurationHours * 60,
DurationDepth = o.DepthEnd - o.DepthStart
})
.ToArray();
.ToArrayAsync(token);
var parentRelationDictionary = wellOperationCategoryRepository.Get(true)
.ToDictionary(c => c.Id, c => new
@ -220,38 +220,39 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
return (result, count);
}
private T FilterByRequest<T>(T entities, WellOperationRequest request)
where T : IQueryable<WellOperation>, IEnumerable<WellOperation>
private static IQueryable<WellOperation> FilterByRequest(IQueryable<WellOperation> entities, WellOperationRequest request)
{
if (request.OperationType.HasValue)
entities = (T)entities.Where(e => e.IdType == request.OperationType.Value);
entities = entities.Where(e => e.IdType == request.OperationType.Value);
if (request.SectionTypeIds?.Any() is true)
entities = (T)entities.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType));
entities = entities.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType));
if (request.OperationCategoryIds?.Any() is true)
entities = (T)entities.Where(e => request.OperationCategoryIds.Contains(e.IdCategory));
entities = entities.Where(e => request.OperationCategoryIds.Contains(e.IdCategory));
if (request.GeDepth.HasValue)
entities = (T)entities.Where(e => e.DepthEnd >= request.GeDepth.Value);
entities = entities.Where(e => e.DepthEnd >= request.GeDepth.Value);
if (request.LeDepth.HasValue)
entities = (T)entities.Where(e => e.DepthEnd <= request.LeDepth.Value);
entities = entities.Where(e => e.DepthEnd <= request.LeDepth.Value);
if (request.GeDate.HasValue)
{
var geDateUtc = request.GeDate.Value.UtcDateTime;
entities = (T)entities.Where(e => e.DateStart >= geDateUtc);
entities = entities.Where(e => e.DateStart >= geDateUtc);
}
if (request.LeDate.HasValue)
{
var leDateUtc = request.LeDate.Value.UtcDateTime;
entities = (T)entities.Where(e => e.DateStart <= leDateUtc);
entities = entities.Where(e => e.DateStart <= leDateUtc);
}
if (request.SortFields?.Any() is true)
entities = (T)entities.AsQueryable().SortBy(request.SortFields);
entities = entities.AsQueryable().SortBy(request.SortFields);
else
entities = entities.AsQueryable().OrderBy(e => e.DateStart);
return entities;
}
private async Task<IQueryable<WellOperation>> BuildQuery(WellOperationRequest request, CancellationToken token)
private IQueryable<WellOperation> BuildQuery(WellOperationRequest request)
{
var query = GetQuery()
.Where(e => request.IdsWell.Contains(e.IdWell))
@ -328,7 +329,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
return sections;
});
return cache;
return cache!;
}
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)

View File

@ -202,12 +202,12 @@ public class WellOperationControllerTest : BaseIntegrationTest
var entity2 = entity1.Adapt<WellOperation>();
entity2.DateStart = entity2.DateStart.AddDays(1);
entity2.IdCategory = WellOperationCategory.IdNonProductiveTime;
entity2.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
entity2.DurationHours = 2;
var entity3 = entity2.Adapt<WellOperation>();
entity3.DateStart = entity3.DateStart.AddDays(1);
entity3.IdCategory = WellOperationCategory.IdNonProductiveTime;
entity3.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
entity3.DurationHours = 3;
dbContext.WellOperations.Add(entity1);
@ -216,19 +216,19 @@ public class WellOperationControllerTest : BaseIntegrationTest
await dbContext.SaveChangesAsync();
var request = new WellOperationRequestBase
{
OperationType = WellOperation.IdOperationTypePlan,
Skip = pageIndex,
Take = pageSize,
};
SortFields = [nameof(WellOperation.DateStart)]
};
//act
var response = await client.GetPageOperationsAsync(well.Id, request);
//assert
Assert.Equal(response.StatusCode, HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
var items = response.Content.Items.ToArray();