1. Возвращаемый тип списка плановых операций - IEnumerable<WellOperationDto>

2. Добавлен CancellationToken token
3. Рефактор запроса на получение списка плановых операций
4. Проверка на доступность скважины пользователю
5. Сортировка данных по дате в методе MergeArrays
This commit is contained in:
Olga Nemt 2023-02-16 09:51:55 +05:00
parent aa3b96b31b
commit c7a6e38315
4 changed files with 32 additions and 23 deletions

View File

@ -28,9 +28,10 @@ namespace AsbCloudApp.Repositories
/// <summary>
/// список плановых операций для сопоставления
/// <param name="idWell"></param>
/// <param name="token"></param>
/// </summary>
/// <returns></returns>
Task<List<WellOperationDto>> GetOperationsPlan(int idWell);
Task<IEnumerable<WellOperationDto>> GetOperationsPlanAsync(int idWell, CancellationToken token);
/// <summary>
/// дата/время первой операции по скважине

View File

@ -58,34 +58,37 @@ namespace AsbCloudInfrastructure.Repository
.GetOrCreateBasic<WellSectionType>(db)
.ToDictionary(s => s.Id, s => s.Caption);
public async Task<List<WellOperationDto>> GetOperationsPlan(int idWell)
public async Task<IEnumerable<WellOperationDto>> GetOperationsPlanAsync(int idWell, CancellationToken token)
{
var lastFactOperation = await db.WellOperations
.Where(x => x.IdType == WellOperation.IdOperationTypeFact)
.Where(x => x.IdPlan != null)
.OrderByDescending(x => x.DateStart)
.FirstOrDefaultAsync()
.FirstOrDefaultAsync(token)
.ConfigureAwait(false);
var query = await db.WellOperations
var query = db.WellOperations
.Include(x => x.OperationCategory)
.Where(x => x.IdWell == idWell)
.Where(x => x.IdType == WellOperation.IdOperationTypePlan)
.AsNoTracking()
.ToListAsync()
.ConfigureAwait(false);
.Where(x => x.IdType == WellOperation.IdOperationTypePlan);
if (lastFactOperation is not null)
{
var dateStart = lastFactOperation?.DateStart!;
query = query.Where(x => x.DateStart >= dateStart).ToList();
query = query.Where(x => x.DateStart >= dateStart);
}
var timezone = wellService.GetTimezone(idWell);
var timeZoneOffset = TimeSpan.FromHours(timezone.Hours);
var result = query.
Select(o => new WellOperationDto()
var entities = await query
.AsNoTracking()
.ToArrayAsync(token)
.ConfigureAwait(false);
var result = entities
.Select(o => new WellOperationDto()
{
IdWell = o.IdWell,
CategoryName = o.OperationCategory.Name,
@ -94,8 +97,7 @@ namespace AsbCloudInfrastructure.Repository
DepthStart = o.DepthStart,
DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified),
Id = o.Id
})
.ToList();
});
return result;
}

View File

@ -236,7 +236,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
BhaUpSpeed = CalcBhaUpSpeed(races),
CasingDownSpeed = CalcCasingDownSpeed(operations),
NonProductiveHours = operations
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains( o.IdCategory))
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory))
.Sum(o => o.DurationHours),
};
return section;
@ -330,7 +330,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
{
if (race.Operations[i].IdCategory == WellOperationCategory.IdBhaDown)
dHours += race.Operations[i].DurationHours;
if (WellOperationCategory.MechanicalDrillingSubIds.Contains( race.Operations[i].IdCategory))
if (WellOperationCategory.MechanicalDrillingSubIds.Contains(race.Operations[i].IdCategory))
break;
}
}
@ -492,7 +492,10 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
result.AddRange(oparationsFactWithPlan);
result.AddRange(oparationsPlanWithNoFact);
result = result.OrderBy(x => x.Item1?.DateStart).ToList();
result = result
.OrderBy(x => x.Item1?.DateStart)
.ThenBy(x => x.Item2?.DateStart)
.ToList();
return result;
}

View File

@ -64,15 +64,18 @@ namespace AsbCloudWebApi.Controllers
/// Возвращает список плановых операций для сопоставления
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Route("operationsPlan")]
[Permission]
[ProducesResponseType(typeof(List<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsPlan([FromRoute] int idWell)
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsPlanAsync([FromRoute] int idWell, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await operationRepository
.GetOperationsPlan(idWell)
.GetOperationsPlanAsync(idWell, token)
.ConfigureAwait(false);
return Ok(result);
}
@ -167,8 +170,8 @@ namespace AsbCloudWebApi.Controllers
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
foreach(var value in values)
value.IdWell= idWell;
foreach (var value in values)
value.IdWell = idWell;
var result = await operationRepository.InsertRangeAsync(values, token)
.ConfigureAwait(false);
@ -193,7 +196,7 @@ namespace AsbCloudWebApi.Controllers
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
value.IdWell= idWell;
value.IdWell = idWell;
value.Id = idOperation;
var result = await operationRepository.UpdateAsync(value, token)