refactor(api): Удалены лишние таблицы связанные со старой логикой получения заданий роботом.
This commit is contained in:
@@ -63,23 +63,15 @@
|
||||
public const string getParam = "{id}";
|
||||
}
|
||||
|
||||
public static class TemplateRobotStatus
|
||||
{
|
||||
public const string Get = Base + "/templates/" + templateId + "/robot-statuses";
|
||||
public const string Update = Base + "/templates/" + templateId + "/robot-statuses";
|
||||
|
||||
public const string templateId = "{templateId}";
|
||||
}
|
||||
|
||||
public static class RobotHistory
|
||||
{
|
||||
//public const string GetAll = Base + "/robot-histories/";
|
||||
public const string Create = Base + "/robot-histories/";
|
||||
}
|
||||
|
||||
public static class StatusTemplate
|
||||
public static class TaskStatus
|
||||
{
|
||||
public const string GetAll = Base + "/template-statuses/";
|
||||
public const string GetAll = Base + "/task-statuses/";
|
||||
}
|
||||
|
||||
public static class GeneratorTemplate
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class StatusTemplateResponse
|
||||
{
|
||||
public int Code { get; set; }
|
||||
|
||||
public required string Name { get; set; }
|
||||
|
||||
public required string Description { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class TemplateRobotStatusResponse : RobotStatusResponse
|
||||
{
|
||||
public int RobotAttemptsNumber { get; set; }
|
||||
public DateTimeOffset? RobotLastStatusUpdated { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.BLL.Settings;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class EsppDataController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<EsppDataController> logger;
|
||||
private readonly IFileService fileService;
|
||||
private readonly StorageSettings storageSettings;
|
||||
|
||||
public EsppDataController(
|
||||
ILogger<EsppDataController> logger,
|
||||
IFileService fileService,
|
||||
StorageSettings storageSettings
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.fileService = fileService;
|
||||
this.storageSettings = storageSettings;
|
||||
}
|
||||
|
||||
// UploadTemplates - неактуально, так как стали брать данные с RabbitMQ
|
||||
|
||||
///// <summary>
|
||||
///// Загрузить файл списка шаблонов полученных из ЕСПП в формате csv
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//[HttpPost(ApiRoutes.EsppData.UploadTemplates)]
|
||||
//public async Task<IActionResult> UploadTemplates([BindRequired] IFormFile file)
|
||||
//{
|
||||
// if (!fileService.IsExtensionAllowed(file, storageSettings.EsppTemplates!.AllowedExtensions))
|
||||
// return BadRequest(
|
||||
// new Response(false,
|
||||
// new List<ErrorModel> {
|
||||
// new ErrorModel {
|
||||
// Message = $"Недопустимое расширение файла. Разрешенные расширения: {string.Join(", ", storageSettings.EsppTemplates.AllowedExtensions)}"
|
||||
// } }));
|
||||
|
||||
// if (!fileService.IsNotExceededLimit(file, storageSettings.EsppTemplates.MaxFileSizeMb))
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { FieldName = nameof(file), Message = $"Размер файла превышает {storageSettings.EsppTemplates.MaxFileSizeMb} МБайт" } }));
|
||||
|
||||
// var uploadResult = await fileService.UploadAsync(file, storageSettings.EsppTemplates.TemplatePath);
|
||||
// if (uploadResult == null)
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при сохранении файла" } }));
|
||||
|
||||
// return Ok(new Response<string>("", true, new List<ErrorModel>(), $"Файл загружен."));
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,7 @@ namespace PARR.API.Controllers.V1
|
||||
public class RobotHistoryController : BaseApiController
|
||||
{
|
||||
private readonly IValidator<RobotHistoryRequest> validator;
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IRobotTemplateHistoryService historyService;
|
||||
|
||||
private readonly IMapper mapper;
|
||||
private readonly IUriService uriService;
|
||||
private readonly IRobotHistoryService robotHistoryService;
|
||||
@@ -25,8 +24,6 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
public RobotHistoryController(
|
||||
IValidator<RobotHistoryRequest> validator,
|
||||
ITemplateService templateService,
|
||||
IRobotTemplateHistoryService historyService,
|
||||
IMapper mapper,
|
||||
IUriService uriService,
|
||||
IRobotHistoryService robotHistoryService,
|
||||
@@ -34,8 +31,6 @@ namespace PARR.API.Controllers.V1
|
||||
)
|
||||
{
|
||||
this.validator = validator;
|
||||
this.templateService = templateService;
|
||||
this.historyService = historyService;
|
||||
this.mapper = mapper;
|
||||
this.uriService = uriService;
|
||||
this.robotHistoryService = robotHistoryService;
|
||||
|
||||
@@ -9,12 +9,12 @@ using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class StatusTemplateController : BaseApiController
|
||||
public class TaskStatusController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IStatusTemplateService statusTemplateService;
|
||||
|
||||
public StatusTemplateController(
|
||||
public TaskStatusController(
|
||||
IMapper mapper,
|
||||
IStatusTemplateService statusTemplateService
|
||||
)
|
||||
@@ -24,19 +24,19 @@ namespace PARR.API.Controllers.V1
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список статусов
|
||||
/// Получить список статусов заданий
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatusTemplate.GetAll)]
|
||||
[HttpGet(ApiRoutes.TaskStatus.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var statusList = await statusTemplateService.Get()
|
||||
.OrderBy(t => t.Code)
|
||||
.ToListAsync();
|
||||
|
||||
var response = mapper.Map<List<StatusTemplateResponse>>(statusList);
|
||||
var response = mapper.Map<List<TaskStatusResponse>>(statusList);
|
||||
|
||||
return Ok(new Response<List<StatusTemplateResponse>>(response, true));
|
||||
return Ok(new Response<List<TaskStatusResponse>>(response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,23 +47,25 @@ namespace PARR.API.Controllers.V1
|
||||
.OrderBy(t => t.Name)
|
||||
.AsSplitQuery();
|
||||
|
||||
if (filter.StatusCode.HasValue)
|
||||
{
|
||||
switch (filter.StatusCode.Value)
|
||||
{
|
||||
case (int)TaskStatusEnum.Ok:
|
||||
query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Ok);
|
||||
break;
|
||||
case (int)TaskStatusEnum.Creating:
|
||||
query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Creating);
|
||||
break;
|
||||
case (int)TaskStatusEnum.Updating:
|
||||
query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Updating);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
//TODO:!!!
|
||||
|
||||
//if (filter.StatusCode.HasValue)
|
||||
//{
|
||||
// switch (filter.StatusCode.Value)
|
||||
// {
|
||||
// case (int)TaskStatusEnum.Ok:
|
||||
// query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Ok);
|
||||
// break;
|
||||
// case (int)TaskStatusEnum.Creating:
|
||||
// query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Creating);
|
||||
// break;
|
||||
// case (int)TaskStatusEnum.Updating:
|
||||
// query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Updating);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (!string.IsNullOrEmpty(filter.Mask))
|
||||
query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(filter.Mask)));
|
||||
@@ -84,75 +86,75 @@ namespace PARR.API.Controllers.V1
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Template.Get)]
|
||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||
{
|
||||
var template = await templateService.GetWithIncludes()
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
//[HttpGet(ApiRoutes.Template.Get)]
|
||||
//public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||
//{
|
||||
// var template = await templateService.GetWithIncludes()
|
||||
// .AsSplitQuery()
|
||||
// .FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (template == null)
|
||||
return NotFound();
|
||||
// if (template == null)
|
||||
// return NotFound();
|
||||
|
||||
var response = mapper.Map<TemplateResponse>(template);
|
||||
// var response = mapper.Map<TemplateResponse>(template);
|
||||
|
||||
return Ok(new Response<TemplateResponse>(response, true));
|
||||
}
|
||||
// return Ok(new Response<TemplateResponse>(response, true));
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Получить один шаблон по заданному статусу
|
||||
/// </summary>
|
||||
/// <param name="statusCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Template.GetByStatusCode)]
|
||||
public async Task<IActionResult> GetByStatus([FromRoute] int statusCode, [FromQuery] RobinQuery query)
|
||||
{
|
||||
Template? template = null;
|
||||
//[HttpGet(ApiRoutes.Template.GetByStatusCode)]
|
||||
//public async Task<IActionResult> GetByStatus([FromRoute] int statusCode, [FromQuery] RobinQuery query)
|
||||
//{
|
||||
// Template? template = null;
|
||||
|
||||
//1.Ищем `RobotStatusCode` = 22 и `RobotLastStatusUpdated` истекло и `RobotAttemptsNumber` >= допустимого значения из настроек,
|
||||
//ставим всем этим записям `RobotStatusCode`= 33
|
||||
//2.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 11.Находим, **выбрали эту запись, конец**.
|
||||
//3.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 22.
|
||||
//Далее проверяется `RobotLastStatusUpdated`, что время последнего смены статуса не превышает допустимого(берется из настроек, поле `RobotWaitTime`)
|
||||
//и что текущая попытка не больше разрешенной(берется из настроек, поле `RobotAttemptsNumber`) - если это так, берется эта запись.
|
||||
// //1.Ищем `RobotStatusCode` = 22 и `RobotLastStatusUpdated` истекло и `RobotAttemptsNumber` >= допустимого значения из настроек,
|
||||
// //ставим всем этим записям `RobotStatusCode`= 33
|
||||
// //2.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 11.Находим, **выбрали эту запись, конец**.
|
||||
// //3.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 22.
|
||||
// //Далее проверяется `RobotLastStatusUpdated`, что время последнего смены статуса не превышает допустимого(берется из настроек, поле `RobotWaitTime`)
|
||||
// //и что текущая попытка не больше разрешенной(берется из настроек, поле `RobotAttemptsNumber`) - если это так, берется эта запись.
|
||||
|
||||
//1.
|
||||
await templateService.CheckAndSetErrorRobotStatusAsync(settingsFromDb.RobotAttemptsNumber, settingsFromDb.RobotWaitTime);
|
||||
// //1.
|
||||
// await templateService.CheckAndSetErrorRobotStatusAsync(settingsFromDb.RobotAttemptsNumber, settingsFromDb.RobotWaitTime);
|
||||
|
||||
|
||||
//2.
|
||||
template = await templateService.GetWithIncludes()
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.StatusCode == statusCode && t.RobotStatusCode == (int)RobotStatusEnum.Wait);
|
||||
// //2.
|
||||
// template = await templateService.GetWithIncludes()
|
||||
// .AsSplitQuery()
|
||||
// .FirstOrDefaultAsync(t => t.StatusCode == statusCode && t.RobotStatusCode == (int)RobotStatusEnum.Wait);
|
||||
|
||||
//3.
|
||||
if (template == null)
|
||||
{
|
||||
var endDate = DateTimeOffset.UtcNow.Add(-settingsFromDb.RobotWaitTime);
|
||||
template = await templateService.GetWithIncludes()
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t =>
|
||||
t.StatusCode == statusCode
|
||||
&& t.RobotStatusCode == (int)RobotStatusEnum.InProgress
|
||||
&& t.RobotAttemptsNumber < settingsFromDb.RobotAttemptsNumber
|
||||
&& t.RobotLastStatusUpdated < endDate
|
||||
);
|
||||
}
|
||||
// //3.
|
||||
// if (template == null)
|
||||
// {
|
||||
// var endDate = DateTimeOffset.UtcNow.Add(-settingsFromDb.RobotWaitTime);
|
||||
// template = await templateService.GetWithIncludes()
|
||||
// .AsSplitQuery()
|
||||
// .FirstOrDefaultAsync(t =>
|
||||
// t.StatusCode == statusCode
|
||||
// && t.RobotStatusCode == (int)RobotStatusEnum.InProgress
|
||||
// && t.RobotAttemptsNumber < settingsFromDb.RobotAttemptsNumber
|
||||
// && t.RobotLastStatusUpdated < endDate
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
if (template == null)
|
||||
return NotFound();
|
||||
// if (template == null)
|
||||
// return NotFound();
|
||||
|
||||
var response = mapper.Map<TemplateResponse>(template);
|
||||
// var response = mapper.Map<TemplateResponse>(template);
|
||||
|
||||
if (query.Robin == true)
|
||||
{
|
||||
var stringResponse = mapper.Map<TemplateStringResponse>(response);
|
||||
return Ok(stringResponse);
|
||||
}
|
||||
// if (query.Robin == true)
|
||||
// {
|
||||
// var stringResponse = mapper.Map<TemplateStringResponse>(response);
|
||||
// return Ok(stringResponse);
|
||||
// }
|
||||
|
||||
return Ok(new Response<TemplateResponse>(response, true));
|
||||
}
|
||||
// return Ok(new Response<TemplateResponse>(response, true));
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -160,25 +162,25 @@ namespace PARR.API.Controllers.V1
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut(ApiRoutes.Template.SetOkStatus)]
|
||||
public async Task<IActionResult> SetOkStatus([FromRoute] Guid id)
|
||||
{
|
||||
var template = await templateService.GetWithIncludes()
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
//[HttpPut(ApiRoutes.Template.SetOkStatus)]
|
||||
//public async Task<IActionResult> SetOkStatus([FromRoute] Guid id)
|
||||
//{
|
||||
// var template = await templateService.GetWithIncludes()
|
||||
// .AsSplitQuery()
|
||||
// .FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (template == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {id}" } }));
|
||||
// if (template == null)
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {id}" } }));
|
||||
|
||||
template.StatusCode = (int)TaskStatusEnum.Ok;
|
||||
// template.StatusCode = (int)TaskStatusEnum.Ok;
|
||||
|
||||
if (!await templateService.CommitAsync())
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при изменении статуса у шаблона с id: {id}" } }));
|
||||
// if (!await templateService.CommitAsync())
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при изменении статуса у шаблона с id: {id}" } }));
|
||||
|
||||
var response = mapper.Map<TemplateResponse>(template);
|
||||
// var response = mapper.Map<TemplateResponse>(template);
|
||||
|
||||
return Ok(new Response<TemplateResponse>(response, true));
|
||||
}
|
||||
// return Ok(new Response<TemplateResponse>(response, true));
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
using AutoMapper;
|
||||
using FluentValidation;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class TemplateRobotStatusController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IValidator<TemplateRobotStatusRequest> validator;
|
||||
|
||||
public TemplateRobotStatusController(
|
||||
IMapper mapper,
|
||||
ITemplateService templateService,
|
||||
IValidator<TemplateRobotStatusRequest> validator
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.templateService = templateService;
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить статус робота по Id шаблона
|
||||
/// </summary>
|
||||
/// <param name="templateId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.TemplateRobotStatus.Get)]
|
||||
public async Task<IActionResult> Get([FromRoute] Guid templateId)
|
||||
{
|
||||
var template = await templateService.Get()
|
||||
.Include(t => t.RobotStatus)
|
||||
.FirstOrDefaultAsync(t => t.Id == templateId);
|
||||
|
||||
if (template == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {templateId}" } }));
|
||||
|
||||
var response = mapper.Map<TemplateRobotStatusResponse>(template);
|
||||
|
||||
return Ok(new Response<TemplateRobotStatusResponse>(response, true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Обновить статус робота по Id шаблона
|
||||
/// </summary>
|
||||
/// <param name="templateId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut(ApiRoutes.TemplateRobotStatus.Update)]
|
||||
public async Task<IActionResult> UpdateStatus([FromRoute] Guid templateId, [FromBody] TemplateRobotStatusRequest request)
|
||||
{
|
||||
var resultValidate = await validator.ValidateAsync(request);
|
||||
if (!resultValidate.IsValid)
|
||||
return BadRequest(new Response(resultValidate.Errors));
|
||||
|
||||
var template = await templateService.Get()
|
||||
.FirstOrDefaultAsync(t => t.Id == templateId);
|
||||
|
||||
if (template == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {templateId}" } }));
|
||||
|
||||
var enumStatus = (RobotStatusEnum)request.Code;
|
||||
|
||||
// изменение статуса
|
||||
templateService.ChangeRobotStatus(enumStatus, ref template);
|
||||
|
||||
if (!await templateService.CommitAsync())
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при изменении статуса шаблону {templateId}" } }));
|
||||
|
||||
var templateToResponse = await templateService.Get()
|
||||
.Include(t => t.RobotStatus)
|
||||
.FirstOrDefaultAsync(t => t.Id == templateId);
|
||||
|
||||
var response = mapper.Map<TemplateRobotStatusResponse>(templateToResponse);
|
||||
|
||||
return Ok(new Response<TemplateRobotStatusResponse>(response, true));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -63,12 +63,7 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
// === Template ===
|
||||
|
||||
CreateMap<DAL.Models.TaskStatus, StatusTemplateResponse>();
|
||||
|
||||
CreateMap<Template, TemplateRobotStatusResponse>()
|
||||
.ForMember(d => d.Code, o => o.MapFrom(s => s.RobotStatus!.Code))
|
||||
.ForMember(d => d.Name, o => o.MapFrom(s => s.RobotStatus!.Name))
|
||||
.ForMember(d => d.Description, o => o.MapFrom(s => s.RobotStatus!.Description));
|
||||
CreateMap<DAL.Models.TaskStatus, TaskStatusResponse>();
|
||||
|
||||
|
||||
CreateMap<Process, ProcessResponse>();
|
||||
|
||||
Reference in New Issue
Block a user