2026-02-27 16:37:52 +10:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using PARR.API.Contracts.V1;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Responses.Base;
|
|
|
|
|
|
using PARR.API.Controllers.V1.Base;
|
|
|
|
|
|
using PARR.API.Settings;
|
2026-04-14 16:27:27 +10:00
|
|
|
|
using PARR.Core.Common.Interfaces.RabbitServices;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
using PARR.Core.Repositories.Interfaces.Job;
|
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;
|
2026-02-27 16:37:52 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Controllers.V1
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Пересчитать все nextRun для JobGroup
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
|
|
|
|
|
public class JobGroupUpdateNextRunController : BaseApiController
|
|
|
|
|
|
{
|
2026-04-14 12:01:49 +10:00
|
|
|
|
private readonly IRabbitService mqService;
|
2026-02-27 16:37:52 +10:00
|
|
|
|
private readonly MqSettings mqSettings;
|
2026-04-30 10:35:31 +10:00
|
|
|
|
private readonly IJobGroupRepository jobGroupService;
|
2026-02-27 16:37:52 +10:00
|
|
|
|
|
|
|
|
|
|
public JobGroupUpdateNextRunController(
|
2026-04-14 12:01:49 +10:00
|
|
|
|
IRabbitService mqService,
|
2026-02-27 16:37:52 +10:00
|
|
|
|
MqSettings mqSettings,
|
2026-04-30 10:35:31 +10:00
|
|
|
|
IJobGroupRepository jobGroupService
|
2026-02-27 16:37:52 +10:00
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.mqService = mqService;
|
|
|
|
|
|
this.mqSettings = mqSettings;
|
|
|
|
|
|
this.jobGroupService = jobGroupService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Обновить nextRun для всех шаблонах в JobGroup
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost(ApiRoutes.JobGroupUpdateNextRun.UpdateNextRun)]
|
|
|
|
|
|
public async Task<IActionResult> UpdateNextRun([FromRoute] Guid jobGroupId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var jobGroup = await jobGroupService.Get().AnyAsync(t => t.Id == jobGroupId);
|
|
|
|
|
|
if (!jobGroup)
|
|
|
|
|
|
return BadRequest(new Response<string?>(null, false, new List<ErrorModel> { new ErrorModel { Message = "Не найдена группа работ с ИД" } }));
|
|
|
|
|
|
|
|
|
|
|
|
var requestToMq = new NextRunUpdateMq
|
|
|
|
|
|
{
|
|
|
|
|
|
JobGroupId = jobGroupId,
|
|
|
|
|
|
Initiator = new HistoryInitiator
|
|
|
|
|
|
{
|
|
|
|
|
|
InitiatorComment = "Вручную отправлен запрос на обновление nextRun для группы работ",
|
|
|
|
|
|
InitiatorParrComponentId = ParrComponentsEnum.Api
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var sendResult = await mqService.SendAsync(mqSettings.NextRun, new List<object> { requestToMq });
|
|
|
|
|
|
|
|
|
|
|
|
if (sendResult.IsSuccess)
|
|
|
|
|
|
return Created("", new Response<string?>(null, true, new List<ErrorModel>(), "Отправлен запрос на расчет nextRun для группы работ."));
|
|
|
|
|
|
else
|
|
|
|
|
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при отправке данных." } }));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|