forked from ddrilling/AsbCloudServer
Fix GtrWitsRepository.GetAsync()
This commit is contained in:
parent
28a583c606
commit
76c845a705
@ -94,15 +94,8 @@ namespace AsbCloudInfrastructure.Repository
|
||||
if (telemetry.TimeZone is null)
|
||||
throw new ArgumentInvalidException(nameof(idWell),$"Telemetry id: {telemetry.Id} can't find timezone");
|
||||
|
||||
var timezoneOffset = TimeSpan.FromHours(telemetry.TimeZone.Hours);
|
||||
|
||||
var query = BuildQuery<TEntity, TType>(telemetry.Id, request);
|
||||
|
||||
if (!await query.AnyAsync(token))
|
||||
return Enumerable.Empty<GtrWitsDto>();
|
||||
|
||||
var interval = TimeSpan.FromSeconds(10);
|
||||
|
||||
var idsRecord = WitsParameters.Select(p => p.Key.IdRecord);
|
||||
|
||||
var entities = await query
|
||||
@ -111,6 +104,12 @@ namespace AsbCloudInfrastructure.Repository
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(token);
|
||||
|
||||
if (!entities.Any())
|
||||
return Enumerable.Empty<GtrWitsDto>();
|
||||
|
||||
var interval = TimeSpan.FromSeconds(10);
|
||||
var timezoneOffset = TimeSpan.FromHours(telemetry.TimeZone.Hours);
|
||||
|
||||
var dtos = entities
|
||||
.GroupBy(e => e.DateTime.Ticks / interval.Ticks)
|
||||
.Select(groupByInterval =>
|
||||
@ -131,17 +130,17 @@ namespace AsbCloudInfrastructure.Repository
|
||||
private IQueryable<TEntity> BuildQuery<TEntity, TType>(int idTelemetry, GtrRequest request)
|
||||
where TEntity : WitsItemBase<TType>
|
||||
where TType : notnull
|
||||
{
|
||||
var dateIntervalStart = DateTime.UtcNow.AddSeconds(-request.IntervalSec);
|
||||
|
||||
{
|
||||
var query = db.Set<TEntity>()
|
||||
.Where(e => e.IdTelemetry == idTelemetry)
|
||||
.Where(e => e.DateTime >= dateIntervalStart);
|
||||
.Where(e => e.IdTelemetry == idTelemetry);
|
||||
|
||||
if (request.Begin.HasValue)
|
||||
{
|
||||
var dateBeginUtc = request.Begin.Value.ToUniversalTime();
|
||||
query = query.Where(e => e.DateTime >= dateBeginUtc);
|
||||
var dateBegin = request.Begin.Value.ToUniversalTime();
|
||||
var dateEnd = dateBegin.AddSeconds(request.IntervalSec);
|
||||
query = query
|
||||
.Where(e => e.DateTime >= dateBegin)
|
||||
.Where(e => e.DateTime <= dateEnd);
|
||||
}
|
||||
|
||||
return query;
|
||||
|
@ -38,7 +38,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
this.wellService = wellService;
|
||||
this.telemetryHubContext = telemetryHubContext;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить значение от ГТИ
|
||||
/// </summary>
|
||||
@ -49,7 +49,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[HttpGet]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(IEnumerable<GtrWitsDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAllAsync(int idWell, [FromQuery] GtrRequest request, CancellationToken token)
|
||||
public async Task<IActionResult> GetAllAsync([Required] int idWell, [FromQuery] GtrRequest request, CancellationToken token)
|
||||
{
|
||||
await AssertUserHasAccessToWellAsync(idWell, token);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user