feat(dal, templateMatcher): изменена логика работы Shortcodes сервиса в сторону самостоятельной дозагрузки данных из БД, в Template сервис добавлен метод атомарного резервирования шаблона для TemplateMatcher

This commit is contained in:
Mikhail Kuznetsov
2026-01-16 18:26:06 +10:00
parent 99a491ede8
commit d91877453a
25 changed files with 822 additions and 509 deletions

View File

@@ -1,7 +1,7 @@
using PARR.DAL.DomainServices.Shortcodes;
using PARR.DAL.DomainServices.Shortcodes.Models;
using PARR.DAL.Models.Job;
using PARR.DAL.Models;
using PARR.TemplateMatcher.Services.Interfaces;
using System.Runtime.CompilerServices;
namespace PARR.TemplateMatcher.Services.Implementations;
@@ -14,38 +14,15 @@ internal class TemplateNameNormalizer : ITemplateNameNormalizer
this.shortcodesService = shortcodesService;
}
public async Task<string> GetNormalizedTemplateNameAsync(Job job, Guid unitId, int? index = null, List<Guid>? templateUnitIds = null)
public async Task<string> GetNormalizedTemplateNameAsync(Template template, [CallerMemberName] string? caller = null)
{
var templateForShortcodes = new TemplateForShortcodes
{
Id = Guid.Empty,
Index = (index != null) ? index + 1 : index,
JobId = job.Id,
UnitId = unitId,
Job = new JobForShortcodes
{
Group = job.Group != null ? new JobGroupForShortcodes
{
Id = job.Group.Id,
GroupingUnitFieldId = job.Group.GroupingUnitFieldId,
GroupType = job.Group.GroupType != null ? new JobGroupTypeForShortcodes
{
Code = job.Group.GroupType.Code
} : null,
GroupName = job.Group.GroupName
} : null,
Tnk = job.Tnk != null ? new TnkForShortcodes
{
Name = job.Tnk.Name,
ShortName = job.Tnk.ShortName ?? ""
} : null,
WorkName = job.WorkName,
Name = job.Name
},
UnitsInTemplate = templateUnitIds?.Select(id => new UnitInTemplateForShortcodes { UnitId = id }).ToList() ?? new List<UnitInTemplateForShortcodes>()
};
var callerName = caller ?? "Unknown";
if (template.Job == null)
throw new ArgumentNullException(nameof(template.Job));
var rawName = await shortcodesService.ApplyShortcodesAsync(template.Job.TemplateNameMask, template, callerName);
var rawName = await shortcodesService.ApplyShortcodesAsync(job.TemplateNameMask, templateForShortcodes);
return rawName.ToUpper();
}
}