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

@@ -7,6 +7,7 @@ using PARR.Core.Common.Interfaces;
using PARR.Core.Services.MatchingStatusService;
using PARR.Core.Services.NextRunServices;
using PARR.Core.Services.NextRunServices.Subservices;
using PARR.Core.Services.RobotSnapshotServices;
using PARR.Core.Services.RobotTask.Implementations;
using PARR.Core.Services.RobotTask.Interfaces;
using PARR.Core.Services.Shortcodes;
@@ -105,6 +106,7 @@ namespace PARR.Core
services.AddTransient<IMatchingStatusService, MatchingStatusService>();
services.AddScoped<IRobotTaskService, RobotTaskService>();
services.AddScoped<IRobotSnapshotService, RobotSnapshotService>();
services.AddScoped<IUnitService, UnitService>();
services.AddScoped<UnitCacheService>();

View File

@@ -0,0 +1,13 @@
using AutoMapper;
using PARR.Domain.DTOs.RobotSnapshotDTO;
namespace PARR.Core.Infrastructure.Mapping.RobotSnapshot
{
public class RobotSnapshotMappingProfile : Profile
{
public RobotSnapshotMappingProfile()
{
CreateMap<PARR.Domain.Entities.RobotEntities.RobotSnapshot, RobotSnapshotItem>();
}
}
}

View File

@@ -0,0 +1,9 @@
using PARR.Core.Repositories.Base;
using PARR.Domain.Entities.RobotEntities;
namespace PARR.Core.Repositories.Interfaces.RobotRepositories
{
public interface IRobotSnapshotRepository : IBaseRepository<RobotSnapshot>
{
}
}

View File

@@ -0,0 +1,9 @@
using PARR.Domain.DTOs.RobotSnapshotDTO;
namespace PARR.Core.Services.RobotSnapshotServices
{
public interface IRobotSnapshotService
{
Task<RobotSnapshotItem> CreateAsync(CreateRobotSnapshot robotSnapshot);
}
}

View File

@@ -0,0 +1,46 @@
using AutoMapper;
using PARR.Core.Repositories.Interfaces.RobotRepositories;
using PARR.Domain.DTOs.RobotSnapshotDTO;
using PARR.Domain.Entities.RobotEntities;
using PARR.Domain.Exceptions;
namespace PARR.Core.Services.RobotSnapshotServices
{
internal class RobotSnapshotService : IRobotSnapshotService
{
private readonly IRobotSnapshotRepository robotSnapshotRepository;
private readonly IMapper mapper;
public RobotSnapshotService(
IRobotSnapshotRepository robotSnapshotRepository,
IMapper mapper
)
{
this.robotSnapshotRepository = robotSnapshotRepository;
this.mapper = mapper;
}
public async Task<RobotSnapshotItem> CreateAsync(CreateRobotSnapshot robotSnapshot)
{
var snapshot = new RobotSnapshot
{
Id = Guid.NewGuid(),
TemplateRobotsCount = robotSnapshot.TemplateRobotsCount,
ScheduleRobotsCount = robotSnapshot.ScheduleRobotsCount,
MaxRobots = robotSnapshot.MaxRobots,
Ip = robotSnapshot.Ip
};
var createdResult = await robotSnapshotRepository.CreateAsync(snapshot);
var commitResult = await robotSnapshotRepository.CommitAsync();
if (!createdResult || !commitResult)
throw new DbErrorException("Ошибка сохранения в БД");
return mapper.Map<RobotSnapshotItem>(snapshot);
}
}
}