forked from ddrilling/AsbCloudServer
Правки после ревью
1. Изменил нейминг 2. Поправил метод получения версии ПО. Поправил кеширование 3. В запрос добавил дополнительные прафила фильтрации
This commit is contained in:
parent
da52a8d9b6
commit
1a9ad8a904
@ -67,19 +67,3 @@ public class TelemetryInfoDto
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Comment { get; set; }
|
public string? Comment { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Информация о телеметрии скважины
|
|
||||||
/// </summary>
|
|
||||||
public class WellTelemetryInfoDto
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Идентификатор скважины
|
|
||||||
/// </summary>
|
|
||||||
public int IdWell { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Информация о телеметрии
|
|
||||||
/// </summary>
|
|
||||||
public TelemetryInfoDto Info { get; set; } = null!;
|
|
||||||
}
|
|
17
AsbCloudApp/Data/SAUB/VersionDto.cs
Normal file
17
AsbCloudApp/Data/SAUB/VersionDto.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace AsbCloudApp.Data.SAUB;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Версия ПО
|
||||||
|
/// </summary>
|
||||||
|
public class VersionDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор скважины
|
||||||
|
/// </summary>
|
||||||
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Информация о версии
|
||||||
|
/// </summary>
|
||||||
|
public TelemetryInfoDto Version { get; set; } = null!;
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
namespace AsbCloudApp.Requests;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Запрос получения информации по телеметрии
|
|
||||||
/// </summary>
|
|
||||||
public class TelemetryInfoRequest
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Идентификатор компании
|
|
||||||
/// </summary>
|
|
||||||
public int IdCompany { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Необязательный параметр. Определяет состояние скважины
|
|
||||||
/// 0 - неизвестно,
|
|
||||||
/// 1 - в работе,
|
|
||||||
/// 2 - завершена
|
|
||||||
/// </summary>
|
|
||||||
public int? IdWellState { get; set; }
|
|
||||||
}
|
|
61
AsbCloudApp/Requests/VersionRequest.cs
Normal file
61
AsbCloudApp/Requests/VersionRequest.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Запрос получения версий ПО
|
||||||
|
/// </summary>
|
||||||
|
public class VersionRequestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор по умолчанию
|
||||||
|
/// </summary>
|
||||||
|
public VersionRequestBase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Копирующий конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
public VersionRequestBase(VersionRequestBase request)
|
||||||
|
{
|
||||||
|
IdWellState = request.IdWellState;
|
||||||
|
IdsWell = request.IdsWell;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Необязательный параметр. Определяет состояние скважины
|
||||||
|
/// null - возвращаются все записи
|
||||||
|
/// 0 - неизвестно,
|
||||||
|
/// 1 - в работе,
|
||||||
|
/// 2 - завершена
|
||||||
|
/// </summary>
|
||||||
|
public int? IdWellState { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификаторы скважин
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int>? IdsWell { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Запрос получения версий ПО
|
||||||
|
/// </summary>
|
||||||
|
public class VersionRequest : VersionRequestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public VersionRequest(int idCompany,
|
||||||
|
VersionRequestBase request)
|
||||||
|
: base(request)
|
||||||
|
{
|
||||||
|
IdCompany = idCompany;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор компании
|
||||||
|
/// </summary>
|
||||||
|
public int IdCompany { get; set; }
|
||||||
|
}
|
@ -64,12 +64,12 @@ public interface ITelemetryService
|
|||||||
Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token);
|
Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить данные о телеметрии
|
/// Получить версии ПО
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<WellTelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token);
|
Task<IEnumerable<VersionDto>> GetVersionsAsync(VersionRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Слить данные телеметрии в одну
|
/// Слить данные телеметрии в одну
|
||||||
|
@ -78,7 +78,7 @@ public class TelemetryService : ITelemetryService
|
|||||||
DropTelemetryCache();
|
DropTelemetryCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WellTelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token)
|
public async Task<IEnumerable<VersionDto>> GetVersionsAsync(VersionRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var wells = db.Set<Well>()
|
var wells = db.Set<Well>()
|
||||||
.Include(x => x.RelationCompaniesWells)
|
.Include(x => x.RelationCompaniesWells)
|
||||||
@ -87,41 +87,32 @@ public class TelemetryService : ITelemetryService
|
|||||||
if (request.IdWellState.HasValue)
|
if (request.IdWellState.HasValue)
|
||||||
wells = wells.Where(x => x.IdState == request.IdWellState);
|
wells = wells.Where(x => x.IdState == request.IdWellState);
|
||||||
|
|
||||||
|
if (request.IdsWell?.Any() == true)
|
||||||
|
wells = wells.Where(x => request.IdsWell.Contains(x.Id));
|
||||||
|
|
||||||
var idTelemetries = await wells.Where(x => x.IdTelemetry.HasValue)
|
var idTelemetries = await wells.Where(x => x.IdTelemetry.HasValue)
|
||||||
.Select(x => x.IdTelemetry!.Value)
|
.Select(x => x.IdTelemetry!.Value)
|
||||||
.ToArrayAsync(token);
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
var key = $"TelemetryInfo_{string.Join("", idTelemetries)}";
|
var telemetries = GetTelemetryCache()
|
||||||
|
.Where(x => idTelemetries.Contains(x.Id))
|
||||||
|
.OrderBy(x => x.Info.DrillingStartDate);
|
||||||
|
|
||||||
var result = await memoryCache.GetOrCreateAsync(key, async entry =>
|
var dtos = telemetries.Select(x =>
|
||||||
{
|
{
|
||||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
|
var version = x.Info.Adapt<TelemetryInfoDto>();
|
||||||
|
version.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(version.TimeZoneOffsetTotalHours);
|
||||||
|
|
||||||
var telemetries = await db.Set<Telemetry>()
|
var dto = new VersionDto
|
||||||
.Include(x => x.Well)
|
|
||||||
.Where(x => idTelemetries.Contains(x.Id))
|
|
||||||
.OrderBy(x => x.Info.DrillingStartDate)
|
|
||||||
.AsNoTracking()
|
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
var dtos = telemetries.Select(x =>
|
|
||||||
{
|
{
|
||||||
var info = x.Info.Adapt<TelemetryInfoDto>();
|
IdWell = x.Well!.Id,
|
||||||
info.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(info.TimeZoneOffsetTotalHours);
|
Version = version
|
||||||
|
};
|
||||||
|
|
||||||
var dto = new WellTelemetryInfoDto
|
return dto;
|
||||||
{
|
|
||||||
IdWell = x.Well!.Id,
|
|
||||||
Info = info
|
|
||||||
};
|
|
||||||
|
|
||||||
return dto;
|
|
||||||
});
|
|
||||||
|
|
||||||
return dtos;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return result!;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
|
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AsbCloudApp.Data.SAUB;
|
|
||||||
using AsbCloudApp.Requests;
|
|
||||||
using AsbCloudApp.Services;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Версии прошивок
|
|
||||||
/// </summary>
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
[ApiController]
|
|
||||||
[Authorize]
|
|
||||||
public class TelemetryInfoController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly ITelemetryService telemetryService;
|
|
||||||
|
|
||||||
public TelemetryInfoController(ITelemetryService telemetryService)
|
|
||||||
{
|
|
||||||
this.telemetryService = telemetryService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получить список версий прошивок
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWellState">Необязательный параметр. Определяет состояние скважины
|
|
||||||
/// null - возвращаются все записи
|
|
||||||
/// 0 - неизвестно,
|
|
||||||
/// 1 - в работе,
|
|
||||||
/// 2 - завершена</param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
|
||||||
[Permission]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellTelemetryInfoDto>), StatusCodes.Status200OK)]
|
|
||||||
public async Task<IActionResult> GetAsync([FromQuery] int? idWellState, CancellationToken token)
|
|
||||||
{
|
|
||||||
var idCompany = User.GetCompanyId();
|
|
||||||
|
|
||||||
if (!idCompany.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var requestToService = new TelemetryInfoRequest
|
|
||||||
{
|
|
||||||
IdCompany = idCompany.Value,
|
|
||||||
IdWellState = idWellState
|
|
||||||
};
|
|
||||||
|
|
||||||
var telemetriesInfo = await telemetryService.GetInfoAsync(requestToService, token);
|
|
||||||
|
|
||||||
return Ok(telemetriesInfo);
|
|
||||||
}
|
|
||||||
}
|
|
50
AsbCloudWebApi/Controllers/VersionController.cs
Normal file
50
AsbCloudWebApi/Controllers/VersionController.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Версии ПО
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class VersionController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
|
public VersionController(ITelemetryService telemetryService)
|
||||||
|
{
|
||||||
|
this.telemetryService = telemetryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить список версий ПО
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<VersionDto>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetAsync([FromQuery] VersionRequestBase request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
|
if (!idCompany.HasValue)
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var requestToService = new VersionRequest(idCompany.Value, request);
|
||||||
|
|
||||||
|
var version = await telemetryService.GetVersionsAsync(requestToService, token);
|
||||||
|
|
||||||
|
return Ok(version);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user