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

@@ -4,7 +4,6 @@ using Microsoft.Extensions.Logging;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.DomainServices.Shortcodes;
using PARR.DAL.DomainServices.Shortcodes.Models;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
using System.Reflection;
@@ -90,51 +89,20 @@ namespace PARR.EsppSync
return;
}
// Построим TemplateForShortcodes из уже загруженного template
var templateForShortcodes = new TemplateForShortcodes
{
Id = template.Id,
Index = template.Index,
JobId = template.JobId,
UnitId = template.UnitId,
Job = template.Job == null ? null : new JobForShortcodes
{
Group = template.Job.Group == null ? null : new JobGroupForShortcodes
{
Id = template.Job.GroupId,
GroupingUnitFieldId = template.Job.Group.GroupingUnitFieldId,
GroupType = template.Job.Group.GroupType == null ? null : new JobGroupTypeForShortcodes
{
Code = template.Job.Group.GroupType.Code
},
GroupName = template.Job.Group.GroupName
},
Tnk = template.Job.Tnk == null ? null : new TnkForShortcodes
{
Name = template.Job.Tnk.Name,
ShortName = template.Job.Tnk.ShortName
},
WorkName = template.Job.WorkName,
Name = template.Job.Name
},
UnitsInTemplate = template.UnitsInTemplate?.Select(uit => new UnitInTemplateForShortcodes { UnitId = uit.UnitId }).ToList() ?? new List<UnitInTemplateForShortcodes>()
};
var dbObjectInEsppObject = converterToEsppObject.Invoke(template);
//Проверяем наличие Shortcode в полях объекта из БД
// Проверяем наличие Shortcode в полях объекта из БД
var properties = dbObjectInEsppObject.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
var type = property.PropertyType;
if(type == typeof(string)){
// только для стрингов проверяем шорткоды
if (property.PropertyType == typeof(string))
{
var value = property.GetValue(dbObjectInEsppObject)?.ToString();
if (value != null)
if (!string.IsNullOrEmpty(value))
{
var processedValue = await shortcodesService.ApplyShortcodesAsync(value, templateForShortcodes);
// Передаём исходный template — он уже загружен с Include
var processedValue = await shortcodesService.ApplyShortcodesAsync(value, template);
property.SetValue(dbObjectInEsppObject, processedValue);
}
}