forked from ddrilling/AsbCloudServer
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:
commit
57e73eadd9
@ -66,4 +66,4 @@ public class TelemetryInfoDto
|
|||||||
/// комментарий
|
/// комментарий
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Comment { get; set; }
|
public string? Comment { get; set; }
|
||||||
}
|
}
|
54
AsbCloudApp/Data/SAUB/VersionDto.cs
Normal file
54
AsbCloudApp/Data/SAUB/VersionDto.cs
Normal 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; }
|
||||||
|
}
|
@ -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<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token);
|
Task<IEnumerable<VersionDto>> GetVersionsAsync(VersionRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Слить данные телеметрии в одну
|
/// Слить данные телеметрии в одну
|
||||||
|
@ -78,43 +78,53 @@ public class TelemetryService : ITelemetryService
|
|||||||
DropTelemetryCache();
|
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)
|
.Include(x => x.RelationCompaniesWells)
|
||||||
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany) &&
|
.ThenInclude(x => x.Company)
|
||||||
x.IdState == request.IdWellState)
|
.Include(x => x.Cluster)
|
||||||
.Where(x => x.IdTelemetry.HasValue)
|
.ThenInclude(c => c.Deposit)
|
||||||
.Select(x => x.IdTelemetry!.Value)
|
.Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany));
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
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 =>
|
if (request.IdsWell?.Any() == true)
|
||||||
{
|
query = query.Where(x => request.IdsWell.Contains(x.Id));
|
||||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
|
|
||||||
|
|
||||||
var query = db.Set<Telemetry>()
|
var wells = await query.Where(x => x.IdTelemetry.HasValue)
|
||||||
.Where(x => idTelemetries.Contains(x.Id))
|
.ToDictionaryAsync(x => x.Id, x => x, token);
|
||||||
.OrderBy(x => x.Info.DrillingStartDate);
|
|
||||||
|
|
||||||
var entities = await query
|
var idTelemetries = wells.Select(x => x.Value.IdTelemetry!.Value);
|
||||||
.AsNoTracking()
|
|
||||||
.ToArrayAsync(token);
|
|
||||||
|
|
||||||
var dtos = entities.Select(x =>
|
var telemetries = GetTelemetryCache()
|
||||||
|
.Where(x => idTelemetries.Contains(x.Id))
|
||||||
|
.OrderBy(x => x.Info.DrillingStartDate);
|
||||||
|
|
||||||
|
var dtos = telemetries.Select(x =>
|
||||||
|
{
|
||||||
|
var well = wells[x.Well!.Id];
|
||||||
|
|
||||||
|
var dto = new VersionDto
|
||||||
{
|
{
|
||||||
var dto = x.Info.Adapt<TelemetryInfoDto>();
|
IdWell = well.Id,
|
||||||
dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours);
|
Well = well.Caption,
|
||||||
return dto;
|
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 dtos;
|
return dto;
|
||||||
});
|
});
|
||||||
|
|
||||||
return result!;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
|
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
|
||||||
public SimpleTimezoneDto GetTimezone(int idTelemetry)
|
public SimpleTimezoneDto GetTimezone(int idTelemetry)
|
||||||
{
|
{
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
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