From 82e7ff8cb460e99442cb1cba626dc5848735b08a Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 4 Dec 2023 09:38:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D1=82=D0=BE=D0=B4=20CreateReport?= =?UTF-8?q?=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8=20ReportsHub=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=81=D0=BA=D0=B0=D1=87=D0=B8=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0=20=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=B4=D0=BD=D0=BE=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudWebApi/SignalR/ReportsHub.cs | 52 ++++++++++++++++------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/AsbCloudWebApi/SignalR/ReportsHub.cs b/AsbCloudWebApi/SignalR/ReportsHub.cs index bb0da640..ac19dc97 100644 --- a/AsbCloudWebApi/SignalR/ReportsHub.cs +++ b/AsbCloudWebApi/SignalR/ReportsHub.cs @@ -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 { - 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; } /// /// Добавление в группу, отправка данных о формировании отчета /// - /// + /// группа + /// ключ скважины + /// параметры запроса /// - 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).ConfigureAwait(false)) + 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); } } }