From e02a51f5ed6a88256f1368969797bde28d915e62 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Tue, 8 Sep 2026 09:47:31 +1000 Subject: [PATCH] =?UTF-8?q?fix(shortcodesService):=20=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=B7=D0=BA=D0=B0=20=D1=88=D0=BE=D1=80=D1=82=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20%=D0=A2=D0=95=D0=93=5F=D0=A1=D0=92=D0=AF?= =?UTF-8?q?=D0=97=D0=98:...%=20-=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=BE=D0=B2=D0=B0=D0=BB=D0=BE=20=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=B1=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20UnitsInTemplate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RelatedUnitTagShortcodeHandler.cs | 2 +- .../Services/Shortcodes/ShortcodesService.cs | 25 ++++++++++++++----- .../Implementations/TemplateMatcher.cs | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/PARR.Core/Services/Shortcodes/Handlers/RelatedUnitTagShortcodeHandler.cs b/PARR.Core/Services/Shortcodes/Handlers/RelatedUnitTagShortcodeHandler.cs index 3eb43e5a..e35016ca 100644 --- a/PARR.Core/Services/Shortcodes/Handlers/RelatedUnitTagShortcodeHandler.cs +++ b/PARR.Core/Services/Shortcodes/Handlers/RelatedUnitTagShortcodeHandler.cs @@ -14,7 +14,7 @@ internal class RelatedUnitTagShortcodeHandler : IShortcodeHandler private static readonly Regex _pattern = new(@"%ТЕГ_СВЯЗИ:([^%]+)%", RegexOptions.Compiled | RegexOptions.IgnoreCase); public Regex Pattern => _pattern; - public ShortcodeDataRequirementsEnum Requirements => ShortcodeDataRequirementsEnum.UnitsInTemplateTags; + public ShortcodeDataRequirementsEnum Requirements => ShortcodeDataRequirementsEnum.UnitsInTemplateTags | ShortcodeDataRequirementsEnum.UnitsInTemplate; public RelatedUnitTagShortcodeHandler(ILogger logger) { diff --git a/PARR.Core/Services/Shortcodes/ShortcodesService.cs b/PARR.Core/Services/Shortcodes/ShortcodesService.cs index 39ac1007..90b7c946 100644 --- a/PARR.Core/Services/Shortcodes/ShortcodesService.cs +++ b/PARR.Core/Services/Shortcodes/ShortcodesService.cs @@ -209,7 +209,7 @@ internal class ShortcodesService : IShortcodesService } - // 5. Проверка UnitTags + // 4. Проверка UnitTags var unitTags = currentData.UnitTags; if ((unitTags == null || unitTags.Count == 0) && requirements.HasFlag(ShortcodeDataRequirementsEnum.UnitTags)) @@ -223,7 +223,7 @@ internal class ShortcodesService : IShortcodesService .Where(u => u.Id == template.UnitId) .SelectMany(u => u.UnitValues .Where(uv => uv.Field != null && - uv.Field.AihitName == "ПАРР тег" && + uv.Field.Code == "tag" && uv.Value != null && uv.Value.Value != null) .Select(uv => uv.Value!.Value!)) @@ -231,9 +231,22 @@ internal class ShortcodesService : IShortcodesService .ConfigureAwait(false); } - // 6. Проверка RelatedUnitTags + // 5. Проверка RelatedUnitTags var relatedUnitTags = currentData.RelatedUnitTags; - var relatedUnitIds = template.UnitsInTemplate?.Select(uit => uit.UnitId).Distinct().ToList() ?? new List(); + + // Приводим template.UnitsInTemplate к List через маппинг + var mappedTemplateUnits = template.UnitsInTemplate? + .Select(uit => new UnitInTemplateForShortcode(uit.UnitId, uit.UnitFieldValueId)) + .ToList(); + + var actualUnitsInTemplate = unitsInTemplate + ?? currentData.UnitsInTemplate + ?? mappedTemplateUnits; + + var relatedUnitIds = actualUnitsInTemplate? + .Select(uit => uit.UnitId) + .Distinct() + .ToList() ?? new List(); if ((relatedUnitTags == null || relatedUnitTags.Count == 0) && requirements.HasFlag(ShortcodeDataRequirementsEnum.UnitsInTemplateTags) && @@ -248,7 +261,7 @@ internal class ShortcodesService : IShortcodesService .Where(u => relatedUnitIds.Contains(u.Id)) .SelectMany(u => u.UnitValues .Where(uv => uv.Field != null && - uv.Field.AihitName == "ПАРР тег" && + uv.Field.Code == "tag" && uv.Value != null && uv.Value.Value != null) .Select(uv => new { UnitId = u.Id, Tag = uv.Value!.Value! })) @@ -260,7 +273,7 @@ internal class ShortcodesService : IShortcodesService .ToDictionary(g => g.Key, g => g.Select(x => x.Tag).ToList()); } - // 7. Возвращаем обновленный рекорд + // 6. Возвращаем обновленный рекорд return currentData with { UnitName = unitName ?? string.Empty, diff --git a/PARR.TemplateMatcher/Services/Implementations/TemplateMatcher.cs b/PARR.TemplateMatcher/Services/Implementations/TemplateMatcher.cs index eccc77ee..25e93dc0 100644 --- a/PARR.TemplateMatcher/Services/Implementations/TemplateMatcher.cs +++ b/PARR.TemplateMatcher/Services/Implementations/TemplateMatcher.cs @@ -130,6 +130,7 @@ namespace PARR.TemplateMatcher.Services.Implementations } } + public async Task UpdateTemplatesForJobGroup(Guid jobGroupId, HistoryInitiator initiator) { _logger.LogDebug("Начало обновления шаблонов для JobGroup {JobGroupId}", jobGroupId);