fix(API,DAL): Восстановлена работа контроллеров RobotTask, TemplateActivator, Template

This commit is contained in:
Mikhail Kuznetsov
2025-06-27 13:42:13 +10:00
parent 03c7852378
commit 91ddd2ae96
12 changed files with 71 additions and 65 deletions

View File

@@ -28,21 +28,18 @@ namespace PARR.API.Controllers.V1
{
private readonly IMapper mapper;
private readonly ITemplateService templateService;
private readonly SettingsFromDb settingsFromDb;
private readonly IRobotConfigurationService robotConfigurationService;
private readonly IClientService clientService;
public TemplateController(
IMapper mapper,
ITemplateService templateService,
SettingsFromDb settingsFromDb,
IRobotConfigurationService robotConfigurationService,
IClientService clientService
)
{
this.mapper = mapper;
this.templateService = templateService;
this.settingsFromDb = settingsFromDb;
this.robotConfigurationService = robotConfigurationService;
this.clientService = clientService;
}
@@ -58,7 +55,9 @@ namespace PARR.API.Controllers.V1
{
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
IQueryable<Template> query = templateService.GetWithIncludes()
IQueryable<Template> query = templateService.GetWithIncludes().AsNoTracking()
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
@@ -70,8 +69,8 @@ namespace PARR.API.Controllers.V1
if (!string.IsNullOrEmpty(filter.Mask))
query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(filter.Mask)));
if (filter.AppInWorkId.HasValue)
query = query.Where(t => t.JobId == filter.AppInWorkId.Value);//TODO Migration to job
if (filter.JobGroupId.HasValue)
query = query.Where(t => t.Job!.GroupId == filter.JobGroupId.Value);
var templates = await templateService.GetPage(query, paginationFilter).ToListAsync();
@@ -92,7 +91,9 @@ namespace PARR.API.Controllers.V1
[HttpGet(ApiRoutes.Template.Get)]
public async Task<IActionResult> GetById([FromRoute] Guid id)
{
var template = await templateService.GetWithIncludes()
var template = await templateService.GetWithIncludes().AsNoTracking()
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
@@ -118,6 +119,8 @@ namespace PARR.API.Controllers.V1
public async Task<IActionResult> ChangeState([FromRoute] Guid id, [FromBody] TemplateChangeStateRequest request)
{
var template = await templateService.GetWithIncludes()
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
@@ -147,7 +150,9 @@ namespace PARR.API.Controllers.V1
if (!await templateService.CommitAsync(new HistoryInitiator { InitiatorComment = "Изменён статус шаблона/расписания", InitiatorIp = clientService.GetClientIp()?.ToString(), InitiatorParrComponentId = ParrComponentsEnum.Api }))
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при изменении шаблона." } }));
var templateToResponse = await templateService.GetWithIncludes()
var templateToResponse = await templateService.GetWithIncludes().AsNoTracking()
.Include(t => t.Unit).ThenInclude(t => t.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)