fix(shortcodesService): исправлена загрузка шорткода %ТЕГ_СВЯЗИ:...% - отсутствовало требование загрузки UnitsInTemplate

This commit is contained in:
Mikhail Kuznetsov
2026-09-08 09:47:31 +10:00
parent fb20395e53
commit e02a51f5ed
3 changed files with 21 additions and 7 deletions

View File

@@ -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<RelatedUnitTagShortcodeHandler> logger)
{

View File

@@ -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<Guid>();
// Приводим template.UnitsInTemplate к List<UnitInTemplateForShortcode> через маппинг
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<Guid>();
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,

View File

@@ -130,6 +130,7 @@ namespace PARR.TemplateMatcher.Services.Implementations
}
}
public async Task UpdateTemplatesForJobGroup(Guid jobGroupId, HistoryInitiator initiator)
{
_logger.LogDebug("Начало обновления шаблонов для JobGroup {JobGroupId}", jobGroupId);