forked from ddrilling/AsbCloudServer
#8103063 BuildQuery
This commit is contained in:
parent
df11450216
commit
e2948782fa
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AsbCloudApp.Requests
|
namespace AsbCloudApp.Requests
|
||||||
{
|
{
|
||||||
@ -6,17 +7,22 @@ namespace AsbCloudApp.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметры для запроса получения РТК
|
/// Параметры для запроса получения РТК
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WellCompositeRequest
|
public class ProcessMapRequest
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Идентификатор скважины
|
/// Идентификатор скважины
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<int> IdWells { get; set; } = null!;
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Тип секции
|
/// Тип секции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<int>? IdWellSectionTypes { get; set; } = null!;
|
public int? IdWellSectionTypes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата обновления
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? UpdateFrom { get; set; }
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
@ -29,7 +29,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(WellCompositeRequest request, CancellationToken token);
|
Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(List<ProcessMapRequest> request, CancellationToken token);
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
@ -31,7 +31,15 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
|
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
|
||||||
DateTime? updateFrom, CancellationToken token)
|
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)
|
.OrderBy(e => e.DepthStart)
|
||||||
.ThenBy(e => e.Id)
|
.ThenBy(e => e.Id)
|
||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
@ -41,16 +49,11 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return dtos;
|
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));
|
var entities = await BuildQuery(request)
|
||||||
if (request.IdWellSectionTypes is not null)
|
.ToListAsync(token)
|
||||||
{
|
.ConfigureAwait(false);
|
||||||
query.Where(e => request.IdWellSectionTypes.Contains(e.IdWellSectionType));
|
|
||||||
}
|
|
||||||
|
|
||||||
var entities = await query
|
|
||||||
.ToListAsync(token);
|
|
||||||
var dtos = entities.Select(Convert).ToList();
|
var dtos = entities.Select(Convert).ToList();
|
||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
@ -71,17 +74,24 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<ProcessMap> BuildQuery(IEnumerable<ProcessMapRequest> request)
|
||||||
private IQueryable<ProcessMap> BuildQuery(int idWell, DateTime? updateFrom)
|
|
||||||
{
|
{
|
||||||
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);
|
query.Where(w => w.IdWell == item.IdWell);
|
||||||
var updateFromUtc = updateFrom?.ToUtcDateTimeOffset(timezone.Hours);
|
|
||||||
|
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);
|
query.Where(e => e.LastUpdate >= updateFromUtc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -57,12 +57,14 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
var idWells = dtos.Select(c => c.IdWellSrc);
|
var idWells = dtos.Select(c => c.IdWellSrc);
|
||||||
var idWellSectionTypes = dtos.Select(c => c.IdWellSectionType);
|
var idWellSectionTypes = dtos.Select(c => c.IdWellSectionType);
|
||||||
|
|
||||||
var processMap = (await processMapRepository.GetByRequesProcessMaplAsync(new WellCompositeRequest
|
var request = new List<ProcessMapRequest>
|
||||||
{
|
{
|
||||||
IdWells = idWells,
|
new ProcessMapRequest {
|
||||||
IdWellSectionTypes = idWellSectionTypes
|
IdWell = idWell
|
||||||
},
|
}
|
||||||
token));
|
};
|
||||||
|
|
||||||
|
var processMap = (await processMapRepository.GetByRequesProcessMaplAsync(request, token));
|
||||||
|
|
||||||
var result = processMap?.Select(x => new ProcessMapDto
|
var result = processMap?.Select(x => new ProcessMapDto
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user