forked from ddrilling/AsbCloudServer
Правки
1. Изменено описание API 2. Добавлено кеширвоание
This commit is contained in:
parent
5a8d1e448d
commit
f27bdb65b1
@ -1,28 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Requests;
|
||||
namespace AsbCloudApp.Requests;
|
||||
|
||||
/// <summary>
|
||||
/// Запрос получения информации по телеметрии
|
||||
/// </summary>
|
||||
public class TelemetryInfoRequestBase
|
||||
public class TelemetryInfoRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор по умолчанию
|
||||
/// Идентификатор компании
|
||||
/// </summary>
|
||||
public TelemetryInfoRequestBase()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Копирующий конструктор
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public TelemetryInfoRequestBase(TelemetryInfoRequestBase request)
|
||||
{
|
||||
IdWellState = request.IdWellState;
|
||||
SortFields = request.SortFields;
|
||||
}
|
||||
public int IdCompany { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Определяет состояние скважины
|
||||
@ -31,32 +17,4 @@ public class TelemetryInfoRequestBase
|
||||
/// 2 - завершена
|
||||
/// </summary>
|
||||
public int IdWellState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Сортировки:
|
||||
/// Содержат список названий полей сортировки
|
||||
/// Указать направление сортировки можно через пробел "asc" или "desc"
|
||||
/// </summary>
|
||||
public IEnumerable<string>? SortFields { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Запрос получения информации по телеметрии
|
||||
/// </summary>
|
||||
public class TelemetryInfoRequest : TelemetryInfoRequestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Копирующий конструктор
|
||||
/// </summary>
|
||||
public TelemetryInfoRequest(int idCompany,
|
||||
TelemetryInfoRequestBase request)
|
||||
: base(request)
|
||||
{
|
||||
IdCompany = idCompany;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор компании
|
||||
/// </summary>
|
||||
public int IdCompany { get; set; }
|
||||
}
|
@ -25,7 +25,6 @@ public class TelemetryService : ITelemetryService
|
||||
//TODO: методы использующие ITelemetryDataCache, скорее всего, тут не нужны
|
||||
private readonly ITelemetryDataCache<TelemetryDataSaubDto> dataSaubCache;
|
||||
private readonly ITimezoneService timezoneService;
|
||||
|
||||
public ITimezoneService TimeZoneService => timezoneService;
|
||||
|
||||
public TelemetryService(
|
||||
@ -81,28 +80,39 @@ public class TelemetryService : ITelemetryService
|
||||
|
||||
public async Task<IEnumerable<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token)
|
||||
{
|
||||
var idTelemetries = await db.Set<Well>().Include(x => x.RelationCompaniesWells)
|
||||
var idTelemetries = await db.Set<Well>()
|
||||
.Include(x => x.RelationCompaniesWells)
|
||||
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany) &&
|
||||
x.IdState == request.IdWellState)
|
||||
.Select(x => x.IdTelemetry)
|
||||
.Where(x => x.IdTelemetry.HasValue)
|
||||
.Select(x => x.IdTelemetry!.Value)
|
||||
.ToArrayAsync(token);
|
||||
|
||||
var query = db.Set<Telemetry>()
|
||||
.Where(x => idTelemetries.Contains(x.Id));
|
||||
var key = $"TelemetryInfo_{string.Join("", idTelemetries)}";
|
||||
|
||||
if (request.SortFields?.Any() == true)
|
||||
query = query.SortBy(request.SortFields);
|
||||
|
||||
var entities = await query
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(token);
|
||||
|
||||
return entities.Select(x =>
|
||||
var result = await memoryCache.GetOrCreateAsync(key, async entry =>
|
||||
{
|
||||
var dto = x.Info.Adapt<TelemetryInfoDto>();
|
||||
dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours);
|
||||
return dto;
|
||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
|
||||
|
||||
var query = db.Set<Telemetry>()
|
||||
.Where(x => idTelemetries.Contains(x.Id))
|
||||
.OrderBy(x => x.Info.DrillingStartDate);
|
||||
|
||||
var entities = await query
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(token);
|
||||
|
||||
var dtos = entities.Select(x =>
|
||||
{
|
||||
var dto = x.Info.Adapt<TelemetryInfoDto>();
|
||||
dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours);
|
||||
return dto;
|
||||
});
|
||||
|
||||
return dtos;
|
||||
});
|
||||
|
||||
return result!;
|
||||
}
|
||||
|
||||
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
|
||||
|
@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
namespace AsbCloudWebApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Информация о телеметрии
|
||||
/// Версии прошивок
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
@ -26,22 +26,29 @@ public class TelemetryInfoController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список информации о телеметрии
|
||||
/// Получить список версий прошивок
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="idWellState">Определяет состояние скважины
|
||||
/// 0 - неизвестно,
|
||||
/// 1 - в работе,
|
||||
/// 2 - завершена</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(IEnumerable<TelemetryInfoDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAsync([FromQuery] TelemetryInfoRequestBase request, CancellationToken token)
|
||||
public async Task<IActionResult> GetAsync([FromQuery] int idWellState, CancellationToken token)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
|
||||
if (!idCompany.HasValue)
|
||||
return Forbid();
|
||||
|
||||
var requestToService = new TelemetryInfoRequest(idCompany.Value, request);
|
||||
var requestToService = new TelemetryInfoRequest
|
||||
{
|
||||
IdCompany = idCompany.Value,
|
||||
IdWellState = idWellState
|
||||
};
|
||||
|
||||
var telemetriesInfo = await telemetryService.GetInfoAsync(requestToService, token);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user