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="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TDto>> GetAsync(int idWell,
|
||||
Task<IEnumerable<TDto>> GetByWellAsync(int idWell,
|
||||
DateTime dateBegin = default, double intervalSec = 600d,
|
||||
int approxPointsCount = 1024, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получить данные тех. процесса
|
||||
/// Получить данные тех. процесса по скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <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>
|
||||
/// Период за который есть данные по скважине в рамках временного интервала
|
||||
|
@ -11,6 +11,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Requests;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.SAUB
|
||||
{
|
||||
@ -22,7 +23,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
protected readonly ITelemetryService telemetryService;
|
||||
protected readonly ITelemetryDataCache<TDto> telemetryDataCache;
|
||||
|
||||
public TelemetryDataBaseService(
|
||||
protected TelemetryDataBaseService(
|
||||
IAsbCloudDbContext db,
|
||||
ITelemetryService telemetryService,
|
||||
ITelemetryDataCache<TDto> telemetryDataCache)
|
||||
@ -86,7 +87,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
}
|
||||
|
||||
/// <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,
|
||||
int approxPointsCount = 1024, CancellationToken token = default)
|
||||
{
|
||||
@ -146,23 +147,41 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
}
|
||||
|
||||
/// <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);
|
||||
if (telemetry is null)
|
||||
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)
|
||||
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 query = dbSet
|
||||
.Where(d => d.IdTelemetry == telemetry.Id)
|
||||
.AsNoTracking();
|
||||
.Where(d => d.IdTelemetry == idTelemetry);
|
||||
|
||||
if (request.GeDate.HasValue)
|
||||
{
|
||||
@ -196,12 +215,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
break;
|
||||
}
|
||||
|
||||
var entities = await query
|
||||
.ToArrayAsync(token);
|
||||
|
||||
var dtos = entities.Select(e => Convert(e, timezone.Hours));
|
||||
|
||||
return dtos;
|
||||
return query;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@ -263,9 +277,9 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
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);
|
||||
}
|
||||
|
||||
public override TelemetryDataSaub Convert(TelemetryDataSaubDto src, double timezoneOffset)
|
||||
protected override TelemetryDataSaub Convert(TelemetryDataSaubDto src, double timezoneOffset)
|
||||
{
|
||||
var entity = src.Adapt<TelemetryDataSaub>();
|
||||
var telemetryUser = telemetryUserService
|
||||
@ -122,7 +122,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
|
||||
return entity;
|
||||
}
|
||||
|
||||
public override TelemetryDataSaubDto Convert(TelemetryDataSaub src, double timezoneOffset)
|
||||
protected override TelemetryDataSaubDto Convert(TelemetryDataSaub src, double timezoneOffset)
|
||||
{
|
||||
var dto = src.Adapt<TelemetryDataSaubDto>();
|
||||
var telemetryUser = telemetryUserService.GetOrDefault(src.IdTelemetry, src.IdUser ?? int.MinValue);
|
||||
@ -151,7 +151,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSa
|
||||
_ => 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}";
|
||||
if (telemetry.Info is not null)
|
||||
|
@ -92,7 +92,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
var content = await telemetryDataService.GetAsync(idWell, begin,
|
||||
var content = await telemetryDataService.GetByWellAsync(idWell, begin,
|
||||
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
||||
|
||||
return Ok(content);
|
||||
@ -123,7 +123,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
var content = await telemetryDataService.GetAsync(idWell, request, token);
|
||||
var content = await telemetryDataService.GetByWellAsync(idWell, request, token);
|
||||
|
||||
return Ok(content);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user