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

Reviewed-on: https://test.digitaldrilling.ru:8443/DDrilling/AsbCloudServer/pulls/312
This commit is contained in:
Никита Фролов 2024-08-22 15:45:38 +05:00
commit fe798d8d66
10 changed files with 12561 additions and 4 deletions

View File

@ -58,7 +58,12 @@ public class TelemetryInfoDto
public string? SpinPlcVersion { get; set; } public string? SpinPlcVersion { get; set; }
/// <summary> /// <summary>
/// комментарий /// версия ПО ПЛК Памп мастер
/// </summary> /// </summary>
public string? Comment { get; set; } public string? PumpPlcVersion { get; set; }
/// <summary>
/// комментарий
/// </summary>
public string? Comment { get; set; }
} }

View File

@ -0,0 +1,20 @@
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

@ -1,5 +1,6 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Requests;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -62,6 +63,14 @@ public interface ITelemetryService
/// <returns></returns> /// <returns></returns>
Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token); 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);
/// <summary> /// <summary>
/// Слить данные телеметрии в одну /// Слить данные телеметрии в одну
/// </summary> /// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
/// <inheritdoc />
public partial class Add_New_Permission : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "t_permission",
columns: new[] { "id", "description", "name" },
values: new object[] { 532, "Разрешение просматривать информацию о телеметрии", "TelemetryInfo.get" });
migrationBuilder.InsertData(
table: "t_relation_user_role_permission",
columns: new[] { "id_permission", "id_user_role" },
values: new object[] { 532, 1 });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "t_relation_user_role_permission",
keyColumns: new[] { "id_permission", "id_user_role" },
keyValues: new object[] { 532, 1 });
migrationBuilder.DeleteData(
table: "t_permission",
keyColumn: "id",
keyValue: 532);
}
}
}

View File

@ -2626,6 +2626,12 @@ namespace AsbCloudDb.Migrations
Id = 531, Id = 531,
Description = "Разрешение на удаление плановой конструкции скважины", Description = "Разрешение на удаление плановой конструкции скважины",
Name = "WellSectionPlan.delete" Name = "WellSectionPlan.delete"
},
new
{
Id = 532,
Description = "Разрешение просматривать информацию о телеметрии",
Name = "TelemetryInfo.get"
}); });
}); });
@ -6366,6 +6372,11 @@ namespace AsbCloudDb.Migrations
{ {
IdUserRole = 1, IdUserRole = 1,
IdPermission = 531 IdPermission = 531
},
new
{
IdUserRole = 1,
IdPermission = 532
}); });
}); });

View File

@ -163,7 +163,9 @@ namespace AsbCloudDb.Model.DefaultData
new() { Id = 528, Name = "WellContact.delete", Description = "Разрешение на удаление контакта" }, new() { Id = 528, Name = "WellContact.delete", Description = "Разрешение на удаление контакта" },
new() { Id = 530, Name = "WellSectionPlan.edit", Description = "Разрешение на редактирование плановой конструкции скважины"}, new() { Id = 530, Name = "WellSectionPlan.edit", Description = "Разрешение на редактирование плановой конструкции скважины"},
new() { Id = 531, Name = "WellSectionPlan.delete", Description = "Разрешение на удаление плановой конструкции скважины"} new() { Id = 531, Name = "WellSectionPlan.delete", Description = "Разрешение на удаление плановой конструкции скважины"},
new() { Id = 532, Name = "TelemetryInfo.get", Description = "Разрешение просматривать информацию о телеметрии"}
}; };
} }
} }

View File

@ -14,6 +14,7 @@ namespace AsbCloudDb.Model
public string? HmiVersion { get; set; } public string? HmiVersion { get; set; }
public string? SaubPlcVersion { get; set; } public string? SaubPlcVersion { get; set; }
public string? SpinPlcVersion { get; set; } public string? SpinPlcVersion { get; set; }
public string? PumpPlcVersion { get; set; }
public string? Comment { get; set; } public string? Comment { get; set; }
} }
} }

View File

@ -14,6 +14,7 @@ using System.Linq;
using System.Text.Csv; using System.Text.Csv;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsbCloudApp.Requests;
namespace AsbCloudInfrastructure.Services.SAUB; namespace AsbCloudInfrastructure.Services.SAUB;
@ -24,7 +25,6 @@ public class TelemetryService : ITelemetryService
//TODO: методы использующие ITelemetryDataCache, скорее всего, тут не нужны //TODO: методы использующие ITelemetryDataCache, скорее всего, тут не нужны
private readonly ITelemetryDataCache<TelemetryDataSaubDto> dataSaubCache; private readonly ITelemetryDataCache<TelemetryDataSaubDto> dataSaubCache;
private readonly ITimezoneService timezoneService; private readonly ITimezoneService timezoneService;
public ITimezoneService TimeZoneService => timezoneService; public ITimezoneService TimeZoneService => timezoneService;
public TelemetryService( public TelemetryService(
@ -78,6 +78,43 @@ public class TelemetryService : ITelemetryService
DropTelemetryCache(); DropTelemetryCache();
} }
public async Task<IEnumerable<TelemetryInfoDto>> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token)
{
var idTelemetries = await 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);
var key = $"TelemetryInfo_{string.Join("", idTelemetries)}";
var result = await memoryCache.GetOrCreateAsync(key, async entry =>
{
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.")] [Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
public SimpleTimezoneDto GetTimezone(int idTelemetry) public SimpleTimezoneDto GetTimezone(int idTelemetry)
{ {

View File

@ -0,0 +1,57 @@
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);
}
}