From 3800cac97a03bfd8607bac46e190206a396322f9 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Fri, 27 Mar 2026 11:58:03 +1000 Subject: [PATCH] =?UTF-8?q?feat(templateUpdater):=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20=D0=B2=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B7=D1=83=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D1=8F=D0=B5=D0=BC=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B0=D1=81=D1=87=D0=B5=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B8=20=D0=B2=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=20=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RobotConfigurationService.cs | 2 +- .../GroupedTemplateSynchronizer.cs | 5 +++ .../Services/TemplateUpdaterService.cs | 44 +++++++++---------- 3 files changed, 28 insertions(+), 23 deletions(-) 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)