diff --git a/PARR.DAL/Services/Implementations/RobotConfigurationService.cs b/PARR.DAL/Services/Implementations/RobotConfigurationService.cs index bbf72a2b..89067a6c 100644 --- a/PARR.DAL/Services/Implementations/RobotConfigurationService.cs +++ b/PARR.DAL/Services/Implementations/RobotConfigurationService.cs @@ -59,7 +59,7 @@ namespace PARR.DAL.Services.Implementations : $"Unknown ({taskStatusValue})"; logger.LogInformation("Нельзя установить статус {newStatus} для конфигурации {configurationId}, templateId: {templateId}, так как текущий статус {currentStatus}", - updatingStatus, configuration.Id, configuration.TemplateId, configuration.TaskStatusCode); + updatingStatus, configuration.Id, configuration.TemplateId, taskStatusName); return false; } diff --git a/PARR.TemplateMatcher/Services/Implemetaions/GroupedTemplateSynchronizer.cs b/PARR.TemplateMatcher/Services/Implemetaions/GroupedTemplateSynchronizer.cs index 2255ebf4..fbad266a 100644 --- a/PARR.TemplateMatcher/Services/Implemetaions/GroupedTemplateSynchronizer.cs +++ b/PARR.TemplateMatcher/Services/Implemetaions/GroupedTemplateSynchronizer.cs @@ -441,6 +441,11 @@ internal class GroupedTemplateSynchronizer : ITemplateSynchronizer var expectedName = await templateNameNormalizer.GetNormalizedTemplateNameAsync(tempTemplateForName); + //var existingTemplateByName = await templateService.Get().AsNoTracking() + // .FirstOrDefaultAsync(t => EF.Functions.ILike(t.Name, expectedName)); + //if (existingTemplateByName != null) + // logger.LogInformation("Переиспользован шаблон"); + var updateRequest = new TemplateUpdaterMq { TemplateId = reusableTemplate.Id, diff --git a/PARR.TemplateUpdater/Services/TemplateUpdaterService.cs b/PARR.TemplateUpdater/Services/TemplateUpdaterService.cs index 7fae5061..ce73801e 100644 --- a/PARR.TemplateUpdater/Services/TemplateUpdaterService.cs +++ b/PARR.TemplateUpdater/Services/TemplateUpdaterService.cs @@ -88,28 +88,6 @@ namespace PARR.TemplateUpdater.Services scheduleIsChanged = true; } - var nextRun = await nextRunService.GetNextRunForTemplateAsync(template.Id, query.IsNew); - if (!nextRun.HasValue) - { - logger.LogError("Ошибка при расчете нового nextRun (вернулся null) для шаблона {templateId}, {templateName}", template.Id, template.Name); - return; - } - - - //if (template.NextRun != query.NextRun) - //{ - // template.NextRun = query.NextRun; - // scheduleIsChanged = true; - //} - - if (template.NextRun != nextRun.Value) - { - template.LastRun = template.NextRun; - template.NextRun = nextRun.Value; - scheduleIsChanged = true; - } - - if (template.UnitId != query.UnitId) { template.UnitId = query.UnitId; @@ -151,6 +129,28 @@ namespace PARR.TemplateUpdater.Services // Поскольку коллекция изменилась — шаблон считается изменённым templateIsChanged = true; } + + //Для правильного расчета shortcod'ов в БД должны быть сохранены данные UnitInTemplates, JobId, UnitId и т.д. + if (templateIsChanged && !await templateService.CommitAsync(query.Initiator)) + { + logger.LogError("Не удалось сохранить изменения в БД. {QueryType}: {Query}", nameof(TemplateUpdaterMq), query.ToJson()); + return; + } + + var nextRun = await nextRunService.GetNextRunForTemplateAsync(template.Id, query.IsNew); + if (!nextRun.HasValue) + { + logger.LogError("Ошибка при расчете нового nextRun (вернулся null) для шаблона {templateId}, {templateName}", template.Id, template.Name); + return; + } + + if (template.NextRun != nextRun.Value) + { + template.LastRun = template.NextRun; + template.NextRun = nextRun.Value; + scheduleIsChanged = true; + } + // === конец обработки UnitsInTemplate === if (templateIsChanged)