This commit is contained in:
ai.astrakhantsev 2023-02-02 10:32:53 +05:00
parent df11450216
commit e2948782fa
4 changed files with 46 additions and 28 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace AsbCloudApp.Requests
{
@ -6,17 +7,22 @@ namespace AsbCloudApp.Requests
/// <summary>
/// Параметры для запроса получения РТК
/// </summary>
public class WellCompositeRequest
public class ProcessMapRequest
{
/// <summary>
/// Идентификатор скважины
/// </summary>
public IEnumerable<int> IdWells { get; set; } = null!;
public int IdWell { get; set; }
/// <summary>
/// Тип секции
/// </summary>
public IEnumerable<int>? IdWellSectionTypes { get; set; } = null!;
public int? IdWellSectionTypes { get; set; }
/// <summary>
/// Дата обновления
/// </summary>
public DateTime? UpdateFrom { get; set; }
}
#nullable disable
}

View File

@ -29,7 +29,7 @@ namespace AsbCloudApp.Services
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(WellCompositeRequest request, CancellationToken token);
Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(List<ProcessMapRequest> request, CancellationToken token);
}
#nullable disable
}

View File

@ -31,7 +31,15 @@ namespace AsbCloudInfrastructure.Repository
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
DateTime? updateFrom, CancellationToken token)
{
var entities = await BuildQuery(idWell, updateFrom)
var request = new List<ProcessMapRequest>
{
new ProcessMapRequest {
IdWell = idWell,
UpdateFrom = updateFrom
}
};
var entities = await BuildQuery(request)
.OrderBy(e => e.DepthStart)
.ThenBy(e => e.Id)
.ToListAsync(token)
@ -41,16 +49,11 @@ namespace AsbCloudInfrastructure.Repository
return dtos;
}
public async Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(WellCompositeRequest request, CancellationToken token)
public async Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(List<ProcessMapRequest> request, CancellationToken token)
{
var query = GetQuery().Where(e => request.IdWells.Contains(e.IdWell));
if (request.IdWellSectionTypes is not null)
{
query.Where(e => request.IdWellSectionTypes.Contains(e.IdWellSectionType));
}
var entities = await query
.ToListAsync(token);
var entities = await BuildQuery(request)
.ToListAsync(token)
.ConfigureAwait(false);
var dtos = entities.Select(Convert).ToList();
return dtos;
}
@ -71,16 +74,23 @@ namespace AsbCloudInfrastructure.Repository
return result;
}
private IQueryable<ProcessMap> BuildQuery(int idWell, DateTime? updateFrom)
private IQueryable<ProcessMap> BuildQuery(IEnumerable<ProcessMapRequest> request)
{
var query = GetQuery().Where(e => e.IdWell == idWell);
var query = GetQuery();
if (updateFrom is not null)
foreach (var item in request)
{
var timezone = wellService.GetTimezone(idWell);
var updateFromUtc = updateFrom?.ToUtcDateTimeOffset(timezone.Hours);
query.Where(e => e.LastUpdate >= updateFromUtc);
query.Where(w => w.IdWell == item.IdWell);
if (item.IdWellSectionTypes is not null)
query.Where(w => w.IdWellSectionType == item.IdWellSectionTypes);
if (item.UpdateFrom is not null)
{
var timezone = wellService.GetTimezone(item.IdWell);
var updateFromUtc = item.UpdateFrom?.ToUtcDateTimeOffset(timezone.Hours);
query.Where(e => e.LastUpdate >= updateFromUtc);
}
}
return query;

View File

@ -57,12 +57,14 @@ namespace AsbCloudInfrastructure.Repository
var idWells = dtos.Select(c => c.IdWellSrc);
var idWellSectionTypes = dtos.Select(c => c.IdWellSectionType);
var processMap = (await processMapRepository.GetByRequesProcessMaplAsync(new WellCompositeRequest
{
IdWells = idWells,
IdWellSectionTypes = idWellSectionTypes
},
token));
var request = new List<ProcessMapRequest>
{
new ProcessMapRequest {
IdWell = idWell
}
};
var processMap = (await processMapRepository.GetByRequesProcessMaplAsync(request, token));
var result = processMap?.Select(x => new ProcessMapDto
{