fix(API,DAL): Восстановлена работа контроллеров RobotTask, TemplateActivator, Template

This commit is contained in:
Mikhail Kuznetsov
2025-06-27 13:42:13 +10:00
parent 03c7852378
commit 91ddd2ae96
12 changed files with 71 additions and 65 deletions

View File

@@ -394,9 +394,9 @@
/// </summary>
public static class TemplateActivator
{
public const string SendRequest = Base + "/jobs/" + appInWorkId + "/template-activator";
public const string SendRequest = Base + "/jobs/" + jobId + "/template-activator";
public const string appInWorkId = "{applicationInWorkId}";
public const string jobId = "{jobId}";
}
#endregion

View File

@@ -8,14 +8,14 @@
//public int? StatusCode { get; set; }
/// <summary>
/// Поиск по маске. Например: "*-ДВС"
/// Поиск по маске. Например: "ДВС-*"
/// </summary>
public string? Mask { get; set; }
/// <summary>
/// Поиск по ИД Задания (ApplicationInWorkId)
/// Поиск по ИД Задания (JobGroupId)
/// </summary>
public Guid? AppInWorkId { get; set; }
public Guid? JobGroupId { get; set; }
}
}

View File

@@ -3,36 +3,43 @@
public class TemplateResponse
{
public Guid Id { get; set; }
public required string Name { get; set; }
public bool IsActiveTemplate { get; set; }
public bool IsActiveSchedule { get; set; }
public Guid ApplicationInWorkId { get; set; }
public required string Category { get; set; }
public required string Initiator { get; set; }
public required string ClosingCode { get; set; }
public required string ShortDescription { get; set; }
public required string FullDescription { get; set; }
public required string Solution { get; set; }
public required string TemplateDuration { get; set; }
public TemplateAgentResponse? Agent { get; set; }
public DateTimeOffset? LastRun { get; set; }
public DateTimeOffset NextRun { get; set; }
public bool IsAutoDistributionEnabled { get; set; }
//public HostTemplateResponse? Host { get; set; }
public UnitBaseResponse? Unit { get; set; }
public JobBaseResponse? Job { get; set; }
//public WorkResponse? Work { get; set; }
public ProcessResponse? Process { get; set; }
public SubprocessResponse? Subprocess { get; set; }
public TnkResponse? Tnk { get; set; }
public List<RobotConfigurationResponse>? SyncStatus { get; set; }

View File

@@ -72,10 +72,17 @@ namespace PARR.API.Controllers.V1
// шаблоны
query = query.Include(t => t.Template)
.ThenInclude(t => t!.Unit)
//.ThenInclude(t => t!.Hosts).ThenInclude(t => t.WorkGroup).ThenInclude(t => t!.ResponseArea)
.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(w => w!.Work)
.ThenInclude(t => t!.Group)
.Include(t => t.Template)
.ThenInclude(w => w!.Job)
.ThenInclude(t => t!.Tnk)
.ThenInclude(s => s!.Subprocess)
.ThenInclude(p => p!.Process);
@@ -84,12 +91,16 @@ namespace PARR.API.Controllers.V1
//расписание
// тут не делаем AsSplitQuery, не может подтянуть все таблицы
query = query.Include(t => t.Template)
.ThenInclude(t => t!.Unit)//.ThenInclude(t => t!.ResponseArea)
//.ThenInclude(t => t!.Hosts).ThenInclude(t => t.WorkGroup)
.ThenInclude(t => t!.Unit)
.ThenInclude(t => t!.UnitValues)
.ThenInclude(t => t.Field)
.Include(t => t.Template)
.ThenInclude(t => t!.Job)
.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!.ApplicationsInWork)
.ThenInclude(t => t!.EsppSchValues)
.ThenInclude(t => t!.EsppSchTypeConfig)
.ThenInclude(t => t!.EsppSchTypeSchedule);

View File

