fix(dal): при формировании групповых шорткодов не хватало include GroupType, изменен ключ кэширования
This commit is contained in:
@@ -124,7 +124,8 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
var maxShortcodes = Regex.Matches(resultName, maxShortcodePattern);
|
||||
if (maxShortcodes.Count > 0)
|
||||
{
|
||||
resultName = await ReplaceMaxShortcodesAsync(job.Group.Id, template.UnitId, resultName, maxShortcodes); // ✅ Исправлено: job.GroupId
|
||||
var unitIds = template.UnitsInTemplate.Select(uit => uit.UnitId).ToList();
|
||||
resultName = await ReplaceMaxShortcodesAsync(job.Group.Id, template.UnitId, unitIds, resultName, maxShortcodes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,13 +161,14 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
{
|
||||
var fieldValues = await unitInValueService.Get()
|
||||
.AsNoTracking()
|
||||
//.AsSplitQuery()
|
||||
.Include(uv => uv.Value)
|
||||
.Where(uv =>
|
||||
uv.FieldId == groupingFieldId.Value &&
|
||||
unitIds.Contains(uv.UnitId) &&
|
||||
uv.Value != null &&
|
||||
!string.IsNullOrWhiteSpace(uv.Value.Value))
|
||||
.Select(uv => new { uv.UnitId, Value = uv.Value.Value })
|
||||
.Select(uv => new { uv.UnitId, Value = uv.Value!.Value })
|
||||
.ToListAsync();
|
||||
|
||||
valuesByUnit = fieldValues
|
||||
@@ -221,7 +223,9 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
|
||||
public bool IsAnyShortcodes(string str)
|
||||
{
|
||||
return Regex.IsMatch(str, shortcodePattern);
|
||||
return Regex.IsMatch(str, shortcodePattern) ||
|
||||
Regex.IsMatch(str, maxShortcodePattern) ||
|
||||
Regex.IsMatch(str, lettersShortcodePattern);
|
||||
}
|
||||
|
||||
private static List<Match> GetShortCodes(string resultName)
|
||||
@@ -359,7 +363,7 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
return resultName;
|
||||
}
|
||||
|
||||
private async Task<string> ReplaceMaxShortcodesAsync(Guid jobGroupId, Guid unitId, string input, MatchCollection maxShortcodes)
|
||||
private async Task<string> ReplaceMaxShortcodesAsync(Guid jobGroupId, Guid unitId, List<Guid> unitIds, string input, MatchCollection maxShortcodes)
|
||||
{
|
||||
var shortcodeToMatches = maxShortcodes
|
||||
.Cast<Match>()
|
||||
@@ -370,18 +374,21 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
{
|
||||
var fullShortcode = kvp.Key;
|
||||
var matches = kvp.Value;
|
||||
var fieldName = fullShortcode.Trim('%').Split(':', 2)[1].Trim(); // "РАБОЧАЯ_ГР_ОТВ_ЗА_ЭК"
|
||||
var fieldName = fullShortcode.Trim('%').Split(':', 2)[1].Trim();
|
||||
|
||||
logger.LogDebug("Обработка {Shortcode} для JobGroup {JobGroupId}, Template.UnitId {UnitId}",
|
||||
fullShortcode, jobGroupId, unitId);
|
||||
logger.LogDebug("Обработка {Shortcode} для JobGroup {JobGroupId}, Template.UnitId {UnitId}, fieldName {FieldName}",
|
||||
fullShortcode, jobGroupId, unitId, fieldName);
|
||||
|
||||
var mostFrequentValue = await groupedShortcodesCacheService.GetAggregatedValueAsync(
|
||||
jobGroupId,
|
||||
unitId,
|
||||
fullShortcode,
|
||||
async () =>
|
||||
{
|
||||
// Логика вычисления, если кэш пуст
|
||||
var unitIds = await jobService.Get()
|
||||
logger.LogDebug("Кэш промахнут для {Shortcode}, начинаем вычисление.", fullShortcode);
|
||||
|
||||
// ✅ Пытаемся загрузить UnitsInTemplate из БД
|
||||
var dbUnitIds = await jobService.Get()
|
||||
.Where(j => j.GroupId == jobGroupId)
|
||||
.Join(
|
||||
templateService.Get()
|
||||
@@ -396,11 +403,23 @@ namespace PARR.DAL.DomainServices.Shortcodes
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
logger.LogDebug("Загружено {Count} unitIds из БД для JobGroup {JobGroupId}", dbUnitIds.Count, jobGroupId);
|
||||
|
||||
// ✅ Если в БД нет UnitsInTemplate — используем переданные unitIds
|
||||
var effectiveUnitIds = dbUnitIds.Any() ? dbUnitIds : unitIds;
|
||||
|
||||
logger.LogDebug("EffectiveUnitIds: [{Ids}], Count: {Count}", string.Join(", ", effectiveUnitIds), effectiveUnitIds.Count);
|
||||
|
||||
// Вызываем метод из сервиса
|
||||
var result = await unitInValueService.GetMostFrequentValueForFieldAsync(unitIds, fieldName);
|
||||
var result = await unitInValueService.GetMostFrequentValueForFieldAsync(effectiveUnitIds, fieldName);
|
||||
|
||||
logger.LogDebug("Результат GetMostFrequentValueForFieldAsync: {Result}, для поля {FieldName}, unitIds: [{Ids}]", result, fieldName, string.Join(", ", effectiveUnitIds));
|
||||
|
||||
return result ?? string.Empty;
|
||||
});
|
||||
|
||||
logger.LogDebug("Итоговое значение для {Shortcode}: {Value}", fullShortcode, mostFrequentValue);
|
||||
|
||||
foreach (var match in matches)
|
||||
{
|
||||
input = input.Replace(match.Value, mostFrequentValue);
|
||||
|
||||
Reference in New Issue
Block a user