2024-07-05 12:42:01 +10:00
|
|
|
|
using FluentValidation;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using PARR.API.Contracts.V1;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Requests;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Responses.Base;
|
|
|
|
|
|
using PARR.API.Controllers.V1.Base;
|
2026-01-22 10:35:27 +10:00
|
|
|
|
using PARR.API.Services.Interfaces;
|
2024-07-05 12:42:01 +10:00
|
|
|
|
using PARR.API.Settings;
|
2026-04-14 16:27:27 +10:00
|
|
|
|
using PARR.Core.Common.Interfaces.RabbitServices;
|
2026-04-14 12:01:49 +10:00
|
|
|
|
using PARR.Domain.Common.Rabbit.Messages;
|
|
|
|
|
|
using PARR.Domain.Common.Roles;
|
2026-04-13 16:58:30 +10:00
|
|
|
|
using PARR.Domain.Entities.Base.History;
|
|
|
|
|
|
using PARR.Domain.Enums;
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Controllers.V1
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Распределитель РР
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
|
|
|
|
|
public class DistributorController : BaseApiController
|
|
|
|
|
|
{
|
2026-04-14 12:01:49 +10:00
|
|
|
|
private readonly IRabbitService mqService;
|
2024-07-05 12:42:01 +10:00
|
|
|
|
private readonly MqSettings mqSettings;
|
2026-05-19 16:52:33 +10:00
|
|
|
|
//private readonly IValidator<DistributeRequest> validator;
|
2026-01-22 10:35:27 +10:00
|
|
|
|
private readonly IClientService clientService;
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
|
|
|
|
|
public DistributorController(
|
2026-04-14 12:01:49 +10:00
|
|
|
|
IRabbitService mqService,
|
2024-07-05 12:42:01 +10:00
|
|
|
|
MqSettings mqSettings,
|
2026-05-19 16:52:33 +10:00
|
|
|
|
//IValidator<DistributeRequest> validator,
|
2026-01-22 10:35:27 +10:00
|
|
|
|
IClientService clientService
|
2024-07-05 12:42:01 +10:00
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.mqService = mqService;
|
|
|
|
|
|
this.mqSettings = mqSettings;
|
2026-05-19 16:52:33 +10:00
|
|
|
|
//this.validator = validator;
|
2026-01-22 10:35:27 +10:00
|
|
|
|
this.clientService = clientService;
|
2024-07-05 12:42:01 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-01-21 16:28:17 +10:00
|
|
|
|
/// Перераспределить шаблоны для группы работ
|
2024-07-05 12:42:01 +10:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost(ApiRoutes.Distributor.Distribute)]
|
|
|
|
|
|
public async Task<IActionResult> Distribute([FromBody] DistributeRequest request)
|
|
|
|
|
|
{
|
2026-05-19 16:52:33 +10:00
|
|
|
|
//var resultValidate = await validator.ValidateAsync(request);
|
|
|
|
|
|
//if (!resultValidate.IsValid)
|
|
|
|
|
|
// return BadRequest(new Response(resultValidate.Errors));
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
|
|
|
|
|
var requestToMq = new TemplateDistributorMq
|
|
|
|
|
|
{
|
2026-01-22 10:35:27 +10:00
|
|
|
|
JobGroupId = request.JobGroupId,
|
|
|
|
|
|
Initiator = new HistoryInitiator
|
|
|
|
|
|
{
|
|
|
|
|
|
InitiatorComment = "Через API отправлен запрос на распределение шаблонов",
|
|
|
|
|
|
InitiatorIp = clientService.GetClientIp()?.ToString(),
|
|
|
|
|
|
InitiatorParrComponentId = ParrComponentsEnum.Api
|
|
|
|
|
|
}
|
2024-07-05 12:42:01 +10:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-01-22 10:35:27 +10:00
|
|
|
|
//var jsonOptions = new JsonSerializerOptions
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
|
|
|
|
|
//};
|
|
|
|
|
|
//var msg = JsonSerializer.Serialize(requestToMq, jsonOptions);
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
2026-01-22 10:35:27 +10:00
|
|
|
|
//var sendResult = await mqService.SendAsync(mqSettings.TemplateDistributor, new[] { msg });
|
|
|
|
|
|
var sendResult = await mqService.SendAsync(mqSettings.TemplateDistributor, new List<object> { requestToMq });
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
|
|
|
|
|
if (sendResult.IsSuccess)
|
|
|
|
|
|
return Created("", new Response<string?>(null, true, new List<ErrorModel>(), "Отправлен запрос на перераспределение регламентных работ."));
|
|
|
|
|
|
else
|
2026-01-21 16:28:17 +10:00
|
|
|
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при отправке данных." } }));
|
2024-07-05 12:42:01 +10:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|