feat(api): Доделал получение задания для агента.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using AutoMapper;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PARR.API.Contracts.V1;
|
using PARR.API.Contracts.V1;
|
||||||
using PARR.API.Contracts.V1.Requests.Queries;
|
using PARR.API.Contracts.V1.Requests.Queries;
|
||||||
@@ -18,21 +17,18 @@ namespace PARR.API.Controllers.V1
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class AgentTaskController : BaseApiController
|
public class AgentTaskController : BaseApiController
|
||||||
{
|
{
|
||||||
private readonly IMapper mapper;
|
|
||||||
private readonly IClientService clientService;
|
private readonly IClientService clientService;
|
||||||
private readonly ITemplateService templateService;
|
private readonly ITemplateService templateService;
|
||||||
private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
private readonly IEsppScheduleTransformService esppScheduleTransformService;
|
||||||
private readonly ILogger<AgentTaskController> logger;
|
private readonly ILogger<AgentTaskController> logger;
|
||||||
|
|
||||||
public AgentTaskController(
|
public AgentTaskController(
|
||||||
IMapper mapper,
|
|
||||||
IClientService clientService,
|
IClientService clientService,
|
||||||
ITemplateService templateService,
|
ITemplateService templateService,
|
||||||
IEsppScheduleTransformService esppScheduleTransformService,
|
IEsppScheduleTransformService esppScheduleTransformService,
|
||||||
ILogger<AgentTaskController> logger
|
ILogger<AgentTaskController> logger
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.mapper = mapper;
|
|
||||||
this.clientService = clientService;
|
this.clientService = clientService;
|
||||||
this.templateService = templateService;
|
this.templateService = templateService;
|
||||||
this.esppScheduleTransformService = esppScheduleTransformService;
|
this.esppScheduleTransformService = esppScheduleTransformService;
|
||||||
@@ -59,12 +55,13 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
var date = request.Date ?? DateTimeOffset.UtcNow;
|
var date = request.Date ?? DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
//Агент получает задания, если `IsAgent = true`, шаблон и расписания активны, и статус синхронизации шаблона и расписания `= Ok`, и `NextRun = сегодня`.
|
//Агент получает задания, если `IsAgent = true`, шаблон и расписания активны, и статус синхронизации шаблона и расписания `= Ok`, и `NextRun = сегодня`, так же если у ApplicationInWork есть расписание.
|
||||||
|
|
||||||
// С одним IP может быть несколько информационных систем, так что может быть несколько хостов
|
// С одним IP может быть несколько информационных систем, так что может быть несколько хостов
|
||||||
var templates = await templateService.Get()
|
var templates = await templateService.Get()
|
||||||
.Include(t => t.RobotConfigurations)
|
.Include(t => t.RobotConfigurations)
|
||||||
.Include(t => t.ApplicationsInWork)
|
.Include(t => t.ApplicationsInWork)
|
||||||
|
.ThenInclude(t => t!.EsppSchValues)
|
||||||
.Include(t => t.Host)
|
.Include(t => t.Host)
|
||||||
.Where(t => t.Host!.IP == ip
|
.Where(t => t.Host!.IP == ip
|
||||||
&& t.ApplicationsInWork!.IsAgent == true
|
&& t.ApplicationsInWork!.IsAgent == true
|
||||||
@@ -72,14 +69,12 @@ namespace PARR.API.Controllers.V1
|
|||||||
&& t.IsActiveSchedule == true
|
&& t.IsActiveSchedule == true
|
||||||
&& t.ApplicationsInWork!.NextRun.DateTime.Date == date.Date.Date
|
&& t.ApplicationsInWork!.NextRun.DateTime.Date == date.Date.Date
|
||||||
&& t.RobotConfigurations.All(c => c.TaskStatusCode == (int)TaskStatusEnum.Ok)
|
&& t.RobotConfigurations.All(c => c.TaskStatusCode == (int)TaskStatusEnum.Ok)
|
||||||
|
&& t.ApplicationsInWork.EsppSchValues.Any()
|
||||||
).ToListAsync();
|
).ToListAsync();
|
||||||
|
|
||||||
if (!templates.Any())
|
if (!templates.Any())
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
// запросить расписание на день для каждого шаблона и сформировать из него список
|
|
||||||
//TODO: идти в appInWorks и отуда формировать список заданий. Так же, как делать если время у заданий совпадает?
|
|
||||||
|
|
||||||
var response = new AgentTaskMinResponse
|
var response = new AgentTaskMinResponse
|
||||||
{
|
{
|
||||||
Scheduled = new List<AgentTaskMinScheduleResponse>()
|
Scheduled = new List<AgentTaskMinScheduleResponse>()
|
||||||
@@ -91,20 +86,25 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
if (!templateSchedule.Any())
|
if (!templateSchedule.Any())
|
||||||
{
|
{
|
||||||
logger.LogWarning($"Запросили рапсисание для агента по LastRun и вернулся пустой список! Такого не должно быть! " +
|
logger.LogWarning($"Запросили раписание для агента по LastRun и вернулся пустой список! Такого не должно быть! " +
|
||||||
$"ApplicationInWorkId: {template.ApplicationInWorkId}, latRun: {template.ApplicationsInWork!.LastRun}, NextRun: {template.ApplicationsInWork!.NextRun}, ip: {ip}, date: {date}");
|
$"ApplicationInWorkId: {template.ApplicationInWorkId}, latRun: {template.ApplicationsInWork!.LastRun}, NextRun: {template.ApplicationsInWork!.NextRun}, ip: {ip}, date: {date}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: проверку что в бд есть поля AgentName, AgentScript
|
if (string.IsNullOrEmpty(template.ApplicationsInWork.AgentName) || string.IsNullOrEmpty(template.ApplicationsInWork.AgentScript))
|
||||||
|
{
|
||||||
|
logger.LogWarning($"Запросили задание для агента с пустыми значениями AgentName || AgentScript. Такого не должно быть! " +
|
||||||
|
$"ApplicationInWorkId: {template.ApplicationInWorkId}, AgentName: {template.ApplicationsInWork.AgentName}, AgentScript: {template.ApplicationsInWork.AgentScript} , ip: {ip}, date: {date}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
templateSchedule.ForEach(item => response.Scheduled.Add(new AgentTaskMinScheduleResponse { Name = template.ApplicationsInWork!.AgentName, Script = template.ApplicationsInWork!.AgentScript, StartAt = item }));
|
templateSchedule.ForEach(item => response.Scheduled.Add(new AgentTaskMinScheduleResponse { Name = template.ApplicationsInWork!.AgentName, Script = template.ApplicationsInWork!.AgentScript, StartAt = item }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// отсортировать потом по дате
|
if (!response.Scheduled.Any())
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
// минимальный респонс
|
return Ok(response.Scheduled.OrderBy(t => t.StartAt));
|
||||||
|
|
||||||
return Ok(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user