Merge pull request 'Фикс версий прошивок' (#314) from feature/versions_list into dev

Reviewed-on: https://test.digitaldrilling.ru:8443/DDrilling/AsbCloudServer/pulls/314
This commit is contained in:
Никита Фролов 2024-08-28 13:28:52 +05:00
commit 57e73eadd9
8 changed files with 202 additions and 104 deletions

View File

@ -0,0 +1,54 @@
using System;
namespace AsbCloudApp.Data.SAUB;
/// <summary>
/// Версия ПО
/// </summary>
public class VersionDto
{
/// <summary>
/// Идентификатор скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// название скважины
/// </summary>
public string Well { get; set; } = string.Empty;
/// <summary>
/// название куста
/// </summary>
public string Cluster { get; set; } = string.Empty;
/// <summary>
/// название месторождения
/// </summary>
public string Deposit { get; set; } = string.Empty;
/// <summary>
/// название заказчика
/// </summary>
public string? Customer { get; set; }
/// <summary>
/// версия ПО панели оператора
/// </summary>
public string? HmiVersion { get; set; }
/// <summary>
/// версия ПО ПЛК САУБ
/// </summary>
public string? SaubPlcVersion { get; set; }
/// <summary>
/// версия ПО ПЛК Спин мастер
/// </summary>
public string? SpinPlcVersion { get; set; }
/// <summary>
/// версия ПО ПЛК Памп мастер
/// </summary>
public string? PumpPlcVersion { get; set; }
}

View File

@ -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; }
}

View 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; }
}

View File

@ -64,12 +64,12 @@ public interface ITelemetryService
Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token);
/// <summary>
/// Получить данные о телеметрии
/// Получить версии ПО
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token);
Task<IEnumerable<VersionDto>> GetVersionsAsync(VersionRequest request, CancellationToken token);
/// <summary>
/// Слить данные телеметрии в одну

View File

@ -78,43 +78,53 @@ public class TelemetryService : ITelemetryService
DropTelemetryCache();
}
public async Task<IEnumerable<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token)
public async Task<IEnumerable<VersionDto>> GetVersionsAsync(VersionRequest request, CancellationToken token)
{
var idTelemetries = await db.Set<Well>()
var query = db.Set<Well>()
.Include(x => x.RelationCompaniesWells)
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany) &&
x.IdState == request.IdWellState)
.Where(x => x.IdTelemetry.HasValue)
.Select(x => x.IdTelemetry!.Value)
.ToArrayAsync(token);
.ThenInclude(x => x.Company)
.Include(x => x.Cluster)
.ThenInclude(c => c.Deposit)
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany));
var key = $"TelemetryInfo_{string.Join("", idTelemetries)}";
if (request.IdWellState.HasValue)
query = query.Where(x => x.IdState == request.IdWellState);
var result = await memoryCache.GetOrCreateAsync(key, async entry =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
if (request.IdsWell?.Any() == true)
query = query.Where(x => request.IdsWell.Contains(x.Id));
var query = db.Set<Telemetry>()
var wells = await query.Where(x => x.IdTelemetry.HasValue)
.ToDictionaryAsync(x => x.Id, x => x, token);
var idTelemetries = wells.Select(x => x.Value.IdTelemetry!.Value);
var telemetries = GetTelemetryCache()
.Where(x => idTelemetries.Contains(x.Id))
.OrderBy(x => x.Info.DrillingStartDate);
var entities = await query
.AsNoTracking()
.ToArrayAsync(token);
var dtos = entities.Select(x =>
var dtos = telemetries.Select(x =>
{
var dto = x.Info.Adapt<TelemetryInfoDto>();
dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours);
var well = wells[x.Well!.Id];
var dto = new VersionDto
{
IdWell = well.Id,
Well = well.Caption,
Cluster = well.Cluster.Caption,
Deposit = well.Cluster.Deposit.Caption,
Customer = well.RelationCompaniesWells.Select(r => r.Company).FirstOrDefault(c => c.IdCompanyType == 1)?.Caption,
HmiVersion = x.Info.HmiVersion,
SaubPlcVersion = x.Info.SaubPlcVersion,
SpinPlcVersion = x.Info.SpinPlcVersion,
};
return dto;
});
return dtos;
});
return result!;
}
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
public SimpleTimezoneDto GetTimezone(int idTelemetry)
{

View File

@ -1,57 +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">Определяет состояние скважины
/// 0 - неизвестно,
/// 1 - в работе,
/// 2 - завершена</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet]
[Permission]
[ProducesResponseType(typeof(IEnumerable<TelemetryInfoDto>), 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);
}
}

View 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);
}
}