feat(dal,templateMatcher): Shortcodes добавлены %МАКС:ИМЯ АТРИБУТА%, %ГР_ПОЛЕ-ПН%, %БУКВЫ:ИМЯ АТРИБУТА%, исправлена фильтрация в UnitFilter, TemplateMatcher отдельные классы для типов работ, Shortcodes теперь работает по своим моделям Dto
This commit is contained in:
@@ -11,7 +11,8 @@ using PARR.API.Services.Interfaces;
|
||||
using PARR.Common.Domain;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainServices.Interfaces;
|
||||
using PARR.DAL.DomainServices.Shortcodes;
|
||||
using PARR.DAL.DomainServices.Shortcodes.Models;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.TransformServices;
|
||||
@@ -68,55 +69,61 @@ namespace PARR.API.Controllers.V1
|
||||
var query = robotConfigurationService.Get()
|
||||
.Where(t => t.RobotCode == (int)robotCode && t.TaskStatusCode == (int)taskStatusCode);
|
||||
|
||||
//var query = robotConfigurationService.GetAsync();
|
||||
|
||||
switch (robotCode)
|
||||
{
|
||||
case RobotsEnum.TemplateOrder:
|
||||
// шаблоны
|
||||
query = query.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Field)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Value)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(a => a!.Job)
|
||||
.ThenInclude(t => t!.Group)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(w => w!.Job)
|
||||
.ThenInclude(t => t!.Tnk)
|
||||
.ThenInclude(s => s!.Subprocess)
|
||||
.ThenInclude(p => p!.Process);
|
||||
query = query
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Field)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Value)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(a => a!.Job)
|
||||
.ThenInclude(t => t!.Group)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(w => w!.Job)
|
||||
.ThenInclude(t => t!.Tnk)
|
||||
.ThenInclude(s => s!.Subprocess)
|
||||
.ThenInclude(p => p!.Process);
|
||||
|
||||
query = query
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t.UnitsInTemplate);
|
||||
|
||||
break;
|
||||
|
||||
case RobotsEnum.ScheduleOrder:
|
||||
//расписание
|
||||
// тут не делаем AsSplitQuery, не может подтянуть все таблицы
|
||||
query = query.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Field)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Value)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(a => a!.Job)
|
||||
.ThenInclude(t => t!.Group)
|
||||
.ThenInclude(t => t!.EsppSchValues)
|
||||
.ThenInclude(t => t!.EsppSchTypeConfig)
|
||||
.ThenInclude(t => t!.EsppSchTypeSchedule);
|
||||
query = query
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Field)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Unit)
|
||||
.ThenInclude(t => t!.UnitValues)
|
||||
.ThenInclude(t => t.Value)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(a => a!.Job)
|
||||
.ThenInclude(t => t!.Group)
|
||||
.ThenInclude(t => t!.EsppSchValues)
|
||||
.ThenInclude(t => t!.EsppSchTypeConfig)
|
||||
.ThenInclude(t => t!.EsppSchTypeSchedule)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t.UnitsInTemplate);
|
||||
|
||||
//выбираем только записи с созданными шаблонами (у которых статус 20 или 30), а только потом у них ищем расписания
|
||||
// сначала находим шаблоны со статусом 30
|
||||
var createdTemplates = robotConfigurationService.Get()
|
||||
.Where(t => t.RobotCode == (int)RobotsEnum.TemplateOrder && (t.TaskStatusCode == (int)TaskStatusEnum.Ok))
|
||||
.Select(t => t.TemplateId);
|
||||
//находим задания с расписанием по списку шаблонов createdTemplates
|
||||
.Where(t => t.RobotCode == (int)RobotsEnum.TemplateOrder && (t.TaskStatusCode == (int)TaskStatusEnum.Ok))
|
||||
.Select(t => t.TemplateId);
|
||||
query = query.Where(t => t.RobotCode == (int)RobotsEnum.ScheduleOrder && createdTemplates.Contains(t.TemplateId));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -161,34 +168,96 @@ namespace PARR.API.Controllers.V1
|
||||
switch (robotCode)
|
||||
{
|
||||
case RobotsEnum.TemplateOrder:
|
||||
//RobotTaskTemplateResponse
|
||||
var robotTaskTemplateResponse = mapper.Map<RobotTaskTemplateResponse>(task);
|
||||
{ //RobotTaskTemplateResponse
|
||||
var robotTaskTemplateResponse = mapper.Map<RobotTaskTemplateResponse>(task);
|
||||
|
||||
//TODO Вынести в отдельный метод ShortcodesService
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.FullDescription))
|
||||
robotTaskTemplateResponse.FullDescription = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.FullDescription, task!.Template!.UnitId, task!.Template!.JobId);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.ShortDescription))
|
||||
robotTaskTemplateResponse.ShortDescription = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.ShortDescription, task!.Template!.UnitId, task!.Template!.JobId);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.Solution))
|
||||
robotTaskTemplateResponse.Solution = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.Solution, task!.Template!.UnitId, task!.Template!.JobId);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.TnkName))
|
||||
robotTaskTemplateResponse.TnkName = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.TnkName, task!.Template!.UnitId, task!.Template!.JobId);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.WorkName))
|
||||
robotTaskTemplateResponse.WorkName = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.WorkName, task!.Template!.UnitId, task!.Template!.JobId);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.WorkGroup))
|
||||
robotTaskTemplateResponse.WorkGroup = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.WorkGroup, task!.Template!.UnitId, task!.Template!.JobId);
|
||||
//TODO Вынести в отдельный метод ShortcodesService
|
||||
|
||||
return Ok(new Response<RobotTaskTemplateResponse>(robotTaskTemplateResponse, true));
|
||||
// ✅ Построим TemplateForShortcodes из уже загруженного task.Template
|
||||
var templateForShortcodes = new TemplateForShortcodes
|
||||
{
|
||||
Id = task.Template!.Id,
|
||||
Index = task.Template.Index,
|
||||
JobId = task.Template.JobId,
|
||||
UnitId = task.Template.UnitId,
|
||||
Job = task.Template.Job == null ? null : new JobForShortcodes
|
||||
{
|
||||
Group = task.Template.Job.Group == null ? null : new JobGroupForShortcodes
|
||||
{
|
||||
GroupingUnitFieldId = task.Template.Job.Group.GroupingUnitFieldId,
|
||||
GroupType = task.Template.Job.Group.GroupType == null ? null : new JobGroupTypeForShortcodes
|
||||
{
|
||||
Code = task.Template.Job.Group.GroupType.Code
|
||||
},
|
||||
GroupName = task.Template.Job.Group.GroupName
|
||||
},
|
||||
Tnk = task.Template.Job.Tnk == null ? null : new TnkForShortcodes
|
||||
{
|
||||
Name = task.Template.Job.Tnk.Name,
|
||||
ShortName = task.Template.Job.Tnk.ShortName ?? ""
|
||||
},
|
||||
WorkName = task.Template.Job.WorkName,
|
||||
Name = task.Template.Job.Name
|
||||
},
|
||||
UnitsInTemplate = task.Template.UnitsInTemplate?.Select(uit => new UnitInTemplateForShortcodes { UnitId = uit.UnitId }).ToList() ?? new List<UnitInTemplateForShortcodes>()
|
||||
};
|
||||
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.FullDescription))
|
||||
robotTaskTemplateResponse.FullDescription = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.FullDescription , templateForShortcodes);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.ShortDescription))
|
||||
robotTaskTemplateResponse.ShortDescription = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.ShortDescription, templateForShortcodes);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.Solution))
|
||||
robotTaskTemplateResponse.Solution = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.Solution, templateForShortcodes);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.TnkName))
|
||||
robotTaskTemplateResponse.TnkName = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.TnkName, templateForShortcodes);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.WorkName))
|
||||
robotTaskTemplateResponse.WorkName = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.WorkName, templateForShortcodes);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskTemplateResponse.WorkGroup))
|
||||
robotTaskTemplateResponse.WorkGroup = await shortcodesService.ApplyShortcodesAsync(robotTaskTemplateResponse.WorkGroup, templateForShortcodes);
|
||||
|
||||
return Ok(new Response<RobotTaskTemplateResponse>(robotTaskTemplateResponse, true));
|
||||
}
|
||||
case RobotsEnum.ScheduleOrder:
|
||||
// если был запрос на расписание, проверяем у него nextRun, lastRun, обновляем их
|
||||
await UpdateLastNextRunDate(task);
|
||||
{ // если был запрос на расписание, проверяем у него nextRun, lastRun, обновляем их
|
||||
await UpdateLastNextRunDate(task);
|
||||
|
||||
//RobotTaskScheduleResponse
|
||||
var robotTaskScheduleResponse = mapper.Map<RobotTaskScheduleResponse>(task);
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskScheduleResponse.WorkGroup))
|
||||
robotTaskScheduleResponse.WorkGroup = await shortcodesService.ApplyShortcodesAsync(robotTaskScheduleResponse.WorkGroup, task!.Template!.UnitId, task!.Template!.JobId);
|
||||
//RobotTaskScheduleResponse
|
||||
var robotTaskScheduleResponse = mapper.Map<RobotTaskScheduleResponse>(task);
|
||||
|
||||
return Ok(new Response<RobotTaskScheduleResponse>(robotTaskScheduleResponse, true));
|
||||
// Построим TemplateForShortcodes из уже загруженного task.Template
|
||||
var templateForShortcodes = new TemplateForShortcodes
|
||||
{
|
||||
Id = task.Template!.Id,
|
||||
Index = task.Template.Index,
|
||||
JobId = task.Template.JobId,
|
||||
UnitId = task.Template.UnitId,
|
||||
Job = task.Template.Job == null ? null : new JobForShortcodes
|
||||
{
|
||||
Group = task.Template.Job.Group == null ? null : new JobGroupForShortcodes
|
||||
{
|
||||
GroupingUnitFieldId = task.Template.Job.Group.GroupingUnitFieldId,
|
||||
GroupType = task.Template.Job.Group.GroupType == null ? null : new JobGroupTypeForShortcodes
|
||||
{
|
||||
Code = task.Template.Job.Group.GroupType.Code
|
||||
},
|
||||
GroupName = task.Template.Job.Group.GroupName
|
||||
},
|
||||
Tnk = task.Template.Job.Tnk == null ? null : new TnkForShortcodes
|
||||
{
|
||||
Name = task.Template.Job.Tnk.Name,
|
||||
ShortName = task.Template.Job.Tnk.ShortName
|
||||
},
|
||||
WorkName = task.Template.Job.WorkName,
|
||||
Name = task.Template.Job.Name
|
||||
},
|
||||
UnitsInTemplate = task.Template.UnitsInTemplate?.Select(uit => new UnitInTemplateForShortcodes { UnitId = uit.UnitId }).ToList() ?? new List<UnitInTemplateForShortcodes>()
|
||||
};
|
||||
|
||||
if (shortcodesService.IsAnyShortcodes(robotTaskScheduleResponse.WorkGroup))
|
||||
robotTaskScheduleResponse.WorkGroup = await shortcodesService.ApplyShortcodesAsync(robotTaskScheduleResponse.WorkGroup, templateForShortcodes);
|
||||
|
||||
return Ok(new Response<RobotTaskScheduleResponse>(robotTaskScheduleResponse, true));
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user