forked from ddrilling/AsbCloudServer
TelemetryService Add GetTelemetriesInfoByLastData(). Remote software versions
This commit is contained in:
parent
15cbb255f9
commit
8221a5d309
@ -1,5 +1,8 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -67,5 +70,6 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> MergeAsync(int from, int to, CancellationToken token);
|
||||
Task<Stream> GetTelemetriesInfoByLastData(DateTimeOffset from, CancellationToken token);
|
||||
}
|
||||
}
|
@ -9,7 +9,9 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Csv;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -153,6 +155,41 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
return telemetry;
|
||||
}
|
||||
|
||||
public async Task<Stream> GetTelemetriesInfoByLastData(DateTimeOffset from, CancellationToken token)
|
||||
{
|
||||
var fromUtc = from.UtcDateTime;
|
||||
var query = db.TelemetryDataSaub
|
||||
.Where(i => i.DateTime >= fromUtc)
|
||||
.GroupBy(i => i.IdTelemetry)
|
||||
.Select(i => new
|
||||
{
|
||||
i.First().Telemetry,
|
||||
LastDate = i.Max(i => i.DateTime)
|
||||
});
|
||||
|
||||
var data = await query.ToArrayAsync(token);
|
||||
|
||||
var infos = data.Select(i => new TelemetryWithSoftwareVersionsDto(
|
||||
i.Telemetry.Id,
|
||||
i.Telemetry.RemoteUid,
|
||||
i.LastDate,
|
||||
i.Telemetry.Info.Deposit,
|
||||
i.Telemetry.Info.Cluster,
|
||||
i.Telemetry.Info.Well,
|
||||
i.Telemetry.Info.HmiVersion,
|
||||
i.Telemetry.Info.SaubPlcVersion,
|
||||
i.Telemetry.Info.SpinPlcVersion)
|
||||
);
|
||||
var stream = new MemoryStream();
|
||||
if (!data.Any())
|
||||
return stream;
|
||||
|
||||
var serializer = new CsvSerializer<TelemetryWithSoftwareVersionsDto>();
|
||||
serializer.Serialize(infos, stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return stream;
|
||||
}
|
||||
|
||||
public async Task<int> MergeAsync(int from, int to, CancellationToken token)
|
||||
{
|
||||
if (from == to)
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.SAUB;
|
||||
|
||||
internal record TelemetryWithSoftwareVersionsDto(int Id,
|
||||
string RemoteUid,
|
||||
DateTimeOffset LastData,
|
||||
string Deposit,
|
||||
string Cluster,
|
||||
string Well,
|
||||
string? HmiVersion,
|
||||
string? SaubPlcVersion,
|
||||
string? SpinPlcVersion);
|
@ -3,7 +3,9 @@ using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -37,6 +39,19 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
this.telemetryHubContext = telemetryHubContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Информация о версиях ПО по телеметриям, данные от которых приходили не позднее From
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Active")]
|
||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetTelemetriesInfoByLastData(CancellationToken token)
|
||||
{
|
||||
var from = DateTimeOffset.UtcNow.AddDays(-1);
|
||||
var stream = await telemetryService.GetTelemetriesInfoByLastData(from, token);
|
||||
return File(stream, "text/csv", $"Software versions by active telemetries from {from :yy-MM-dd hh-mm}.csv");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Принимает общую информацию по скважине
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user