fix(shortcodesService): исправлена загрузка шорткода %ТЕГ_СВЯЗИ:...% - отсутствовало требование загрузки UnitsInTemplate
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -130,6 +130,7 @@ namespace PARR.TemplateMatcher.Services.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task UpdateTemplatesForJobGroup(Guid jobGroupId, HistoryInitiator initiator)
|
||||
{
|
||||
_logger.LogDebug("Начало обновления шаблонов для JobGroup {JobGroupId}", jobGroupId);
|
||||
|
||||
Reference in New Issue
Block a user