1. Правки после ревью

2. nullable enable в WellOperationPlanDto
This commit is contained in:
Olga Nemt 2023-02-21 16:15:36 +05:00
parent 4f6cbd014e
commit c15c0e5522
3 changed files with 47 additions and 42 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudApp.Data
{
@ -7,18 +8,18 @@ namespace AsbCloudApp.Data
/// класс, который хранит список плановых операций для сопоставления
/// и даты последней сопоставленной плановой операции
/// </summary>
#nullable disable
#nullable enable
public class WellOperationPlanDto
{
/// <summary>
/// коллекция плановых операций
/// </summary>
public IEnumerable<WellOperationDto> WellOperationsPlan { get; set; }
public IEnumerable<WellOperationDto> WellOperationsPlan { get; set; } = Enumerable.Empty<WellOperationDto>();
/// <summary>
/// дата последней сопоставленной плановой операции
/// </summary>
public DateTime DateLastAssosiatedPlanOperation { get; set; }
public DateTime? DateLastAssosiatedPlanOperation { get; set; }
}
#nullable disable

View File

@ -32,7 +32,7 @@ namespace AsbCloudApp.Repositories
/// <param name="token"></param>
/// </summary>
/// <returns></returns>
Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime currentDate, CancellationToken token);
Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token);
/// <summary>
/// дата/время первой операции по скважине

View File

@ -63,56 +63,59 @@ namespace AsbCloudInfrastructure.Repository
.GetOrCreateBasic<WellSectionType>(db)
.ToDictionary(s => s.Id, s => s.Caption);
public async Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime currentDate, CancellationToken token)
public async Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token)
{
var timezone = wellService.GetTimezone(idWell);
var currentDateOffset = currentDate.ToUtcDateTimeOffset(timezone.Hours);
var timeZoneOffset = TimeSpan.FromHours(timezone.Hours);
var request = new WellOperationRequest()
{
IdWell = idWell
};
var lastFactOperation = await db.WellOperations
.Where(x => x.IdType == WellOperation.IdOperationTypeFact)
.Where(x => x.IdPlan != null)
.Where(x => x.DateStart < currentDateOffset)
.Include(x => x.OperationPlan)
.OrderByDescending(x => x.DateStart)
.FirstOrDefaultAsync(token)
.ConfigureAwait(false);
var entities = await BuildQuery(request)
.Where(x => x.IdType == WellOperation.IdOperationTypePlan)
.AsNoTracking()
.ToArrayAsync(token)
.ConfigureAwait(false);
var dateLastAssosiatedPlanOperation = await getDateLastAssosiatedPlanOperation(idWell, currentDate, timezone.Hours, token);
var query = await db.WellOperations
.Include(x => x.OperationCategory)
.Include(x => x.WellSectionType)
.Where(x => x.IdWell == idWell)
.Where(x => x.IdType == WellOperation.IdOperationTypePlan)
.AsNoTracking()
.ToArrayAsync(token)
.ConfigureAwait(false);
var result = new WellOperationPlanDto()
{
WellOperationsPlan = query
.Select(o => new WellOperationDto()
{
IdWell = o.IdWell,
CategoryName = o.OperationCategory.Name,
IdCategory = o.IdCategory,
IdPlan = o.IdPlan,
DepthStart = o.DepthStart,
DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified),
Id = o.Id,
IdWellSectionType = o.IdWellSectionType,
WellSectionTypeName = o.WellSectionType?.Caption ?? string.Empty,
}),
DateLastAssosiatedPlanOperation = lastFactOperation?.OperationPlan.DateStart is not null
? DateTime.SpecifyKind(lastFactOperation.OperationPlan.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified)
: DateTime.MinValue
WellOperationsPlan = entities,
DateLastAssosiatedPlanOperation = dateLastAssosiatedPlanOperation
};
return result;
}
private async Task<DateTime?> getDateLastAssosiatedPlanOperation(
int idWell,
DateTime? currentDate,
double timeZoneHours,
CancellationToken token)
{
if (currentDate is not null)
{
var currentDateOffset = currentDate.Value.ToUtcDateTimeOffset(timeZoneHours);
var timeZoneOffset = TimeSpan.FromHours(timeZoneHours);
var lastFactOperation = await db.WellOperations
.Where(x => x.IdWell == idWell)
.Where(x => x.IdType == WellOperation.IdOperationTypeFact)
.Where(x => x.IdPlan != null)
.Where(x => x.DateStart < currentDateOffset)
.Include(x => x.OperationPlan)
.OrderByDescending(x => x.DateStart)
.FirstOrDefaultAsync(token)
.ConfigureAwait(false);
if (lastFactOperation is not null)
return DateTime.SpecifyKind(lastFactOperation.OperationPlan.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified);
}
return null;
}
/// <inheritdoc/>
public DateTimeOffset? FirstOperationDate(int idWell)
{
@ -373,6 +376,7 @@ namespace AsbCloudInfrastructure.Repository
.Where(subOp => subOp.DateStart <= o.DateStart)
.Min(subOp => subOp.DateStart))
.TotalDays,
});
if (request.SortFields?.Any() == true)