feat(api): Контроллер по управлению ScheduleEsppId. Получение задания для расписания.
This commit is contained in:
@@ -55,14 +55,23 @@
|
||||
public static class Template
|
||||
{
|
||||
public const string GetAll = Base + "/templates/";
|
||||
public const string Get = Base + "/templates/" + getParam;
|
||||
public const string SetOkStatus = Base + "/templates/" + getParam + "/status/ok";
|
||||
public const string GetByStatusCode = Base + "/templates/status/{statusCode}";
|
||||
//public const string Get = Base + "/templates/" + getParam;
|
||||
//public const string SetOkStatus = Base + "/templates/" + getParam + "/status/ok";
|
||||
//public const string GetByStatusCode = Base + "/templates/status/{statusCode}";
|
||||
|
||||
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
|
||||
public static class TemplateScheduleEspp
|
||||
{
|
||||
public const string Get = Base + "/templates/" + templateId + "/schedule-esppid";
|
||||
|
||||
public const string Create = Base + "/templates/" + templateId + "/schedule-esppid";
|
||||
|
||||
public const string templateId = "{templateId}";
|
||||
}
|
||||
|
||||
public static class RobotHistory
|
||||
{
|
||||
//public const string GetAll = Base + "/robot-histories/";
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace PARR.API.Contracts.V1.Requests
|
||||
{
|
||||
public class TemplateScheduleEsppIdRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор расписания ЕСПП
|
||||
/// </summary>
|
||||
public string ScheduleEsppId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class TemplateScheduleEsppIdResponse
|
||||
{
|
||||
public string? ScheduleEsppId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -41,12 +41,16 @@ namespace PARR.API.Controllers.V1
|
||||
//Ищем все задания с превышенным кол-вом попыток и с просроченным временем и ставим им статус ошибки
|
||||
await robotConfigurationService.FindUnfulfilledTaskAndSetRobotErrorStatusAsync(settingsFromDb.RobotAttemptsNumber, settingsFromDb.RobotWaitTime);
|
||||
|
||||
|
||||
var query = robotConfigurationService.Get()
|
||||
.Where(t => t.RobotCode == (int)robotCode && t.TaskStatusCode == (int)taskStatusCode);
|
||||
|
||||
//var query = robotConfigurationService.Get();
|
||||
|
||||
switch (robotCode)
|
||||
{
|
||||
case RobotsEnum.TemplateOrder:
|
||||
// шаблоны
|
||||
query = query.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Host).ThenInclude(t => t!.ResponseArea)
|
||||
.Include(t => t.Template)
|
||||
@@ -58,6 +62,7 @@ namespace PARR.API.Controllers.V1
|
||||
.AsSplitQuery();
|
||||
break;
|
||||
case RobotsEnum.ScheduleOrder:
|
||||
//расписание
|
||||
// тут не делаем AsSplitQuery, не может подтянуть все таблицы
|
||||
query = query.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Host).ThenInclude(t => t!.ResponseArea)
|
||||
@@ -65,9 +70,15 @@ namespace PARR.API.Controllers.V1
|
||||
.ThenInclude(t => t!.ApplicationsInWork)
|
||||
.ThenInclude(t => t!.EsppSchValues)
|
||||
.ThenInclude(t => t!.EsppSchTypeConfig)
|
||||
.ThenInclude(t => t!.EsppSchTypeSchedule)
|
||||
;
|
||||
//todo: include
|
||||
.ThenInclude(t => t!.EsppSchTypeSchedule);
|
||||
|
||||
//выбираем только записи с созданными шаблонами (у которых статус 30), а только потом у них ищем расписания
|
||||
// сначала находим шаблоны со статусом 30
|
||||
var createdTemplates = robotConfigurationService.Get()
|
||||
.Where(t => t.RobotCode == (int)RobotsEnum.TemplateOrder && t.TaskStatusCode == (int)TaskStatusEnum.Ok)
|
||||
.Select(t => t.TemplateId);
|
||||
//находим задания с расписанием по списку шаблонов createdTemplates
|
||||
query = query.Where(t => t.RobotCode == (int)RobotsEnum.ScheduleOrder && createdTemplates.Contains(t.TemplateId));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -75,7 +86,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
RobotConfiguration? task = null;
|
||||
|
||||
//ищем задание в ожидании, если нашли, выбираем ее
|
||||
//ищем задание в ожидании, если нашли, выбираем его
|
||||
task = await query.FirstOrDefaultAsync(t => t.RobotStatusCode == (int)RobotStatusEnum.Wait);
|
||||
|
||||
if (task == null)
|
||||
@@ -104,7 +115,6 @@ namespace PARR.API.Controllers.V1
|
||||
return Ok(new Response<RobotTaskTemplateResponse>(mapper.Map<RobotTaskTemplateResponse>(task), true));
|
||||
case RobotsEnum.ScheduleOrder:
|
||||
//RobotTaskScheduleResponse
|
||||
//TODO: сделать маппинг!!!
|
||||
return Ok(new Response<RobotTaskScheduleResponse>(mapper.Map<RobotTaskScheduleResponse>(task), true));
|
||||
default:
|
||||
break;
|
||||
|
||||
82
PARR.API/Controllers/V1/TemplateScheduleEspp.cs
Normal file
82
PARR.API/Controllers/V1/TemplateScheduleEspp.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using AutoMapper;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Контроллер по управлению ScheduleEsppId у шаблона
|
||||
/// </summary>
|
||||
public class TemplateScheduleEspp : BaseApiController
|
||||
{
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IMapper mapper;
|
||||
private readonly IValidator<TemplateScheduleEsppIdRequest> validator;
|
||||
private readonly IUriService uriService;
|
||||
|
||||
public TemplateScheduleEspp(
|
||||
ITemplateService templateService,
|
||||
IMapper mapper,
|
||||
IValidator<TemplateScheduleEsppIdRequest> validator,
|
||||
IUriService uriService
|
||||
)
|
||||
{
|
||||
this.templateService = templateService;
|
||||
this.mapper = mapper;
|
||||
this.validator = validator;
|
||||
this.uriService = uriService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить ИД расписания ЕСПП по ИД шаблона
|
||||
/// </summary>
|
||||
/// <param name="templateId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.TemplateScheduleEspp.Get)]
|
||||
public async Task<IActionResult> Get([FromRoute] Guid templateId)
|
||||
{
|
||||
var template = await templateService.GetAsync(templateId);
|
||||
|
||||
if (template == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {templateId}" } }));
|
||||
|
||||
return Ok(new Response<TemplateScheduleEsppIdResponse>(mapper.Map<TemplateScheduleEsppIdResponse>(template), true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Задать ИД расписания ЕСПП шаблону с ИД
|
||||
/// </summary>
|
||||
/// <param name="templateId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.TemplateScheduleEspp.Create)]
|
||||
public async Task<IActionResult> SetEsppId([FromRoute] Guid templateId, [FromBody] TemplateScheduleEsppIdRequest request)
|
||||
{
|
||||
var resultValidate = await validator.ValidateAsync(request);
|
||||
if (!resultValidate.IsValid)
|
||||
return BadRequest(new Response(resultValidate.Errors));
|
||||
|
||||
var template = await templateService.GetAsync(templateId);
|
||||
|
||||
if (template == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {templateId}" } }));
|
||||
|
||||
template.ScheduleEsppId = request.ScheduleEsppId;
|
||||
|
||||
if (!await templateService.CommitAsync())
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при сохранении шаблона." } }));
|
||||
|
||||
var createdUri = uriService.GetUri(ApiRoutes.TemplateScheduleEspp.Get, ApiRoutes.TemplateScheduleEspp.templateId, templateId);
|
||||
|
||||
return Created(createdUri, new Response<TemplateScheduleEsppIdResponse>(mapper.Map<TemplateScheduleEsppIdResponse>(template), true));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,8 @@ namespace PARR.API.MappingProfiles
|
||||
.ForMember(d => d.SyncStatus, o => o.MapFrom(s => s.RobotConfigurations));
|
||||
// === Template ===
|
||||
|
||||
CreateMap<Template, TemplateScheduleEsppIdResponse>();
|
||||
|
||||
CreateMap<DAL.Models.TaskStatus, TaskStatusResponse>();
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using FluentValidation;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
|
||||
namespace PARR.API.Validators
|
||||
{
|
||||
public class TemplateScheduleEsppIdRequestValidator : AbstractValidator<TemplateScheduleEsppIdRequest>
|
||||
{
|
||||
public TemplateScheduleEsppIdRequestValidator()
|
||||
{
|
||||
RuleFor(t => t.ScheduleEsppId).NotNull().NotEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user