forked from ddrilling/AsbCloudServer
Add WitsControllerAbstract.GetLastDataAsync(..)
This commit is contained in:
parent
091464a390
commit
7b957d0edb
@ -11,6 +11,7 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
Task SaveDataAsync(int idTelemetry, IEnumerable<TDto> dtos, CancellationToken token);
|
Task SaveDataAsync(int idTelemetry, IEnumerable<TDto> dtos, CancellationToken token);
|
||||||
Task<IEnumerable<TDto>> GetAsync(int idTelemetry, DateTime begin, DateTime end, CancellationToken token);
|
Task<IEnumerable<TDto>> GetAsync(int idTelemetry, DateTime begin, DateTime end, CancellationToken token);
|
||||||
|
Task<IEnumerable<TDto>> GetLastAsync(int idTelemetry, CancellationToken token);
|
||||||
Task<(DateTime begin, DateTime end, int count)?> GetStatAsync(int idTelemetry, CancellationToken token);
|
Task<(DateTime begin, DateTime end, int count)?> GetStatAsync(int idTelemetry, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -54,6 +54,17 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return data.Select(d => Convert(d, timezoneHours));
|
return data.Select(d => Convert(d, timezoneHours));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<TDto>> GetLastAsync(int idTelemetry, CancellationToken token)
|
||||||
|
{
|
||||||
|
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
|
||||||
|
var query = dbset
|
||||||
|
.Where(d => d.IdTelemetry == idTelemetry)
|
||||||
|
.OrderBy(d => d.DateTime)
|
||||||
|
.AsNoTracking();
|
||||||
|
var data = await query.LastOrDefaultAsync(token);
|
||||||
|
return new TDto[] { Convert(data, timezoneHours) };
|
||||||
|
}
|
||||||
|
|
||||||
public Task SaveDataAsync(int idTelemetry, IEnumerable<TDto> dtos, CancellationToken token)
|
public Task SaveDataAsync(int idTelemetry, IEnumerable<TDto> dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (dtos?.Any() != true)
|
if (dtos?.Any() != true)
|
||||||
@ -86,5 +97,6 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
data.DateTime = entity.DateTime.ToRemoteDateTime(timezoneHours);
|
data.DateTime = entity.DateTime.ToRemoteDateTime(timezoneHours);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -59,6 +60,26 @@ namespace AsbCloudWebApi.Controllers.WITS
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение последней пришедшей WITS записи.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="witsRecordRepository"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{idWell}/last")]
|
||||||
|
public async virtual Task<ActionResult<IEnumerable<TDto>>> GetLastDataAsync(
|
||||||
|
int idWell,
|
||||||
|
[FromServices] IWitsRecordRepository<TDto> witsRecordRepository,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||||
|
if (idTelemetry is null)
|
||||||
|
return NoContent();
|
||||||
|
var dtos = await witsRecordRepository.GetLastAsync((int)idTelemetry, token);
|
||||||
|
return Ok(dtos);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение списка архивных WITS записей за период.
|
/// Получение списка архивных WITS записей за период.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -71,8 +92,8 @@ namespace AsbCloudWebApi.Controllers.WITS
|
|||||||
[HttpGet("{idWell}")]
|
[HttpGet("{idWell}")]
|
||||||
public async virtual Task<ActionResult<IEnumerable<TDto>>> GetDataAsync(
|
public async virtual Task<ActionResult<IEnumerable<TDto>>> GetDataAsync(
|
||||||
int idWell,
|
int idWell,
|
||||||
DateTime begin,
|
[Required] DateTime begin,
|
||||||
DateTime end,
|
[Required] DateTime end,
|
||||||
[FromServices] IWitsRecordRepository<TDto> witsRecordRepository,
|
[FromServices] IWitsRecordRepository<TDto> witsRecordRepository,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user