@@ -11,7 +11,7 @@ using PARR.BLL.Domain.Mq;
using PARR.BLL.Services.Interfaces;
using PARR.Common.Domain;
using PARR.Constants;
using PARR.DAL.Services.Interfaces;
using PARR.DAL.Services.Interfaces.Job;
using System.Text.Json;
namespace PARR.API.Controllers.V1
@@ -26,7 +26,7 @@ namespace PARR.API.Controllers.V1
private readonly IMqService mqService;
private readonly IUriService uriService;
private readonly MqSettings mqSettings;
private readonly IApplicationsInWorkService applicationsInWorkService;
private readonly IJobService jobService;
private readonly IClientService clientService;
public TemplateActivatorController(
@@ -34,7 +34,7 @@ namespace PARR.API.Controllers.V1
IMqService mqService,
IUriService uriService,
MqSettings mqSettings,
IApplicationsInWorkService applicationsInWorkService,
IJobService jobService,
IClientService clientService
)
{
@@ -42,7 +42,7 @@ namespace PARR.API.Controllers.V1
this.mqService = mqService;
this.uriService = uriService;
this.mqSettings = mqSettings;
this.applicationsInWorkService = applicationsInWorkService;
this.jobService = jobService;
this.clientService = clientService;
}
@@ -50,24 +50,24 @@ namespace PARR.API.Controllers.V1
/// <summary>
/// Отправить запрос на активацию/деактивацию шаблонов/расписаний
/// </summary>
/// <param name="applicationInWorkId"></param>
/// <param name="jobId"></param>
/// <returns></returns>
[HttpPost(ApiRoutes.TemplateActivator.SendRequest)]
public async Task<IActionResult> SendRequest([FromRoute] Guid applicationInWorkId, [FromBody] TemplateActivatorRequest request)
public async Task<IActionResult> SendRequest([FromRoute] Guid jobId, [FromBody] TemplateActivatorRequest request)
{
var resultValidate = await validator.ValidateAsync(request);
if (!resultValidate.IsValid)
return BadRequest(new Response(resultValidate.Errors));
var appInWork = await applicationsInWorkService.GetAsync(applicationInWorkId);
var job = await jobService.GetAsync(jobId);
if (appInWork == null)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(applicationInWorkId), Message = "Некорректное значение" } }));
if (job == null)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(jobId), Message = "Некорректное значение" } }));
var mqRequest = new TemplateActivatorMq
{
ApplicationInWorkId = applicationInWorkId,
JobId = jobId,
Action = request.Action,
HistoryInitiator = new HistoryInitiator { InitiatorIp = clientService.GetClientIp()?.ToString(), InitiatorParrComponentId = ParrComponentsEnum.Api }
};

View File

