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);