feat(dal, templateMatcher): изменена логика работы Shortcodes сервиса в сторону самостоятельной дозагрузки данных из БД, в Template сервис добавлен метод атомарного резервирования шаблона для TemplateMatcher
This commit is contained in:
@@ -66,6 +66,8 @@ namespace PARR.TemplateGeneratorWorker
|
||||
var job = await jobService
|
||||
.Get().AsNoTracking()
|
||||
.Include(t => t.Group)
|
||||
.ThenInclude(g => g!.GroupType)
|
||||
.Include(t => t.Tnk)
|
||||
.FirstOrDefaultAsync(t => t.Id == query.JobId);
|
||||
|
||||
if (job == null)
|
||||
@@ -80,36 +82,20 @@ namespace PARR.TemplateGeneratorWorker
|
||||
return;
|
||||
}
|
||||
|
||||
var templateForShortcodes = new TemplateForShortcodes
|
||||
// === Создаём временный Template для подстановки шорткодов ===
|
||||
var tempTemplateForShortcodes = new Template
|
||||
{
|
||||
Id = Guid.Empty, // шаблон ещё не создан
|
||||
Index = query.Index,
|
||||
Id = Guid.Empty, // ещё не создан
|
||||
Name = "", // не используется
|
||||
JobId = query.JobId,
|
||||
UnitId = query.UnitId,
|
||||
Job = job == null ? null : new JobForShortcodes
|
||||
{
|
||||
Group = job.Group == null ? null : new JobGroupForShortcodes
|
||||
{
|
||||
Id = job.GroupId,
|
||||
GroupingUnitFieldId = job.Group.GroupingUnitFieldId,
|
||||
GroupType = job.Group.GroupType == null ? null : new JobGroupTypeForShortcodes
|
||||
{
|
||||
Code = job.Group.GroupType.Code
|
||||
},
|
||||
GroupName = job.Group.GroupName
|
||||
},
|
||||
Tnk = job.Tnk == null ? null : new TnkForShortcodes
|
||||
{
|
||||
Name = job.Tnk.Name,
|
||||
ShortName = job.Tnk.ShortName
|
||||
},
|
||||
WorkName = job.WorkName,
|
||||
Name = job.Name
|
||||
},
|
||||
UnitsInTemplate = query.UnitsInTemplate?.Select(guid => new UnitInTemplateForShortcodes { UnitId = guid }).ToList() ?? new List<UnitInTemplateForShortcodes>()
|
||||
Index = query.Index,
|
||||
Job = job,
|
||||
Unit = null, // ShortcodesService сам догрузит при необходимости
|
||||
UnitsInTemplate = query.UnitsInTemplate?.Select(unitId => new UnitsInTemplate { UnitId = unitId }).ToList() ?? new List<UnitsInTemplate>()
|
||||
};
|
||||
|
||||
var templateName = await shortcodesService.ApplyShortcodesAsync(job!.TemplateNameMask!, templateForShortcodes);
|
||||
var templateName = await shortcodesService.ApplyShortcodesAsync(job.TemplateNameMask!, tempTemplateForShortcodes);
|
||||
|
||||
var nextRun = await esppScheduleTransformService.GetNextDateAsync(job.GroupId, job.Group!.ReferenceDate);
|
||||
|
||||
@@ -125,20 +111,10 @@ namespace PARR.TemplateGeneratorWorker
|
||||
StatusTypeId = TemplateStatusTypeEnum.Used,
|
||||
InitiatorComment = query.HistoryInitiator?.InitiatorComment,
|
||||
InitiatorParrComponentId = query.HistoryInitiator?.InitiatorParrComponentId,
|
||||
Index = query.Index
|
||||
Index = query.Index,
|
||||
UnitsInTemplate = query.UnitsInTemplate?.Select(unitId => new UnitsInTemplate { UnitId = unitId }).ToList() ?? new List<UnitsInTemplate>()
|
||||
};
|
||||
|
||||
// Устанавливаем UnitsInTemplate
|
||||
if (query.UnitsInTemplate != null && query.UnitsInTemplate.Any())
|
||||
{
|
||||
template.UnitsInTemplate = query.UnitsInTemplate.Select(unitId => new UnitsInTemplate { UnitId = unitId }).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Если список пуст, все равно инициализируем коллекцию, чтобы избежать NullReferenceException при сохранении (если это не nullable)
|
||||
template.UnitsInTemplate = new List<UnitsInTemplate>();
|
||||
}
|
||||
|
||||
if (await templateService.CreateAsync(template) && await templateService.CommitAsync(new HistoryInitiator { InitiatorComment = "Запрос на генерацию с тестового шаблона", InitiatorParrComponentId = ParrComponentsEnum.TemplateTaskGenerator }))
|
||||
{
|
||||
logger.LogInformation("Создан шаблон: Id={TemplateId}, Name={Name}, Job={JobId}, Unit={UnitId}, Index={Index}, UnitsInTemplateCount={UnitsCount}",
|
||||
|
||||
Reference in New Issue
Block a user