forked from ddrilling/AsbCloudServer
Рефакторинг сервисов телеметрии
This commit is contained in:
parent
aa297e235d
commit
7919926c21
@ -23,18 +23,27 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="approxPointsCount">кол-во элементов до которых эти данные прореживаются</param>
|
/// <param name="approxPointsCount">кол-во элементов до которых эти данные прореживаются</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<TDto>> GetAsync(int idWell,
|
Task<IEnumerable<TDto>> GetByWellAsync(int idWell,
|
||||||
DateTime dateBegin = default, double intervalSec = 600d,
|
DateTime dateBegin = default, double intervalSec = 600d,
|
||||||
int approxPointsCount = 1024, CancellationToken token = default);
|
int approxPointsCount = 1024, CancellationToken token = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить данные тех. процесса
|
/// Получить данные тех. процесса по скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<TDto>> GetAsync(int idWell, TelemetryDataRequest request, CancellationToken token);
|
Task<IEnumerable<TDto>> GetByWellAsync(int idWell, TelemetryDataRequest request, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных тех. процесса по телеметрии
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idTelemetry"></param>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<TDto>> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Период за который есть данные по скважине в рамках временного интервала
|
/// Период за который есть данные по скважине в рамках временного интервала
|
||||||
|
@ -11,6 +11,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.SAUB
|
namespace AsbCloudInfrastructure.Services.SAUB
|
||||||
{
|
{
|
||||||
@ -22,7 +23,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
protected readonly ITelemetryService telemetryService;
|
protected readonly ITelemetryService telemetryService;
|
||||||
protected readonly ITelemetryDataCache<TDto> telemetryDataCache;
|
protected readonly ITelemetryDataCache<TDto> telemetryDataCache;
|
||||||
|
|
||||||
public TelemetryDataBaseService(
|
protected TelemetryDataBaseService(
|
||||||
IAsbCloudDbContext db,
|
IAsbCloudDbContext db,
|
||||||
ITelemetryService telemetryService,
|
ITelemetryService telemetryService,
|
||||||
ITelemetryDataCache<TDto> telemetryDataCache)
|
ITelemetryDataCache<TDto> telemetryDataCache)
|
||||||
@ -86,7 +87,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual async Task<IEnumerable<TDto>> GetAsync(int idWell,
|
public virtual async Task<IEnumerable<TDto>> GetByWellAsync(int idWell,
|
||||||
DateTime dateBegin = default, double intervalSec = 600d,
|
DateTime dateBegin = default, double intervalSec = 600d,
|
||||||
int approxPointsCount = 1024, CancellationToken token = default)
|
int approxPointsCount = 1024, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
@ -146,23 +147,41 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual async Task<IEnumerable<TDto>> GetAsync(int idWell, AsbCloudApp.Requests.TelemetryDataRequest request, CancellationToken token)
|
public virtual async Task<IEnumerable<TDto>> GetByWellAsync(int idWell, TelemetryDataRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||||
if (telemetry is null)
|
if (telemetry is null)
|
||||||
return Enumerable.Empty<TDto>();
|
return Enumerable.Empty<TDto>();
|
||||||
|
|
||||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
return await GetByTelemetryAsync(telemetry.Id, request, token);
|
||||||
|
}
|
||||||
|
|
||||||
var cache = telemetryDataCache.GetOrDefault(telemetry.Id, request);
|
public async Task<IEnumerable<TDto>> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var timezone = telemetryService.GetTimezone(idTelemetry);
|
||||||
|
|
||||||
|
var cache = telemetryDataCache.GetOrDefault(idTelemetry, request);
|
||||||
|
|
||||||
if(cache is not null)
|
if(cache is not null)
|
||||||
return cache;
|
return cache;
|
||||||
|
|
||||||
|
var query = BuildQuery(idTelemetry, request);
|
||||||
|
|
||||||
|
var entities = await query
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var dtos = entities.Select(e => Convert(e, timezone.Hours));
|
||||||
|
|
||||||
|
return dtos;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IQueryable<TEntity> BuildQuery(int idTelemetry, TelemetryDataRequest request)
|
||||||
|
{
|
||||||
var dbSet = db.Set<TEntity>();
|
var dbSet = db.Set<TEntity>();
|
||||||
|
|
||||||
var query = dbSet
|
var query = dbSet
|
||||||
.Where(d => d.IdTelemetry == telemetry.Id)
|
.Where(d => d.IdTelemetry == idTelemetry);
|
||||||
.AsNoTracking();
|
|
||||||
|
|
||||||
if (request.GeDate.HasValue)
|
if (request.GeDate.HasValue)
|
||||||
{
|
{
|
||||||
@ -196,12 +215,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var entities = await query
|
return query;
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
var dtos = entities.Select(e => Convert(e, timezone.Hours));
|
|
||||||
|
|
||||||
return dtos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@ -263,9 +277,9 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
return telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id);
|
return telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract TDto Convert(TEntity src, double timezoneOffset);
|
protected abstract TDto Convert(TEntity src, double timezoneOffset);
|
||||||
|
|
||||||
public abstract TEntity Convert(TDto src, double timezoneOffset);
|
protected abstract TEntity Convert(TDto src, double timezoneOffset);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
|
|||||||
return await query.ToArrayAsync(token);
|
return await query.ToArrayAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TelemetryDataSaub Convert(TelemetryDataSaubDto src, double timezoneOffset)
|
protected override TelemetryDataSaub Convert(TelemetryDataSaubDto src, double timezoneOffset)
|
||||||
{
|
{
|
||||||
var entity = src.Adapt<TelemetryDataSaub>();
|
var entity = src.Adapt<TelemetryDataSaub>();
|
||||||
var telemetryUser = telemetryUserService
|
var telemetryUser = telemetryUserService
|
||||||
@ -122,7 +122,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TelemetryDataSaubDto Convert(TelemetryDataSaub src, double timezoneOffset)
|
protected override TelemetryDataSaubDto Convert(TelemetryDataSaub src, double timezoneOffset)
|
||||||
{
|
{
|
||||||
var dto = src.Adapt<TelemetryDataSaubDto>();
|
var dto = src.Adapt<TelemetryDataSaubDto>();
|
||||||
var telemetryUser = telemetryUserService.GetOrDefault(src.IdTelemetry, src.IdUser ?? int.MinValue);
|
var telemetryUser = telemetryUserService.GetOrDefault(src.IdTelemetry, src.IdUser ?? int.MinValue);
|
||||||
@ -151,7 +151,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
|
|||||||
_ => 32_768
|
_ => 32_768
|
||||||
};
|
};
|
||||||
|
|
||||||
var data = await GetAsync(idWell, beginDate, intervalSec, approxPointsCount, token);
|
var data = await GetByWellAsync(idWell, beginDate, intervalSec, approxPointsCount, token);
|
||||||
|
|
||||||
var fileName = $"DataSaub idWell{idWell}";
|
var fileName = $"DataSaub idWell{idWell}";
|
||||||
if (telemetry.Info is not null)
|
if (telemetry.Info is not null)
|
||||||
|
@ -92,7 +92,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
if (!isCompanyOwnsWell)
|
if (!isCompanyOwnsWell)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var content = await telemetryDataService.GetAsync(idWell, begin,
|
var content = await telemetryDataService.GetByWellAsync(idWell, begin,
|
||||||
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
||||||
|
|
||||||
return Ok(content);
|
return Ok(content);
|
||||||
@ -123,7 +123,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
if (!isCompanyOwnsWell)
|
if (!isCompanyOwnsWell)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var content = await telemetryDataService.GetAsync(idWell, request, token);
|
var content = await telemetryDataService.GetByWellAsync(idWell, request, token);
|
||||||
|
|
||||||
return Ok(content);
|
return Ok(content);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user