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
|
public interface IMeasureService
|
||||||
{
|
{
|
||||||
Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token);
|
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>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token);
|
||||||
Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token);
|
Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token);
|
||||||
Task<int> InsertAsync(int idWell, MeasureDto data, CancellationToken token);
|
Task<int> InsertAsync(int idWell, MeasureDto data, CancellationToken token);
|
||||||
|
@ -30,13 +30,30 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return dto;
|
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)
|
public async Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var categories = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
var categories = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
|
||||||
if (!categories.Any())
|
if (!categories.Any())
|
||||||
return default;
|
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)
|
.Where(m => m.IdWell == idWell && m.IdCategory == c.Id && !m.IsDeleted)
|
||||||
.OrderByDescending(m => m.Timestamp)
|
.OrderByDescending(m => m.Timestamp)
|
||||||
.Take(1)
|
.Take(1)
|
||||||
@ -62,7 +79,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.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;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +93,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.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;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("last")]
|
[Route("lastAll")]
|
||||||
public async Task<IActionResult> GetAllLastAsync([FromRoute] int idWell, CancellationToken token = default)
|
public async Task<IActionResult> GetAllLastAsync([FromRoute] int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
@ -44,8 +44,19 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{idCategory}/history")]
|
[Route("last/{idCategory}")]
|
||||||
public async Task<IActionResult> GetHisoryAsync([FromRoute] int idWell, [FromQuery] int idCategory, CancellationToken token = default)
|
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))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
@ -57,16 +57,16 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetOperationsAsync(
|
public async Task<IActionResult> GetOperationsAsync(
|
||||||
int idWell,
|
[FromRoute] int idWell,
|
||||||
int? opertaionType = default,
|
[FromQuery] int? opertaionType = default,
|
||||||
[FromQuery] IEnumerable<int> sectionTypeIds = default,
|
[FromQuery] IEnumerable<int> sectionTypeIds = default,
|
||||||
[FromQuery] IEnumerable<int> operationCategoryIds = default,
|
[FromQuery] IEnumerable<int> operationCategoryIds = default,
|
||||||
DateTime begin = default,
|
[FromQuery] DateTime begin = default,
|
||||||
DateTime end = default,
|
[FromQuery] DateTime end = default,
|
||||||
double minDepth = double.MinValue,
|
[FromQuery] double minDepth = double.MinValue,
|
||||||
double maxDepth = double.MaxValue,
|
[FromQuery] double maxDepth = double.MaxValue,
|
||||||
int skip = 0,
|
[FromQuery] int skip = 0,
|
||||||
int take = 32,
|
[FromQuery] int take = 32,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
Loading…
Reference in New Issue
Block a user