@@ -28,21 +28,18 @@ namespace PARR.API.Controllers.V1
{
private readonly IMapper mapper;
private readonly ITemplateService templateService;
private readonly SettingsFromDb settingsFromDb;
private readonly IRobotConfigurationService robotConfigurationService;
private readonly IClientService clientService;
public TemplateController(
IMapper mapper,
ITemplateService templateService,
SettingsFromDb settingsFromDb,
IRobotConfigurationService robotConfigurationService,
IClientService clientService
)
{
this.mapper = mapper;
this.templateService = templateService;
this.settingsFromDb = settingsFromDb;
this.robotConfigurationService = robotConfigurationService;
this.clientService = clientService;
}
@@ -58,7 +55,9 @@ namespace PARR.API.Controllers.V1
{
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
IQueryable<Template> query = templateService.GetWithIncludes()
IQueryable<Template> query = templateService.GetWithIncludes().AsNoTracking()
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
@@ -70,8 +69,8 @@ namespace PARR.API.Controllers.V1
if (!string.IsNullOrEmpty(filter.Mask))
query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(filter.Mask)));
if (filter.AppInWorkId.HasValue)
query = query.Where(t => t.JobId == filter.AppInWorkId.Value);//TODO Migration to job
if (filter.JobGroupId.HasValue)
query = query.Where(t => t.Job!.GroupId == filter.JobGroupId.Value);
var templates = await templateService.GetPage(query, paginationFilter).ToListAsync();
@@ -92,7 +91,9 @@ namespace PARR.API.Controllers.V1
[HttpGet(ApiRoutes.Template.Get)]
public async Task<IActionResult> GetById([FromRoute] Guid id)
{
var template = await templateService.GetWithIncludes()
var template = await templateService.GetWithIncludes().AsNoTracking()
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
@@ -118,6 +119,8 @@ namespace PARR.API.Controllers.V1
public async Task<IActionResult> ChangeState([FromRoute] Guid id, [FromBody] TemplateChangeStateRequest request)
{
var template = await templateService.GetWithIncludes()
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t!.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)
@@ -147,7 +150,9 @@ namespace PARR.API.Controllers.V1
if (!await templateService.CommitAsync(new HistoryInitiator { InitiatorComment = "Изменён статус шаблона/расписания", InitiatorIp = clientService.GetClientIp()?.ToString(), InitiatorParrComponentId = ParrComponentsEnum.Api }))
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при изменении шаблона." } }));
var templateToResponse = await templateService.GetWithIncludes()
var templateToResponse = await templateService.GetWithIncludes().AsNoTracking()
.Include(t => t.Unit).ThenInclude(t => t.UnitValues).ThenInclude(t => t.Field)
.Include(t => t.Unit).ThenInclude(t => t.UnitValues).ThenInclude(t => t.Value)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.Robot)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.TaskStatus)
.Include(t => t.RobotConfigurations).ThenInclude(t => t.RobotStatus)

View File

@@ -48,7 +48,7 @@ namespace PARR.API.MappingProfiles
#endregion
CreateMap<ApplicationsInWork, TemplateAgentResponse>()
CreateMap<JobGroup, TemplateAgentResponse>()
.ForMember(d => d.IsAgent, o => o.MapFrom(s => s.IsAgent))
.ForMember(d => d.Name, o => o.MapFrom(s => s.AgentName))
.ForMember(d => d.Script, o => o.MapFrom(s => s.AgentScript))
@@ -167,7 +167,7 @@ namespace PARR.API.MappingProfiles
.ForMember(d => d.Initiator, o => o.MapFrom<RobotTaskTemplateInitiatorResolver>())
.ForMember(d => d.Category, o => o.MapFrom<RobotTaskTemplateCategoryResolver>())
.ForMember(d => d.WorkGroup, o => o.MapFrom(s => s.Template!.Unit.BaseFields.WorkGroup))
.ForMember(d => d.Ek, o => o.MapFrom(s => s.Template!.Unit.Name))
.ForMember(d => d.Ek, o => o.MapFrom(s => s.Template!.Unit!.Name))
.ForMember(d => d.Name, o => o.MapFrom(s => s.Template!.Name))
.ForMember(d => d.ProcessName, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.Process!.Name))
.ForMember(d => d.ProcessEsppId, o => o.MapFrom(s => s.Template!.Job!.Tnk!.Subprocess!.Process!.EsppId))

View File

