feat(api,core,dal,domain): Сохранение снапшотов состояния роботов.

This commit is contained in:
Mikhail Trubnikov
2026-06-10 16:48:16 +10:00
parent a64ab59de1
commit d736208a46
22 changed files with 4194 additions and 1 deletions

View File

@@ -256,6 +256,11 @@
public const string GetStatusesLastDay = BaseStat + "/orders/statuses/last-day/{statusCode}";
}
public static class StatRobotSnapshot
{
public const string Create = BaseStat + "/robot-snapshots/";
}
public static class StatRabbitMq
{
public const string GetQueueStats = BaseStat + "/rabbitmq-queues/";

View File

@@ -0,0 +1,11 @@
namespace PARR.API.Contracts.V1.Requests
{
public record StatRobotSnapshotCreateRequest
{
public int TemplateRobotsCount { get; set; }
public int ScheduleRobotsCount { get; set; }
public int MaxRobots { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
namespace PARR.API.Contracts.V1.Responses.Statistics
{
public record StatRobotSnapshotItemResponse
{
public Guid Id { get; init; }
public DateTimeOffset DateCreated { get; init; }
public int TemplateRobotsCount { get; init; }
public int ScheduleRobotsCount { get; init; }
public int MaxRobots { get; init; }
public required string Ip { get; init; }
}
}

View File

@@ -0,0 +1,52 @@
using AutoMapper;
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.Contracts.V1.Responses.Statistics;
using PARR.API.Controllers.V1.Base;
using PARR.API.Services.Interfaces;
using PARR.Core.Services.RobotSnapshotServices;
using PARR.Domain.Common.Roles;
using PARR.Domain.DTOs.RobotSnapshotDTO;
namespace PARR.API.Controllers.V1.Statistics
{
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class StatRobotSnapshotController : BaseApiController
{
private readonly IRobotSnapshotService robotSnapshotService;
private readonly IMapper mapper;
private readonly IClientService clientService;
public StatRobotSnapshotController(
IRobotSnapshotService robotSnapshotService,
IMapper mapper,
IClientService clientService
)
{
this.robotSnapshotService = robotSnapshotService;
this.mapper = mapper;
this.clientService = clientService;
}
/// <summary>
/// Отправить снапшот роботов.
/// Доступ только с ролью "Робот ЕСПП"
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Authorize(Roles = ParrRoles.EsppRobot.Role)]
[HttpPost(ApiRoutes.StatRobotSnapshot.Create)]
public async Task<IActionResult> Create([FromBody] StatRobotSnapshotCreateRequest request)
{
var obj = new CreateRobotSnapshot(request.TemplateRobotsCount, request.ScheduleRobotsCount, request.MaxRobots, clientService.GetClientIp()?.ToString() ?? "");
var snapshot = await robotSnapshotService.CreateAsync(obj);
return Created("", new Response<StatRobotSnapshotItemResponse>(mapper.Map<StatRobotSnapshotItemResponse>(snapshot), true));
}
}
}

View File

@@ -5,6 +5,7 @@ using PARR.API.Contracts.V1.Responses.Statistics;
using PARR.API.MappingProfiles.Resolvers;
using PARR.Core.Repositories.Interfaces.Schedule;
using PARR.Domain.DTOs.Matching;
using PARR.Domain.DTOs.RobotSnapshotDTO;
using PARR.Domain.DTOs.RobotTask;
using PARR.Domain.DTOs.Shortcode;
using PARR.Domain.DTOs.TaskDTO;
@@ -485,6 +486,9 @@ namespace PARR.API.MappingProfiles
#endregion
CreateMap<RobotSnapshotItem, StatRobotSnapshotItemResponse>();
}
}

View File

@@ -0,0 +1,23 @@
using FluentValidation;
using PARR.API.Contracts.V1.Requests;
namespace PARR.API.Validators
{
public class StatRobotSnapshotCreateRequestValidator: AbstractValidator<StatRobotSnapshotCreateRequest>
{
public StatRobotSnapshotCreateRequestValidator()
{
RuleFor(t => t.TemplateRobotsCount)
.GreaterThanOrEqualTo(0)
.WithMessage("Значение должно быть больше или равно нулю");
RuleFor(t => t.ScheduleRobotsCount)
.GreaterThanOrEqualTo(0)
.WithMessage("Значение должно быть больше или равно нулю");
RuleFor(t => t.MaxRobots)
.GreaterThanOrEqualTo(0)
.WithMessage("Значение должно быть больше или равно нулю");
}
}
}