Merge pull request '#23919905 - Баг с выгрузкой рапорта в "Диаграммах"' (#164) from fix/#23919905-daily-diagram-create-report-from-signalr into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/164
Reviewed-by: Никита Фролов <ng.frolov@digitaldrilling.ru>
This commit is contained in:
Никита Фролов 2023-12-05 12:05:28 +05:00
commit 8ec901736b

View File

@ -1,8 +1,9 @@
using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Background;
using AsbCloudWebApi.SignalR.Clients;
using Microsoft.AspNetCore.Authorization;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using System.Threading;
using System.Threading.Tasks;
@ -17,39 +18,44 @@ namespace AsbCloudWebApi.SignalR
[Authorize]
public class ReportsHub : BaseHub<IReportHubClient>
{
private readonly BackgroundWorker backgroundWorker;
private readonly IWellService wellService;
private readonly IReportService reportService;
public ReportsHub(BackgroundWorker backgroundWorker)
public ReportsHub(IWellService wellService, IReportService reportService)
{
this.backgroundWorker = backgroundWorker;
this.wellService = wellService;
this.reportService = reportService;
}
/// <summary>
/// Добавление в группу, отправка данных о формировании отчета
/// </summary>
/// <param name="groupName"></param>
/// <param name="groupName">группа</param>
/// <param name="idWell">ключ скважины</param>
/// <param name="request">параметры запроса</param>
/// <returns></returns>
public override async Task AddToGroup(string groupName)
public async Task CreateReport(string groupName, int idWell, ReportParametersRequest request)
{
var idUser = Context.User?.GetUserId();
var idCompany = Context.User?.GetCompanyId();
if ((idCompany is null) || (idUser is null))
return;
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, CancellationToken.None))
return;
await base.AddToGroup(groupName);
var workId = groupName.Replace("Report_", "");
var work = backgroundWorker.Works.FirstOrDefault(work => work.Id == workId);
void HandleReportProgressAsync(object progress, string id) =>
Task.Run(async () =>
{
await Clients.Group(groupName)
.GetReportProgress(progress, CancellationToken.None);
}, CancellationToken.None);
var progress = new ReportProgressDto()
{
Operation = "Ожидает начала в очереди.",
Progress = 0f,
};
var state = work?.CurrentState;
if (state is not null)
{
progress.Operation = state.State;
progress.Progress = (float)state.Progress;
}
await Clients.Group(groupName).GetReportProgress(progress, CancellationToken.None);
var id = reportService.EnqueueCreateReportWork(idWell, (int)idUser,
request.StepSeconds, request.Format, request.Begin, request.End, HandleReportProgressAsync);
}
}
}