forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/#32181043-add-durationHours-to-compositeWell
This commit is contained in:
commit
c3af911369
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories
|
namespace AsbCloudApp.Repositories
|
||||||
{
|
{
|
||||||
@ -60,5 +61,15 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[Obsolete]
|
[Obsolete]
|
||||||
IEnumerable<WitsItemRecordDto> GetLastData(int idWell);
|
IEnumerable<WitsItemRecordDto> GetLastData(int idWell);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступные даты по скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="geDate"></param>
|
||||||
|
/// <param name="leDate"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset? geDate, DateTimeOffset? leDate, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ public class GtrRequest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата начала выборки.По умолчанию: текущее время - IntervalSec
|
/// Дата начала выборки.По умолчанию: текущее время - IntervalSec
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? Begin { get; set; }
|
public DateTimeOffset? Begin { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Интервал времени даты начала выборки, секунды
|
/// Интервал времени даты начала выборки, секунды
|
||||||
|
@ -15,6 +15,8 @@ using System.Threading.Tasks;
|
|||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository
|
namespace AsbCloudInfrastructure.Repository
|
||||||
{
|
{
|
||||||
@ -82,6 +84,42 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
public async Task<IEnumerable<GtrWitsDto>> GetAsync(int idWell, GtrRequest request, CancellationToken token) =>
|
public async Task<IEnumerable<GtrWitsDto>> GetAsync(int idWell, GtrRequest request, CancellationToken token) =>
|
||||||
await GetAsync<WitsItemFloat, float>(idWell, request, token);
|
await GetAsync<WitsItemFloat, float>(idWell, request, token);
|
||||||
|
|
||||||
|
public async Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset? geDate, DateTimeOffset? leDate, CancellationToken token)
|
||||||
|
{
|
||||||
|
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||||
|
|
||||||
|
if (telemetry is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var rangeQuery = db
|
||||||
|
.Set<WitsItemFloat>()
|
||||||
|
.Where(e => e.IdTelemetry == telemetry.Id);
|
||||||
|
|
||||||
|
if (geDate is not null)
|
||||||
|
rangeQuery = rangeQuery.Where(e => e.DateTime >= geDate);
|
||||||
|
|
||||||
|
if (leDate is not null)
|
||||||
|
rangeQuery = rangeQuery.Where(e => e.DateTime <= leDate);
|
||||||
|
|
||||||
|
var groupedQuery = rangeQuery.GroupBy(e => e.IdTelemetry)
|
||||||
|
.Select(group => new
|
||||||
|
{
|
||||||
|
Min = group.Min(e => e.DateTime),
|
||||||
|
Max = group.Max(e => e.DateTime)
|
||||||
|
});
|
||||||
|
var range = await groupedQuery.FirstOrDefaultAsync(token);
|
||||||
|
|
||||||
|
if (range is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var result = new DatesRangeDto
|
||||||
|
{
|
||||||
|
From = range.Min.ToOffset(telemetry.TimeZone!.Offset),
|
||||||
|
To = range.Max.ToOffset(telemetry.TimeZone!.Offset),
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<GtrWitsDto>> GetAsync<TEntity, TType>(int idWell, GtrRequest request, CancellationToken token)
|
private async Task<IEnumerable<GtrWitsDto>> GetAsync<TEntity, TType>(int idWell, GtrRequest request, CancellationToken token)
|
||||||
where TEntity : WitsItemBase<TType>
|
where TEntity : WitsItemBase<TType>
|
||||||
where TType : notnull
|
where TType : notnull
|
||||||
@ -116,8 +154,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
{
|
{
|
||||||
var items = groupByInterval.Select(e => e);
|
var items = groupByInterval.Select(e => e);
|
||||||
var values = items.GroupBy(e => (e.IdRecord, e.IdItem))
|
var values = items.GroupBy(e => (e.IdRecord, e.IdItem))
|
||||||
.Where(parameter => parameter.Any())
|
.Where(group => WitsParameters.ContainsKey(group.Key))
|
||||||
.ToDictionary(parameter => WitsParameters[parameter.Key], g => g.Last().Value.ToString());
|
.ToDictionary(group => WitsParameters[group.Key], g => (object)g.Last().Value);
|
||||||
|
|
||||||
var dto = values.Adapt<GtrWitsDto>();
|
var dto = values.Adapt<GtrWitsDto>();
|
||||||
dto.DateTime = items.Last().DateTime.ToOffset(timezoneOffset);
|
dto.DateTime = items.Last().DateTime.ToOffset(timezoneOffset);
|
||||||
@ -142,6 +180,19 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.Where(e => e.DateTime >= dateBegin)
|
.Where(e => e.DateTime >= dateBegin)
|
||||||
.Where(e => e.DateTime <= dateEnd);
|
.Where(e => e.DateTime <= dateEnd);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var lastDate = query
|
||||||
|
.OrderBy(e=>e.DateTime)
|
||||||
|
.LastOrDefault()
|
||||||
|
?.DateTime
|
||||||
|
?? DateTimeOffset.UtcNow;
|
||||||
|
var dateBegin = lastDate.AddSeconds(-request.IntervalSec);
|
||||||
|
var dateEnd = lastDate;
|
||||||
|
query = query
|
||||||
|
.Where(e => e.DateTime >= dateBegin)
|
||||||
|
.Where(e => e.DateTime <= dateEnd);
|
||||||
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ using System.Threading.Tasks;
|
|||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using System;
|
||||||
|
using Org.BouncyCastle.Asn1.Ocsp;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers.SAUB
|
namespace AsbCloudWebApi.Controllers.SAUB
|
||||||
{
|
{
|
||||||
@ -58,6 +61,31 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
return Ok(dtos);
|
return Ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает диапазон дат за которые есть телеметрия за период времени
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="geDate"></param>
|
||||||
|
/// <param name="leDate"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{idWell}/dateRange")]
|
||||||
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
|
||||||
|
[ProducesResponseType((int)System.Net.HttpStatusCode.NoContent)]
|
||||||
|
public virtual async Task<ActionResult<DatesRangeDto?>> GetRangeAsync(
|
||||||
|
[FromRoute] int idWell,
|
||||||
|
DateTimeOffset? geDate,
|
||||||
|
DateTimeOffset? leDate,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
await AssertUserHasAccessToWellAsync(idWell, token);
|
||||||
|
|
||||||
|
var range = await gtrRepository.GetRangeAsync(idWell, geDate, leDate, token);
|
||||||
|
|
||||||
|
return Ok(range);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить загруженные данные ГТИ по скважине
|
/// Получить загруженные данные ГТИ по скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -81,7 +109,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
if (!isCompanyOwnsWell)
|
if (!isCompanyOwnsWell)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var content = await gtrRepository.GetAsync(idWell, request.Begin,
|
var content = await gtrRepository.GetAsync(idWell, request.Begin?.DateTime,
|
||||||
request.IntervalSec, request.ApproxPointsCount, token).ConfigureAwait(false);
|
request.IntervalSec, request.ApproxPointsCount, token).ConfigureAwait(false);
|
||||||
|
|
||||||
return Ok(content);
|
return Ok(content);
|
||||||
|
Loading…
Reference in New Issue
Block a user