forked from ddrilling/AsbCloudServer
nit
This commit is contained in:
parent
811a24a085
commit
7dbe43a72a
@ -54,7 +54,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновить существующую операцию
|
/// Обновить существующую операцию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dto"></param>
|
/// <param name="dtos"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> UpdateRangeAsync(IEnumerable<WellOperationDto> dtos, CancellationToken token);
|
Task<int> UpdateRangeAsync(IEnumerable<WellOperationDto> dtos, CancellationToken token);
|
||||||
|
@ -72,15 +72,15 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
|
|
||||||
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
|
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = BuildQuery(request, token);
|
var query = BuildQuery(request);
|
||||||
var entities = (await query)
|
var entities = await query
|
||||||
.Select(o => new
|
.Select(o => new
|
||||||
{
|
{
|
||||||
o.IdCategory,
|
o.IdCategory,
|
||||||
DurationMinutes = o.DurationHours * 60,
|
DurationMinutes = o.DurationHours * 60,
|
||||||
DurationDepth = o.DepthEnd - o.DepthStart
|
DurationDepth = o.DepthEnd - o.DepthStart
|
||||||
})
|
})
|
||||||
.ToArray();
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
var parentRelationDictionary = wellOperationCategoryRepository.Get(true)
|
var parentRelationDictionary = wellOperationCategoryRepository.Get(true)
|
||||||
.ToDictionary(c => c.Id, c => new
|
.ToDictionary(c => c.Id, c => new
|
||||||
@ -220,38 +220,39 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
return (result, count);
|
return (result, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T FilterByRequest<T>(T entities, WellOperationRequest request)
|
private static IQueryable<WellOperation> FilterByRequest(IQueryable<WellOperation> entities, WellOperationRequest request)
|
||||||
where T : IQueryable<WellOperation>, IEnumerable<WellOperation>
|
|
||||||
{
|
{
|
||||||
if (request.OperationType.HasValue)
|
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)
|
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)
|
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)
|
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)
|
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)
|
if (request.GeDate.HasValue)
|
||||||
{
|
{
|
||||||
var geDateUtc = request.GeDate.Value.UtcDateTime;
|
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)
|
if (request.LeDate.HasValue)
|
||||||
{
|
{
|
||||||
var leDateUtc = request.LeDate.Value.UtcDateTime;
|
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)
|
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;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IQueryable<WellOperation>> BuildQuery(WellOperationRequest request, CancellationToken token)
|
private IQueryable<WellOperation> BuildQuery(WellOperationRequest request)
|
||||||
{
|
{
|
||||||
var query = GetQuery()
|
var query = GetQuery()
|
||||||
.Where(e => request.IdsWell.Contains(e.IdWell))
|
.Where(e => request.IdsWell.Contains(e.IdWell))
|
||||||
@ -328,7 +329,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
return sections;
|
return sections;
|
||||||
});
|
});
|
||||||
|
|
||||||
return cache;
|
return cache!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
|
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken)
|
||||||
|
@ -202,12 +202,12 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
|
|
||||||
var entity2 = entity1.Adapt<WellOperation>();
|
var entity2 = entity1.Adapt<WellOperation>();
|
||||||
entity2.DateStart = entity2.DateStart.AddDays(1);
|
entity2.DateStart = entity2.DateStart.AddDays(1);
|
||||||
entity2.IdCategory = WellOperationCategory.IdNonProductiveTime;
|
entity2.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
|
||||||
entity2.DurationHours = 2;
|
entity2.DurationHours = 2;
|
||||||
|
|
||||||
var entity3 = entity2.Adapt<WellOperation>();
|
var entity3 = entity2.Adapt<WellOperation>();
|
||||||
entity3.DateStart = entity3.DateStart.AddDays(1);
|
entity3.DateStart = entity3.DateStart.AddDays(1);
|
||||||
entity3.IdCategory = WellOperationCategory.IdNonProductiveTime;
|
entity3.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
|
||||||
entity3.DurationHours = 3;
|
entity3.DurationHours = 3;
|
||||||
|
|
||||||
dbContext.WellOperations.Add(entity1);
|
dbContext.WellOperations.Add(entity1);
|
||||||
@ -216,19 +216,19 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
|
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
|
||||||
var request = new WellOperationRequestBase
|
var request = new WellOperationRequestBase
|
||||||
{
|
{
|
||||||
OperationType = WellOperation.IdOperationTypePlan,
|
OperationType = WellOperation.IdOperationTypePlan,
|
||||||
Skip = pageIndex,
|
Skip = pageIndex,
|
||||||
Take = pageSize,
|
Take = pageSize,
|
||||||
};
|
SortFields = [nameof(WellOperation.DateStart)]
|
||||||
|
};
|
||||||
|
|
||||||
//act
|
//act
|
||||||
var response = await client.GetPageOperationsAsync(well.Id, request);
|
var response = await client.GetPageOperationsAsync(well.Id, request);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(response.StatusCode, HttpStatusCode.OK);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.NotNull(response.Content);
|
Assert.NotNull(response.Content);
|
||||||
|
|
||||||
var items = response.Content.Items.ToArray();
|
var items = response.Content.Items.ToArray();
|
||||||
|
Loading…
Reference in New Issue
Block a user