forked from ddrilling/AsbCloudServer
MeasureService Add GetLastAsync
This commit is contained in:
parent
9724b24d98
commit
80d74067c0
@ -8,6 +8,7 @@ namespace AsbCloudApp.Services
|
||||
public interface IMeasureService
|
||||
{
|
||||
Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token);
|
||||
Task<MeasureDto> GetLastAsync(int idWell, int idCategory, CancellationToken token);
|
||||
Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token);
|
||||
Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token);
|
||||
Task<int> InsertAsync(int idWell, MeasureDto data, CancellationToken token);
|
||||
|
@ -30,13 +30,30 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<MeasureDto> GetLastAsync(int idWell, int idCategory, CancellationToken token)
|
||||
{
|
||||
var query = db.Measures
|
||||
.Include(m => m.Category)
|
||||
.Where(m => m.IdWell == idWell && m.IdCategory == idCategory && !m.IsDeleted)
|
||||
.OrderByDescending(m => m.Timestamp)
|
||||
.Take(1);
|
||||
|
||||
var entity = await query
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var dtos = entity?.Adapt<MeasureDto, Measure>((d, s) => d.CategoryName = s.Category?.Name);
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var categories = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
||||
if (!categories.Any())
|
||||
return default;
|
||||
|
||||
var queries = categories.Select(c => db.Measures
|
||||
var queries = categories.Select(c => db.Measures.Include(m => m.Category)
|
||||
.Where(m => m.IdWell == idWell && m.IdCategory == c.Id && !m.IsDeleted)
|
||||
.OrderByDescending(m => m.Timestamp)
|
||||
.Take(1)
|
||||
@ -62,7 +79,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var dtos = entities.Adapt<MeasureDto, Measure>((d, s) => d.CategoryName = s.Category.Name);
|
||||
var dtos = entities.Adapt<MeasureDto, Measure>((d, s) => d.CategoryName = s.Category?.Name);
|
||||
return dtos;
|
||||
}
|
||||
|
||||
@ -76,7 +93,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var dtos = entities.Adapt<MeasureDto, Measure>((d, s) => d.CategoryName = s.Category.Name);
|
||||
var dtos = entities.Adapt<MeasureDto, Measure>((d, s) => d.CategoryName = s.Category?.Name);
|
||||
return dtos;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("last")]
|
||||
[Route("lastAll")]
|
||||
public async Task<IActionResult> GetAllLastAsync([FromRoute] int idWell, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
@ -44,8 +44,19 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{idCategory}/history")]
|
||||
public async Task<IActionResult> GetHisoryAsync([FromRoute] int idWell, [FromQuery] int idCategory, CancellationToken token = default)
|
||||
[Route("last/{idCategory}")]
|
||||
public async Task<IActionResult> GetLastAsync([FromRoute] int idWell, [FromRoute] int idCategory, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await lastDataService.GetLastAsync(idWell, idCategory, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("history/{idCategory}")]
|
||||
public async Task<IActionResult> GetHisoryAsync([FromRoute] int idWell, [FromRoute] int idCategory, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
@ -57,16 +57,16 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetOperationsAsync(
|
||||
int idWell,
|
||||
int? opertaionType = default,
|
||||
[FromRoute] int idWell,
|
||||
[FromQuery] int? opertaionType = default,
|
||||
[FromQuery] IEnumerable<int> sectionTypeIds = default,
|
||||
[FromQuery] IEnumerable<int> operationCategoryIds = default,
|
||||
DateTime begin = default,
|
||||
DateTime end = default,
|
||||
double minDepth = double.MinValue,
|
||||
double maxDepth = double.MaxValue,
|
||||
int skip = 0,
|
||||
int take = 32,
|
||||
[FromQuery] DateTime begin = default,
|
||||
[FromQuery] DateTime end = default,
|
||||
[FromQuery] double minDepth = double.MinValue,
|
||||
[FromQuery] double maxDepth = double.MaxValue,
|
||||
[FromQuery] int skip = 0,
|
||||
[FromQuery] int take = 32,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
|
Loading…
Reference in New Issue
Block a user