@@ -26,13 +26,13 @@ namespace PARR.API.MappingProfiles.Resolvers
public List<RobotTaskScheduleSchResponse>? Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, List<RobotTaskScheduleSchResponse>? destMember, ResolutionContext context)
{
var appInWorksId = source.Template!.JobId;
var jobGroupId = source.Template!.Job!.GroupId;
var schedule = esppConfigService.GetEsppScheduleDto(appInWorksId);
var schedule = esppConfigService.GetEsppScheduleDto(jobGroupId);
if (schedule == null)
{
logger.LogError($"RobotTaskScheduleSchResolver: Не смог замапить расписание для робота, так как оно null. appInWorksId: {appInWorksId}");
logger.LogError($"RobotTaskScheduleSchResolver: Не смог замапить расписание для робота, так как оно null. jobGroupId: {jobGroupId}");
return null;
}

View File

@@ -11,7 +11,7 @@ namespace PARR.BLL.Domain.Mq
/// <summary>
/// Id регламентной работы
/// </summary>
public Guid ApplicationInWorkId { get; set; }
public Guid JobId { get; set; }
/// <summary>
/// Действие по активации/деактивации

View File

@@ -35,15 +35,6 @@ namespace PARR.DAL.Services.Implementations
{
//Формирует расписание в нормальном понятном виде из БД
var test = await dataContext.EsppSchValues
//.Include(t => t.JobGroup)
//.Include(t => t.EsppSchTypeConfig)
// .ThenInclude(t => t!.EsppSchTypeSchedule)
//.Include(t => t.EsppSchTypeConfig)
// .ThenInclude(t => t.EsppSchType)
//.Include(t => t.EsppSchTypeValue)
.ToListAsync();
var schValues = await dataContext.EsppSchValues
.Include(t => t.EsppSchTypeConfig)
.ThenInclude(t => t!.EsppSchTypeSchedule)

View File

@@ -38,7 +38,10 @@ namespace PARR.DAL.Services.Implementations
.Include(a => a.Job)
.ThenInclude(t => t!.Tnk)
.ThenInclude(s => s!.Subprocess)
.ThenInclude(p => p!.Process);
.ThenInclude(p => p!.Process)
.Include(t=>t.Job)
.ThenInclude(t=>t!.Group);
//return Get()
// .Include(h => h.Host)
// .ThenInclude(t => t!.ResponseArea)

View File

@@ -1,6 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.Common;
using PARR.Constants;
using PARR.DAL.Contracts;
using PARR.DAL.DomainModels;
@@ -13,8 +12,6 @@ namespace PARR.DAL.TransformServices
internal class EsppScheduleTransformService : IEsppScheduleTransformService
{
private readonly IEsppSchTypeConfigService esppSchTypeConfigService;
private readonly IApplicationsInWorkService applicationsInWorkService;
private readonly IWeekendDayService weekendDayService;
private readonly INextRunModifierService nextRunModifierService;
private readonly IJobGroupService jobGroupService;
private readonly ILogger<EsppScheduleTransformService> logger;
@@ -59,15 +56,12 @@ namespace PARR.DAL.TransformServices
public EsppScheduleTransformService(
ILogger<EsppScheduleTransformService> logger,
IEsppSchTypeConfigService esppSchTypeConfigService,
IApplicationsInWorkService applicationsInWorkService,
IWeekendDayService weekendDayService,
INextRunModifierService nextRunModifierService,
IJobGroupService jobGroupService
)
{
this.esppSchTypeConfigService = esppSchTypeConfigService;
this.applicationsInWorkService = applicationsInWorkService;
this.weekendDayService = weekendDayService;
this.nextRunModifierService = nextRunModifierService;
this.jobGroupService = jobGroupService;
this.logger = logger;
@@ -167,13 +161,8 @@ namespace PARR.DAL.TransformServices
if (lastRun > DateTimeOffset.UtcNow)
return await nextRunModifierService.GetWorkDayAsync(lastRun);
//var appInWork = await applicationsInWorkService.Get()
// .Include(aiw => aiw.EsppSchValues)
// .ThenInclude(esv => esv.EsppSchTypeValue)
// .ThenInclude(etv => etv!.DistributionPeriod)
// .FirstOrDefaultAsync(t => t.Id == applicationInWorkId);
var jobGroup = await jobGroupService.Get()
.Include(t=>t.EsppSchValues)
var jobGroup = await jobGroupService.Get().AsTracking()
.Include(t => t.EsppSchValues)
.ThenInclude(esv => esv.EsppSchTypeValue)
.ThenInclude(etv => etv!.DistributionPeriod)
.FirstOrDefaultAsync(t => t.Id == jobGroupId);