2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2023-12-04 09:38:42 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2023-10-25 16:03:07 +05:00
|
|
|
|
using AsbCloudInfrastructure.Background;
|
2023-10-30 12:13:38 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR.Clients;
|
2023-10-25 16:03:07 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-12-04 09:38:42 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-10-25 16:03:07 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-05-20 11:07:45 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi.SignalR;
|
|
|
|
|
|
|
|
|
|
// SignalR manual:
|
|
|
|
|
// https://docs.microsoft.com/ru-ru/aspnet/core/signalr/introduction?view=aspnetcore-5.0
|
|
|
|
|
//[SignalRHub]
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ReportsHub
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class ReportsHub : BaseHub<IReportHubClient>
|
2021-05-20 11:07:45 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
private readonly IReportService reportService;
|
|
|
|
|
|
|
|
|
|
public ReportsHub(IWellService wellService, IReportService reportService)
|
|
|
|
|
{
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.reportService = reportService;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 12:13:38 +05:00
|
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// Добавление в группу, отправка данных о формировании отчета
|
2023-10-30 12:13:38 +05:00
|
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <param name="groupName">группа</param>
|
|
|
|
|
/// <param name="idWell">ключ скважины</param>
|
|
|
|
|
/// <param name="request">параметры запроса</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task CreateReport(string groupName, int idWell, ReportParametersRequest request)
|
2021-05-20 11:07:45 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
void HandleReportProgressAsync(object progress, string id) =>
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await Clients.Group(groupName)
|
|
|
|
|
.GetReportProgress(progress, CancellationToken.None);
|
|
|
|
|
}, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
var id = reportService.EnqueueCreateReportWork(idWell, (int)idUser, request, HandleReportProgressAsync);
|
2021-05-20 11:07:45 +05:00
|
|
|
|
}
|
|
|
|
|
}
|