forked from ddrilling/AsbCloudServer
1. Правки после ревью
2. nullable enable в WellOperationPlanDto
This commit is contained in:
parent
4f6cbd014e
commit
c15c0e5522
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
@ -7,18 +8,18 @@ namespace AsbCloudApp.Data
|
|||||||
/// класс, который хранит список плановых операций для сопоставления
|
/// класс, который хранит список плановых операций для сопоставления
|
||||||
/// и даты последней сопоставленной плановой операции
|
/// и даты последней сопоставленной плановой операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
#nullable disable
|
#nullable enable
|
||||||
public class WellOperationPlanDto
|
public class WellOperationPlanDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// коллекция плановых операций
|
/// коллекция плановых операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<WellOperationDto> WellOperationsPlan { get; set; }
|
public IEnumerable<WellOperationDto> WellOperationsPlan { get; set; } = Enumerable.Empty<WellOperationDto>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// дата последней сопоставленной плановой операции
|
/// дата последней сопоставленной плановой операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime DateLastAssosiatedPlanOperation { get; set; }
|
public DateTime? DateLastAssosiatedPlanOperation { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
@ -32,7 +32,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime currentDate, CancellationToken token);
|
Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// дата/время первой операции по скважине
|
/// дата/время первой операции по скважине
|
||||||
|
@ -63,13 +63,44 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.GetOrCreateBasic<WellSectionType>(db)
|
.GetOrCreateBasic<WellSectionType>(db)
|
||||||
.ToDictionary(s => s.Id, s => s.Caption);
|
.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 timezone = wellService.GetTimezone(idWell);
|
||||||
var currentDateOffset = currentDate.ToUtcDateTimeOffset(timezone.Hours);
|
var request = new WellOperationRequest()
|
||||||
var timeZoneOffset = TimeSpan.FromHours(timezone.Hours);
|
{
|
||||||
|
IdWell = idWell
|
||||||
|
};
|
||||||
|
|
||||||
|
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 result = new WellOperationPlanDto()
|
||||||
|
{
|
||||||
|
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
|
var lastFactOperation = await db.WellOperations
|
||||||
|
.Where(x => x.IdWell == idWell)
|
||||||
.Where(x => x.IdType == WellOperation.IdOperationTypeFact)
|
.Where(x => x.IdType == WellOperation.IdOperationTypeFact)
|
||||||
.Where(x => x.IdPlan != null)
|
.Where(x => x.IdPlan != null)
|
||||||
.Where(x => x.DateStart < currentDateOffset)
|
.Where(x => x.DateStart < currentDateOffset)
|
||||||
@ -78,39 +109,11 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.FirstOrDefaultAsync(token)
|
.FirstOrDefaultAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (lastFactOperation is not null)
|
||||||
|
return DateTime.SpecifyKind(lastFactOperation.OperationPlan.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified);
|
||||||
|
|
||||||
var query = await db.WellOperations
|
}
|
||||||
.Include(x => x.OperationCategory)
|
return null;
|
||||||
.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
|
|
||||||
};
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@ -373,6 +376,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.Where(subOp => subOp.DateStart <= o.DateStart)
|
.Where(subOp => subOp.DateStart <= o.DateStart)
|
||||||
.Min(subOp => subOp.DateStart))
|
.Min(subOp => subOp.DateStart))
|
||||||
.TotalDays,
|
.TotalDays,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (request.SortFields?.Any() == true)
|
if (request.SortFields?.Any() == true)
|
||||||
|
Loading…
Reference in New Issue
Block a user