1. Изменен запрос для формирования списка плановых операция для сопоставления

2. Добавлена модель WellOperationPlanDto для хранения списка плановых операций и даты последней сопоставленной плановой операции
3. WellSectionTypeName и CategoryName в WellOperationDto могут быть nullable
This commit is contained in:
Olga Nemt 2023-02-21 13:22:24 +05:00
parent 0083048821
commit aef99cbf11
5 changed files with 69 additions and 44 deletions

View File

@ -25,7 +25,7 @@ namespace AsbCloudApp.Data
/// <summary>
/// название секции скважины
/// </summary>
public string WellSectionTypeName { get; set; } = null!;
public string? WellSectionTypeName { get; set; }
/// <summary>
/// id категории операции
@ -41,7 +41,7 @@ namespace AsbCloudApp.Data
/// <summary>
/// название категории операции
/// </summary>
public string CategoryName { get; set; } = null!;
public string? CategoryName { get; set; }
/// <summary>
/// дополнительная информация по операции

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudApp.Data
{
/// <summary>
/// класс, для хранения списка плановых операций для сопоставления
/// и даты последней сопоставленной плановой операции
/// </summary>
#nullable disable
public class WellOperationPlanDto
{
/// <summary>
/// коллекция плановых операций
/// </summary>
public IEnumerable<WellOperationDto> WellOperationsPlan { get; set; }
/// <summary>
/// дата последней сопоставленной плановой операции
/// </summary>
public DateTime DateLastAssosiatedPlanOperation { get; set; }
}
#nullable disable
}

View File

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

View File

@ -4,11 +4,9 @@ using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb;
using AsbCloudDb.Model;
using DocumentFormat.OpenXml.Office2016.Excel;
using Mapster;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
@ -65,54 +63,53 @@ namespace AsbCloudInfrastructure.Repository
.GetOrCreateBasic<WellSectionType>(db)
.ToDictionary(s => s.Id, s => s.Caption);
public async Task<IEnumerable<WellOperationDto>> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token)
public async Task<WellOperationPlanDto> GetOperationsPlanAsync(int idWell, DateTime currentDate, CancellationToken token)
{
var timezone = wellService.GetTimezone(idWell);
DateTimeOffset? currentDateOffset = currentDate.HasValue
? currentDate.Value.ToUtcDateTimeOffset(timezone.Hours)
: null;
var currentDateOffset = currentDate.ToUtcDateTimeOffset(timezone.Hours);
var timeZoneOffset = TimeSpan.FromHours(timezone.Hours);
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);
.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 query = db.WellOperations
var query = await db.WellOperations
.Include(x => x.OperationCategory)
.Include(x => x.WellSectionType)
.Where(x => x.IdWell == idWell)
.Where(x => x.IdType == WellOperation.IdOperationTypePlan);
.Where(x => x.IdType == WellOperation.IdOperationTypePlan)
.AsNoTracking()
.ToArrayAsync(token)
.ConfigureAwait(false);
if (lastFactOperation?.OperationPlan is not null)
var result = new WellOperationPlanDto()
{
var dateStart = lastFactOperation.OperationPlan.DateStart;
query = query.Where(x => x.DateStart >= dateStart);
}
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,
}),
var entities = await query
.AsNoTracking()
.ToArrayAsync(token)
.ConfigureAwait(false);
DateLastAssosiatedPlanOperation = lastFactOperation?.OperationPlan.DateStart is not null
? DateTime.SpecifyKind(lastFactOperation.OperationPlan.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified)
: DateTime.MinValue
};
var timeZoneOffset = TimeSpan.FromHours(timezone.Hours);
var result = entities
.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,
});
return result;
}

View File

@ -65,15 +65,15 @@ namespace AsbCloudWebApi.Controllers
/// Возвращает список плановых операций для сопоставления
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="currentDate">текущая дата для нахождения предыдущей фактической операции
/// <param name="currentDate">дата для нахождения последней сопоставленной плановой операции</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Route("operationsPlan")]
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(WellOperationPlanDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOperationsPlanAsync(
[FromRoute] int idWell,
[FromQuery] DateTime? currentDate,
[FromQuery] DateTime currentDate,
CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))