forked from ddrilling/AsbCloudServer
Получение данных ГТИ по Record Id
This commit is contained in:
parent
bdf1a0b77c
commit
8d1ae1af84
30
AsbCloudApp/Data/GTR/WitsItemRecordDto.cs
Normal file
30
AsbCloudApp/Data/GTR/WitsItemRecordDto.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data.GTR
|
||||
{
|
||||
/// <summary>
|
||||
/// Запись WITS
|
||||
/// </summary>
|
||||
public class WitsItemRecordDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Record Id
|
||||
/// </summary>
|
||||
public int IdRecord { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Item Id
|
||||
/// </summary>
|
||||
public int IdItem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата создания записи
|
||||
/// </summary>
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Значение
|
||||
/// </summary>
|
||||
public object Value { get; set; }
|
||||
}
|
||||
}
|
@ -34,6 +34,15 @@ namespace AsbCloudApp.Repositories
|
||||
Task<IEnumerable<WitsRecordDto>> GetAsync(int idWell,
|
||||
DateTime? dateBegin, double intervalSec = 600d,
|
||||
int approxPointsCount = 1024, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// получение данных по record id
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="idRecord"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<WitsItemRecordDto>> GetByRecordAsync(int idWell, int idRecord, CancellationToken token = default);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -61,6 +61,35 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WitsItemRecordDto>> GetByRecordAsync(int idWell, int idRecord, CancellationToken token = default)
|
||||
{
|
||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||
if (telemetry is null)
|
||||
return Enumerable.Empty<WitsItemRecordDto>();
|
||||
|
||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
||||
|
||||
var recordAllInt = await GetItemsOrDefaultByRecordAsync<WitsItemInt, int>(telemetry.Id, idRecord, timezone.Hours, token);
|
||||
var recordAllFloat = await GetItemsOrDefaultByRecordAsync<WitsItemFloat, float>(telemetry.Id, idRecord, timezone.Hours, token);
|
||||
var recordAllString = await GetItemsOrDefaultByRecordAsync<WitsItemString, string>(telemetry.Id, idRecord, timezone.Hours, token);
|
||||
|
||||
var dtos = (recordAllFloat.Union(recordAllInt)).Union(recordAllString)
|
||||
.GroupBy(g => new
|
||||
{
|
||||
g.IdRecord,
|
||||
g.IdTelemetry,
|
||||
g.IdItem
|
||||
})
|
||||
.Select(g => new WitsItemRecordDto()
|
||||
{
|
||||
IdRecord = g.Key.IdRecord,
|
||||
IdItem = g.Key.IdItem,
|
||||
Date = g.MaxBy(i => i.Date)!.Date,
|
||||
Value = g.MaxBy(i => i.Date)!.Item.Value,
|
||||
}).ToArray();
|
||||
return dtos;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<ItemRecord>> GetItemsOrDefaultAsync<TEntity, TValue>(
|
||||
int idTelemetry,
|
||||
DateTimeOffset? dateBegin,
|
||||
@ -111,6 +140,40 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return items;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<ItemRecord>> GetItemsOrDefaultByRecordAsync<TEntity, TValue>(
|
||||
int idTelemetry,
|
||||
int idRecord,
|
||||
double timezoneHours,
|
||||
CancellationToken token)
|
||||
where TEntity : WitsItemBase<TValue>
|
||||
where TValue : notnull
|
||||
{
|
||||
var query = db.Set<TEntity>()
|
||||
.Where(i => i.IdTelemetry == idTelemetry)
|
||||
.Where(i => i.IdRecord == idRecord);
|
||||
|
||||
var fullDataCount = await query.CountAsync(token);
|
||||
|
||||
if (fullDataCount == 0)
|
||||
return Enumerable.Empty<ItemRecord>();
|
||||
|
||||
var entities = await query
|
||||
.OrderBy(d => d.DateTime)
|
||||
.AsNoTracking()
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var items = entities.Select(e => new ItemRecord
|
||||
{
|
||||
IdRecord = e.IdRecord,
|
||||
IdTelemetry = e.IdTelemetry,
|
||||
Date = e.DateTime.ToRemoteDateTime(timezoneHours),
|
||||
IdItem = e.IdItem,
|
||||
Item = new JsonValue(e.Value)
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
public async Task SaveDataAsync(int idTelemetry, WitsRecordDto dto, CancellationToken token)
|
||||
{
|
||||
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
|
||||
|
@ -68,6 +68,26 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
[HttpGet("{idWell}/{idRecord}")]
|
||||
[Permission]
|
||||
public async Task<ActionResult<IEnumerable<WitsItemRecordDto>>> GetDataByRecordAsync(int idWell, int idRecord, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
var content = await gtrRepository.GetByRecordAsync(idWell, idRecord, token).ConfigureAwait(false);
|
||||
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод для получения WITS записи от панели оператора.
|
||||
/// Сохраняет в БД.
|
||||
|
Loading…
Reference in New Issue
Block a user