Fix GtrWitsRepository.GetAsync()

This commit is contained in:
ngfrolov 2024-04-17 09:18:08 +05:00
parent 28a583c606
commit 76c845a705
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
2 changed files with 15 additions and 16 deletions

View File

@ -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 =>
@ -132,16 +131,16 @@ namespace AsbCloudInfrastructure.Repository
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;

View File

@ -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);