fix(templateGenerator): Исправлена ошибка преобразования сообщений из RabbitMq

This commit is contained in:
Mikhail Kuznetsov
2026-05-14 18:06:19 +10:00
parent 90e6352117
commit 4dc89ffd2d
2 changed files with 6 additions and 13 deletions

View File

@@ -2,6 +2,6 @@
{ {
public interface IValidatorService public interface IValidatorService
{ {
Task<bool> IsValidAsync(Guid jobId, Guid unitId, int? index, List<Guid>? unitsInTemplate = null); Task<bool> IsValidAsync(Guid jobId, Guid unitId, int? index, List<(Guid UnitId, Guid UnitFieldValueId)>? unitsInTemplate = null);
} }
} }

View File

@@ -23,9 +23,6 @@ namespace PARR.TemplateGeneratorWorker
private readonly ITemplateRepository templateService; private readonly ITemplateRepository templateService;
private readonly INextRunService nextRunService; private readonly INextRunService nextRunService;
//private readonly INextRunService nextRunService;
//private readonly IEsppScheduleTransformService esppScheduleTransformService;
public TemplateGenerator( public TemplateGenerator(
ILogger<TemplateGenerator> logger, ILogger<TemplateGenerator> logger,
@@ -35,8 +32,6 @@ namespace PARR.TemplateGeneratorWorker
IShortcodesService shortcodesService, IShortcodesService shortcodesService,
ITemplateRepository templateService, ITemplateRepository templateService,
INextRunService nextRunService INextRunService nextRunService
//INextRunService nextRunService
//IEsppScheduleTransformService esppScheduleTransformService
) )
{ {
this.logger = logger; this.logger = logger;
@@ -46,10 +41,9 @@ namespace PARR.TemplateGeneratorWorker
this.shortcodesService = shortcodesService; this.shortcodesService = shortcodesService;
this.templateService = templateService; this.templateService = templateService;
this.nextRunService = nextRunService; this.nextRunService = nextRunService;
//this.nextRunService = nextRunService;
//this.esppScheduleTransformService = esppScheduleTransformService;
} }
public async Task GenerateTemplateAsync(string msg) public async Task GenerateTemplateAsync(string msg)
{ {
logger.LogInformation($"Получили запрос: {msg}"); logger.LogInformation($"Получили запрос: {msg}");
@@ -63,7 +57,8 @@ namespace PARR.TemplateGeneratorWorker
} }
// Проверяем всё // Проверяем всё
if (!await validatorService.IsValidAsync(query.JobId, query.UnitId, query.Index, query.UnitsInTemplate)) var unitsInTemplate = query.UnitsInTemplate.Select(s => (s.UnitId, s.UnitFieldValueId)).ToList();
if (!await validatorService.IsValidAsync(query.JobId, query.UnitId, query.Index, unitsInTemplate))
{ {
logger.LogError($"Параметры запроса не прошли валидацию: JobId={query.JobId}, UnitId={query.UnitId}, Index={query.Index}, UnitsInTemplateCount={query.UnitsInTemplate?.Count ?? 0}"); logger.LogError($"Параметры запроса не прошли валидацию: JobId={query.JobId}, UnitId={query.UnitId}, Index={query.Index}, UnitsInTemplateCount={query.UnitsInTemplate?.Count ?? 0}");
return; return;
@@ -98,15 +93,13 @@ namespace PARR.TemplateGeneratorWorker
Index = query.Index, Index = query.Index,
Job = job, Job = job,
Unit = null, // ShortcodesService сам догрузит при необходимости Unit = null, // ShortcodesService сам догрузит при необходимости
UnitsInTemplate = query.UnitsInTemplate?.Select(unitId => new UnitsInTemplate { UnitId = unitId }).ToList() ?? new List<UnitsInTemplate>() UnitsInTemplate = query.UnitsInTemplate?.Select(uit => new UnitsInTemplate { UnitId = uit.UnitId, UnitFieldValueId = uit.UnitFieldValueId }).ToList() ?? new List<UnitsInTemplate>()
}; };
var templateName = await shortcodesService.ApplyShortcodesAsync(job.TemplateNameMask!, tempTemplateForShortcodes); var templateName = await shortcodesService.ApplyShortcodesAsync(job.TemplateNameMask!, tempTemplateForShortcodes);
var responseArea = await shortcodesService.ApplyShortcodesAsync(job.ResponseAreaMask, tempTemplateForShortcodes); var responseArea = await shortcodesService.ApplyShortcodesAsync(job.ResponseAreaMask, tempTemplateForShortcodes);
var workGroup = await shortcodesService.ApplyShortcodesAsync(job.WorkGroupMask, tempTemplateForShortcodes); var workGroup = await shortcodesService.ApplyShortcodesAsync(job.WorkGroupMask, tempTemplateForShortcodes);
//var nextRun = await esppScheduleTransformService.GetNextDateAsync(job.GroupId, job.Group!.ReferenceDate);
//var nextRun = await nextRunService.GetNextRunForNewTemplateAsync(job.GroupId, responseArea);
var nextRun = await nextRunService.GetNextRunForNewTemplateAsync(job.GroupId, workGroup, responseArea); var nextRun = await nextRunService.GetNextRunForNewTemplateAsync(job.GroupId, workGroup, responseArea);
if (!nextRun.HasValue) if (!nextRun.HasValue)
@@ -128,7 +121,7 @@ namespace PARR.TemplateGeneratorWorker
InitiatorComment = query.HistoryInitiator?.InitiatorComment, InitiatorComment = query.HistoryInitiator?.InitiatorComment,
InitiatorParrComponentId = query.HistoryInitiator?.InitiatorParrComponentId, InitiatorParrComponentId = query.HistoryInitiator?.InitiatorParrComponentId,
Index = query.Index, Index = query.Index,
UnitsInTemplate = query.UnitsInTemplate?.Select(unitId => new UnitsInTemplate { UnitId = unitId }).ToList() ?? new List<UnitsInTemplate>() UnitsInTemplate = query.UnitsInTemplate?.Select(uit => new UnitsInTemplate { UnitId = uit.UnitId, UnitFieldValueId = uit.UnitFieldValueId }).ToList() ?? new List<UnitsInTemplate>()
}; };
if (await templateService.CreateAsync(template) && await templateService.CommitAsync(new HistoryInitiator { InitiatorComment = "Запрос на генерацию с тестового шаблона", InitiatorParrComponentId = ParrComponentsEnum.TemplateTaskGenerator })) if (await templateService.CreateAsync(template) && await templateService.CommitAsync(new HistoryInitiator { InitiatorComment = "Запрос на генерацию с тестового шаблона", InitiatorParrComponentId = ParrComponentsEnum.TemplateTaskGenerator }))