refactor(api): Удалены лишние таблицы связанные со старой логикой получения заданий роботом.
This commit is contained in:
@@ -63,23 +63,15 @@
|
|||||||
public const string getParam = "{id}";
|
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 static class RobotHistory
|
||||||
{
|
{
|
||||||
//public const string GetAll = Base + "/robot-histories/";
|
//public const string GetAll = Base + "/robot-histories/";
|
||||||
public const string Create = 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
|
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
|
public class RobotHistoryController : BaseApiController
|
||||||
{
|
{
|
||||||
private readonly IValidator<RobotHistoryRequest> validator;
|
private readonly IValidator<RobotHistoryRequest> validator;
|
||||||
private readonly ITemplateService templateService;
|
|
||||||
private readonly IRobotTemplateHistoryService historyService;
|
|
||||||
private readonly IMapper mapper;
|
private readonly IMapper mapper;
|
||||||
private readonly IUriService uriService;
|
private readonly IUriService uriService;
|
||||||
private readonly IRobotHistoryService robotHistoryService;
|
private readonly IRobotHistoryService robotHistoryService;
|
||||||
@@ -25,8 +24,6 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
public RobotHistoryController(
|
public RobotHistoryController(
|
||||||
IValidator<RobotHistoryRequest> validator,
|
IValidator<RobotHistoryRequest> validator,
|
||||||
ITemplateService templateService,
|
|
||||||
IRobotTemplateHistoryService historyService,
|
|
||||||
IMapper mapper,
|
IMapper mapper,
|
||||||
IUriService uriService,
|
IUriService uriService,
|
||||||
IRobotHistoryService robotHistoryService,
|
IRobotHistoryService robotHistoryService,
|
||||||
@@ -34,8 +31,6 @@ namespace PARR.API.Controllers.V1
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
this.templateService = templateService;
|
|
||||||
this.historyService = historyService;
|
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.uriService = uriService;
|
this.uriService = uriService;
|
||||||
this.robotHistoryService = robotHistoryService;
|
this.robotHistoryService = robotHistoryService;
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ using PARR.DAL.Services.Interfaces;
|
|||||||
|
|
||||||
namespace PARR.API.Controllers.V1
|
namespace PARR.API.Controllers.V1
|
||||||
{
|
{
|
||||||
public class StatusTemplateController : BaseApiController
|
public class TaskStatusController : BaseApiController
|
||||||
{
|
{
|
||||||
private readonly IMapper mapper;
|
private readonly IMapper mapper;
|
||||||
private readonly IStatusTemplateService statusTemplateService;
|
private readonly IStatusTemplateService statusTemplateService;
|
||||||
|
|
||||||
public StatusTemplateController(
|
public TaskStatusController(
|
||||||
IMapper mapper,
|
IMapper mapper,
|
||||||
IStatusTemplateService statusTemplateService
|
IStatusTemplateService statusTemplateService
|
||||||
)
|
)
|
||||||
@@ -24,19 +24,19 @@ namespace PARR.API.Controllers.V1
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить список статусов
|
/// Получить список статусов заданий
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet(ApiRoutes.StatusTemplate.GetAll)]
|
[HttpGet(ApiRoutes.TaskStatus.GetAll)]
|
||||||
public async Task<IActionResult> GetAll()
|
public async Task<IActionResult> GetAll()
|
||||||
{
|
{
|
||||||
var statusList = await statusTemplateService.Get()
|
var statusList = await statusTemplateService.Get()
|
||||||
.OrderBy(t => t.Code)
|
.OrderBy(t => t.Code)
|
||||||
.ToListAsync();
|
.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)
|
.OrderBy(t => t.Name)
|
||||||
.AsSplitQuery();
|
.AsSplitQuery();
|
||||||
|
|
||||||
if (filter.StatusCode.HasValue)
|
//TODO:!!!
|
||||||
{
|
|
||||||
switch (filter.StatusCode.Value)
|
//if (filter.StatusCode.HasValue)
|
||||||
{
|
//{
|
||||||
case (int)TaskStatusEnum.Ok:
|
// switch (filter.StatusCode.Value)
|
||||||
query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Ok);
|
// {
|
||||||
break;
|
// case (int)TaskStatusEnum.Ok:
|
||||||
case (int)TaskStatusEnum.Creating:
|
// query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Ok);
|
||||||
query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Creating);
|
// break;
|
||||||
break;
|
// case (int)TaskStatusEnum.Creating:
|
||||||
case (int)TaskStatusEnum.Updating:
|
// query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Creating);
|
||||||
query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Updating);
|
// break;
|
||||||
break;
|
// case (int)TaskStatusEnum.Updating:
|
||||||
default:
|
// query = query.Where(t => t.StatusCode == (int)TaskStatusEnum.Updating);
|
||||||
break;
|
// break;
|
||||||
}
|
// default:
|
||||||
}
|
// break;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filter.Mask))
|
if (!string.IsNullOrEmpty(filter.Mask))
|
||||||
query = query.Where(t => EF.Functions.Like(t.Name.ToLower(), SqlHelpers.RegexToLike(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>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet(ApiRoutes.Template.Get)]
|
//[HttpGet(ApiRoutes.Template.Get)]
|
||||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
//public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||||
{
|
//{
|
||||||
var template = await templateService.GetWithIncludes()
|
// var template = await templateService.GetWithIncludes()
|
||||||
.AsSplitQuery()
|
// .AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(t => t.Id == id);
|
// .FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
if (template == null)
|
// if (template == null)
|
||||||
return NotFound();
|
// 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>
|
||||||
/// Получить один шаблон по заданному статусу
|
/// Получить один шаблон по заданному статусу
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="statusCode"></param>
|
/// <param name="statusCode"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet(ApiRoutes.Template.GetByStatusCode)]
|
//[HttpGet(ApiRoutes.Template.GetByStatusCode)]
|
||||||
public async Task<IActionResult> GetByStatus([FromRoute] int statusCode, [FromQuery] RobinQuery query)
|
//public async Task<IActionResult> GetByStatus([FromRoute] int statusCode, [FromQuery] RobinQuery query)
|
||||||
{
|
//{
|
||||||
Template? template = null;
|
// Template? template = null;
|
||||||
|
|
||||||
//1.Ищем `RobotStatusCode` = 22 и `RobotLastStatusUpdated` истекло и `RobotAttemptsNumber` >= допустимого значения из настроек,
|
// //1.Ищем `RobotStatusCode` = 22 и `RobotLastStatusUpdated` истекло и `RobotAttemptsNumber` >= допустимого значения из настроек,
|
||||||
//ставим всем этим записям `RobotStatusCode`= 33
|
// //ставим всем этим записям `RobotStatusCode`= 33
|
||||||
//2.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 11.Находим, **выбрали эту запись, конец**.
|
// //2.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 11.Находим, **выбрали эту запись, конец**.
|
||||||
//3.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 22.
|
// //3.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 22.
|
||||||
//Далее проверяется `RobotLastStatusUpdated`, что время последнего смены статуса не превышает допустимого(берется из настроек, поле `RobotWaitTime`)
|
// //Далее проверяется `RobotLastStatusUpdated`, что время последнего смены статуса не превышает допустимого(берется из настроек, поле `RobotWaitTime`)
|
||||||
//и что текущая попытка не больше разрешенной(берется из настроек, поле `RobotAttemptsNumber`) - если это так, берется эта запись.
|
// //и что текущая попытка не больше разрешенной(берется из настроек, поле `RobotAttemptsNumber`) - если это так, берется эта запись.
|
||||||
|
|
||||||
//1.
|
// //1.
|
||||||
await templateService.CheckAndSetErrorRobotStatusAsync(settingsFromDb.RobotAttemptsNumber, settingsFromDb.RobotWaitTime);
|
// await templateService.CheckAndSetErrorRobotStatusAsync(settingsFromDb.RobotAttemptsNumber, settingsFromDb.RobotWaitTime);
|
||||||
|
|
||||||
|
|
||||||
//2.
|
// //2.
|
||||||
template = await templateService.GetWithIncludes()
|
// template = await templateService.GetWithIncludes()
|
||||||
.AsSplitQuery()
|
// .AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(t => t.StatusCode == statusCode && t.RobotStatusCode == (int)RobotStatusEnum.Wait);
|
// .FirstOrDefaultAsync(t => t.StatusCode == statusCode && t.RobotStatusCode == (int)RobotStatusEnum.Wait);
|
||||||
|
|
||||||
//3.
|
// //3.
|
||||||
if (template == null)
|
// if (template == null)
|
||||||
{
|
// {
|
||||||
var endDate = DateTimeOffset.UtcNow.Add(-settingsFromDb.RobotWaitTime);
|
// var endDate = DateTimeOffset.UtcNow.Add(-settingsFromDb.RobotWaitTime);
|
||||||
template = await templateService.GetWithIncludes()
|
// template = await templateService.GetWithIncludes()
|
||||||
.AsSplitQuery()
|
// .AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(t =>
|
// .FirstOrDefaultAsync(t =>
|
||||||
t.StatusCode == statusCode
|
// t.StatusCode == statusCode
|
||||||
&& t.RobotStatusCode == (int)RobotStatusEnum.InProgress
|
// && t.RobotStatusCode == (int)RobotStatusEnum.InProgress
|
||||||
&& t.RobotAttemptsNumber < settingsFromDb.RobotAttemptsNumber
|
// && t.RobotAttemptsNumber < settingsFromDb.RobotAttemptsNumber
|
||||||
&& t.RobotLastStatusUpdated < endDate
|
// && t.RobotLastStatusUpdated < endDate
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
if (template == null)
|
// if (template == null)
|
||||||
return NotFound();
|
// return NotFound();
|
||||||
|
|
||||||
var response = mapper.Map<TemplateResponse>(template);
|
// var response = mapper.Map<TemplateResponse>(template);
|
||||||
|
|
||||||
if (query.Robin == true)
|
// if (query.Robin == true)
|
||||||
{
|
// {
|
||||||
var stringResponse = mapper.Map<TemplateStringResponse>(response);
|
// var stringResponse = mapper.Map<TemplateStringResponse>(response);
|
||||||
return Ok(stringResponse);
|
// return Ok(stringResponse);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return Ok(new Response<TemplateResponse>(response, true));
|
// return Ok(new Response<TemplateResponse>(response, true));
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -160,25 +162,25 @@ namespace PARR.API.Controllers.V1
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut(ApiRoutes.Template.SetOkStatus)]
|
//[HttpPut(ApiRoutes.Template.SetOkStatus)]
|
||||||
public async Task<IActionResult> SetOkStatus([FromRoute] Guid id)
|
//public async Task<IActionResult> SetOkStatus([FromRoute] Guid id)
|
||||||
{
|
//{
|
||||||
var template = await templateService.GetWithIncludes()
|
// var template = await templateService.GetWithIncludes()
|
||||||
.AsSplitQuery()
|
// .AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(t => t.Id == id);
|
// .FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
if (template == null)
|
// if (template == null)
|
||||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найден шаблон с id: {id}" } }));
|
// 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())
|
// if (!await templateService.CommitAsync())
|
||||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при изменении статуса у шаблона с id: {id}" } }));
|
// 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 ===
|
// === Template ===
|
||||||
|
|
||||||
CreateMap<DAL.Models.TaskStatus, StatusTemplateResponse>();
|
CreateMap<DAL.Models.TaskStatus, TaskStatusResponse>();
|
||||||
|
|
||||||
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<Process, ProcessResponse>();
|
CreateMap<Process, ProcessResponse>();
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ namespace PARR.DAL.Context
|
|||||||
public DbSet<Models.Setting> Setting { get; set; }
|
public DbSet<Models.Setting> Setting { get; set; }
|
||||||
|
|
||||||
public DbSet<RobotHistoryLevel> RobotHistoryLevels { get; set; }
|
public DbSet<RobotHistoryLevel> RobotHistoryLevels { get; set; }
|
||||||
public DbSet<RobotTemplateHistory> RobotTemplateHistories { get; set; }
|
|
||||||
|
|
||||||
public DbSet<Robot> Robots { get; set; }
|
public DbSet<Robot> Robots { get; set; }
|
||||||
public DbSet<RobotConfiguration> RobotConfigurations { get; set; }
|
public DbSet<RobotConfiguration> RobotConfigurations { get; set; }
|
||||||
|
|||||||
1950
PARR.DAL/Migrations/20231006042130_TblTemplatesUpdate.Designer.cs
generated
Normal file
1950
PARR.DAL/Migrations/20231006042130_TblTemplatesUpdate.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
135
PARR.DAL/Migrations/20231006042130_TblTemplatesUpdate.cs
Normal file
135
PARR.DAL/Migrations/20231006042130_TblTemplatesUpdate.cs
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PARR.DAL.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class TblTemplatesUpdate : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Templates_TaskStatuses_StatusCode",
|
||||||
|
table: "Templates");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "RobotTemplateHistories");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "RobotAttemptsNumber",
|
||||||
|
table: "Templates");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "RobotLastStatusUpdated",
|
||||||
|
table: "Templates");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "StatusCode",
|
||||||
|
table: "Templates",
|
||||||
|
newName: "TaskStatusCode");
|
||||||
|
|
||||||
|
migrationBuilder.RenameIndex(
|
||||||
|
name: "IX_Templates_StatusCode",
|
||||||
|
table: "Templates",
|
||||||
|
newName: "IX_Templates_TaskStatusCode");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Templates_TaskStatuses_TaskStatusCode",
|
||||||
|
table: "Templates",
|
||||||
|
column: "TaskStatusCode",
|
||||||
|
principalTable: "TaskStatuses",
|
||||||
|
principalColumn: "Code");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Templates_TaskStatuses_TaskStatusCode",
|
||||||
|
table: "Templates");
|
||||||
|
|
||||||
|
migrationBuilder.RenameColumn(
|
||||||
|
name: "TaskStatusCode",
|
||||||
|
table: "Templates",
|
||||||
|
newName: "StatusCode");
|
||||||
|
|
||||||
|
migrationBuilder.RenameIndex(
|
||||||
|
name: "IX_Templates_TaskStatusCode",
|
||||||
|
table: "Templates",
|
||||||
|
newName: "IX_Templates_StatusCode");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "RobotAttemptsNumber",
|
||||||
|
table: "Templates",
|
||||||
|
type: "integer",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||||
|
name: "RobotLastStatusUpdated",
|
||||||
|
table: "Templates",
|
||||||
|
type: "timestamp with time zone",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "RobotTemplateHistories",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
HistoryLevel = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
TemplateId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
TemplateStatusCode = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||||
|
EsppMessage = table.Column<string>(type: "text", nullable: true),
|
||||||
|
IdSeries = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
RobotMessage = table.Column<string>(type: "text", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_RobotTemplateHistories", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_RobotTemplateHistories_RobotHistoryLevels_HistoryLevel",
|
||||||
|
column: x => x.HistoryLevel,
|
||||||
|
principalTable: "RobotHistoryLevels",
|
||||||
|
principalColumn: "Level",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_RobotTemplateHistories_TaskStatuses_TemplateStatusCode",
|
||||||
|
column: x => x.TemplateStatusCode,
|
||||||
|
principalTable: "TaskStatuses",
|
||||||
|
principalColumn: "Code",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_RobotTemplateHistories_Templates_TemplateId",
|
||||||
|
column: x => x.TemplateId,
|
||||||
|
principalTable: "Templates",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RobotTemplateHistories_HistoryLevel",
|
||||||
|
table: "RobotTemplateHistories",
|
||||||
|
column: "HistoryLevel");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RobotTemplateHistories_TemplateId",
|
||||||
|
table: "RobotTemplateHistories",
|
||||||
|
column: "TemplateId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_RobotTemplateHistories_TemplateStatusCode",
|
||||||
|
table: "RobotTemplateHistories",
|
||||||
|
column: "TemplateStatusCode");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Templates_TaskStatuses_StatusCode",
|
||||||
|
table: "Templates",
|
||||||
|
column: "StatusCode",
|
||||||
|
principalTable: "TaskStatuses",
|
||||||
|
principalColumn: "Code");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -946,44 +946,6 @@ namespace PARR.DAL.Migrations
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.RobotTemplateHistory", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<DateTimeOffset>("DateCreated")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<string>("EsppMessage")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<int>("HistoryLevel")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<Guid>("IdSeries")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("RobotMessage")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<Guid>("TemplateId")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<int>("TemplateStatusCode")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("HistoryLevel");
|
|
||||||
|
|
||||||
b.HasIndex("TemplateId");
|
|
||||||
|
|
||||||
b.HasIndex("TemplateStatusCode");
|
|
||||||
|
|
||||||
b.ToTable("RobotTemplateHistories");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Setting", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Setting", b =>
|
||||||
{
|
{
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
@@ -1138,16 +1100,10 @@ namespace PARR.DAL.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<int?>("RobotAttemptsNumber")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<DateTimeOffset?>("RobotLastStatusUpdated")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<int?>("RobotStatusCode")
|
b.Property<int?>("RobotStatusCode")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<int?>("StatusCode")
|
b.Property<int?>("TaskStatusCode")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
@@ -1161,7 +1117,7 @@ namespace PARR.DAL.Migrations
|
|||||||
|
|
||||||
b.HasIndex("RobotStatusCode");
|
b.HasIndex("RobotStatusCode");
|
||||||
|
|
||||||
b.HasIndex("StatusCode");
|
b.HasIndex("TaskStatusCode");
|
||||||
|
|
||||||
b.ToTable("Templates");
|
b.ToTable("Templates");
|
||||||
});
|
});
|
||||||
@@ -1701,33 +1657,6 @@ namespace PARR.DAL.Migrations
|
|||||||
b.Navigation("StatusTask");
|
b.Navigation("StatusTask");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.RobotTemplateHistory", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("PARR.DAL.Models.RobotHistoryLevel", "RobotHistoryLevel")
|
|
||||||
.WithMany("robotTemplateHistories")
|
|
||||||
.HasForeignKey("HistoryLevel")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("PARR.DAL.Models.Template", "Template")
|
|
||||||
.WithMany("RobotTemplateHistories")
|
|
||||||
.HasForeignKey("TemplateId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("PARR.DAL.Models.TaskStatus", "StatusTemplate")
|
|
||||||
.WithMany("RobotTemplateHistories")
|
|
||||||
.HasForeignKey("TemplateStatusCode")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("RobotHistoryLevel");
|
|
||||||
|
|
||||||
b.Navigation("StatusTemplate");
|
|
||||||
|
|
||||||
b.Navigation("Template");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Subprocess", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Subprocess", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("PARR.DAL.Models.Process", "Process")
|
b.HasOne("PARR.DAL.Models.Process", "Process")
|
||||||
@@ -1753,21 +1682,17 @@ namespace PARR.DAL.Migrations
|
|||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("PARR.DAL.Models.RobotStatus", "RobotStatus")
|
b.HasOne("PARR.DAL.Models.RobotStatus", null)
|
||||||
.WithMany("Templates")
|
.WithMany("Templates")
|
||||||
.HasForeignKey("RobotStatusCode");
|
.HasForeignKey("RobotStatusCode");
|
||||||
|
|
||||||
b.HasOne("PARR.DAL.Models.TaskStatus", "StatusTask")
|
b.HasOne("PARR.DAL.Models.TaskStatus", null)
|
||||||
.WithMany("Templates")
|
.WithMany("Templates")
|
||||||
.HasForeignKey("StatusCode");
|
.HasForeignKey("TaskStatusCode");
|
||||||
|
|
||||||
b.Navigation("ApplicationsInWork");
|
b.Navigation("ApplicationsInWork");
|
||||||
|
|
||||||
b.Navigation("Host");
|
b.Navigation("Host");
|
||||||
|
|
||||||
b.Navigation("RobotStatus");
|
|
||||||
|
|
||||||
b.Navigation("StatusTask");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Tnk", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Tnk", b =>
|
||||||
@@ -1943,8 +1868,6 @@ namespace PARR.DAL.Migrations
|
|||||||
modelBuilder.Entity("PARR.DAL.Models.RobotHistoryLevel", b =>
|
modelBuilder.Entity("PARR.DAL.Models.RobotHistoryLevel", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("RobotHistories");
|
b.Navigation("RobotHistories");
|
||||||
|
|
||||||
b.Navigation("robotTemplateHistories");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.RobotStatus", b =>
|
modelBuilder.Entity("PARR.DAL.Models.RobotStatus", b =>
|
||||||
@@ -1959,16 +1882,12 @@ namespace PARR.DAL.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.TaskStatus", b =>
|
modelBuilder.Entity("PARR.DAL.Models.TaskStatus", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("RobotTemplateHistories");
|
|
||||||
|
|
||||||
b.Navigation("Templates");
|
b.Navigation("Templates");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Template", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Template", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("RobotConfigurations");
|
b.Navigation("RobotConfigurations");
|
||||||
|
|
||||||
b.Navigation("RobotTemplateHistories");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PARR.DAL.Models.Tnk", b =>
|
modelBuilder.Entity("PARR.DAL.Models.Tnk", b =>
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ namespace PARR.DAL.Models
|
|||||||
public required string Description { get; set; }
|
public required string Description { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ICollection<RobotTemplateHistory> robotTemplateHistories { get; set; } = new HashSet<RobotTemplateHistory>();
|
|
||||||
|
|
||||||
public ICollection<RobotHistory> RobotHistories { get; set; } = new HashSet<RobotHistory>();
|
public ICollection<RobotHistory> RobotHistories { get; set; } = new HashSet<RobotHistory>();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
using PARR.DAL.Models.Base;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace PARR.DAL.Models
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// История работы робота по управлению шаблонами в ЕСПП
|
|
||||||
/// </summary>
|
|
||||||
[Table("RobotTemplateHistories")]
|
|
||||||
public class RobotTemplateHistory : IBase
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
|
|
||||||
public DateTimeOffset DateCreated { get; set; }
|
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
public DateTimeOffset? DateModified { get; set; }
|
|
||||||
|
|
||||||
public int HistoryLevel { get; set; }
|
|
||||||
|
|
||||||
public string? RobotMessage { get; set; }
|
|
||||||
|
|
||||||
public string? EsppMessage { get; set; }
|
|
||||||
|
|
||||||
public Guid TemplateId { get; set; }
|
|
||||||
|
|
||||||
public int TemplateStatusCode { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Уникальный идентификатор серии выполнения, нужен для сопоставления истории
|
|
||||||
/// </summary>
|
|
||||||
public Guid IdSeries { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
[ForeignKey(nameof(HistoryLevel))]
|
|
||||||
public RobotHistoryLevel? RobotHistoryLevel { get; set; }
|
|
||||||
|
|
||||||
[ForeignKey(nameof(TemplateId))]
|
|
||||||
public Template? Template { get; set; }
|
|
||||||
|
|
||||||
[ForeignKey(nameof(TemplateStatusCode))]
|
|
||||||
public TaskStatus? StatusTemplate { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,5 @@ namespace PARR.DAL.Models
|
|||||||
public string Description { get; set; } = string.Empty;
|
public string Description { get; set; } = string.Empty;
|
||||||
|
|
||||||
public ICollection<Template> Templates { get; set; } = new HashSet<Template>();
|
public ICollection<Template> Templates { get; set; } = new HashSet<Template>();
|
||||||
|
|
||||||
public ICollection<RobotTemplateHistory> RobotTemplateHistories { get; set; } = new HashSet<RobotTemplateHistory>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,31 +27,31 @@ namespace PARR.DAL.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Статус шаблона. Что нужно сделать роботу в ЕСПП
|
/// Статус шаблона. Что нужно сделать роботу в ЕСПП
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? StatusCode { get; set; }
|
//public int? StatusCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Статус работы робота
|
/// Статус работы робота
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? RobotStatusCode { get; set; }
|
//public int? RobotStatusCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество попыток выполнения задания роботом
|
/// Количество попыток выполнения задания роботом
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? RobotAttemptsNumber { get; set; }
|
//public int? RobotAttemptsNumber { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Последняя дата обновления статуса RobotStatusCode роботом
|
/// Последняя дата обновления статуса RobotStatusCode роботом
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTimeOffset? RobotLastStatusUpdated { get; set; }
|
//public DateTimeOffset? RobotLastStatusUpdated { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[ForeignKey(nameof(StatusCode))]
|
//[ForeignKey(nameof(StatusCode))]
|
||||||
public TaskStatus? StatusTask { get; set; }
|
//public TaskStatus? StatusTask { get; set; }
|
||||||
|
|
||||||
[ForeignKey(nameof(RobotStatusCode))]
|
//[ForeignKey(nameof(RobotStatusCode))]
|
||||||
public RobotStatus? RobotStatus { get; set; }
|
//public RobotStatus? RobotStatus { get; set; }
|
||||||
|
|
||||||
public ICollection<RobotTemplateHistory> RobotTemplateHistories { get; set; } = new HashSet<RobotTemplateHistory>();
|
//public ICollection<RobotTemplateHistory> RobotTemplateHistories { get; set; } = new HashSet<RobotTemplateHistory>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ namespace PARR.DAL
|
|||||||
services.AddTransient<IStatusTemplateService, StatusTemplateService>();
|
services.AddTransient<IStatusTemplateService, StatusTemplateService>();
|
||||||
services.AddTransient<IRobotHistoryLevelService, RobotHistoryLevelService>();
|
services.AddTransient<IRobotHistoryLevelService, RobotHistoryLevelService>();
|
||||||
services.AddTransient<IRobotStatusService, RobotStatusService>();
|
services.AddTransient<IRobotStatusService, RobotStatusService>();
|
||||||
services.AddTransient<IRobotTemplateHistoryService, RobotTemplateHistoryService>();
|
|
||||||
services.AddTransient<IRobotService, RobotService>();
|
services.AddTransient<IRobotService, RobotService>();
|
||||||
services.AddTransient<IRobotConfigurationService, RobotConfigurationService>();
|
services.AddTransient<IRobotConfigurationService, RobotConfigurationService>();
|
||||||
services.AddTransient<IRobotHistoryService, RobotHistoryService>();
|
services.AddTransient<IRobotHistoryService, RobotHistoryService>();
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using PARR.DAL.Context;
|
|
||||||
using PARR.DAL.Models;
|
|
||||||
using PARR.DAL.Services.Abstracts;
|
|
||||||
using PARR.DAL.Services.Interfaces;
|
|
||||||
|
|
||||||
namespace PARR.DAL.Services.Implementations
|
|
||||||
{
|
|
||||||
internal class RobotTemplateHistoryService : BaseService<RobotTemplateHistory>, IRobotTemplateHistoryService
|
|
||||||
{
|
|
||||||
private readonly DataContext dataContext;
|
|
||||||
|
|
||||||
public RobotTemplateHistoryService(DataContext dataContext, ILogger<RobotTemplateHistoryService> logger) : base(logger)
|
|
||||||
{
|
|
||||||
this.dataContext = dataContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override DbSet<RobotTemplateHistory> EntitySet => dataContext.RobotTemplateHistories;
|
|
||||||
|
|
||||||
protected override DataContext EntitiContext => dataContext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -35,7 +35,6 @@ namespace PARR.DAL.Services.Implementations
|
|||||||
.ThenInclude(t => t!.ResponseArea)
|
.ThenInclude(t => t!.ResponseArea)
|
||||||
.Include(h => h.Host)
|
.Include(h => h.Host)
|
||||||
.ThenInclude(t => t!.EkStatus)
|
.ThenInclude(t => t!.EkStatus)
|
||||||
.Include(r => r.RobotStatus)
|
|
||||||
.Include(a => a.ApplicationsInWork)
|
.Include(a => a.ApplicationsInWork)
|
||||||
.ThenInclude(w => w!.Work)
|
.ThenInclude(w => w!.Work)
|
||||||
.ThenInclude(t => t!.Tnk)
|
.ThenInclude(t => t!.Tnk)
|
||||||
@@ -43,65 +42,6 @@ namespace PARR.DAL.Services.Implementations
|
|||||||
.ThenInclude(p => p!.Process);
|
.ThenInclude(p => p!.Process);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: удалить этот метод
|
|
||||||
#region delete
|
|
||||||
public async Task CheckAndSetErrorRobotStatusAsync(int robotAttemptsNumber, TimeSpan robotWaitTime)
|
|
||||||
{
|
|
||||||
//Ищем `RobotStatusCode` = 22 и `RobotLastStatusUpdated` истекло и `RobotAttemptsNumber` >= допустимого значения из настроек,
|
|
||||||
//ставим всем этим записям `RobotStatusCode`= 33
|
|
||||||
|
|
||||||
var endDate = DateTimeOffset.UtcNow.Add(-robotWaitTime);
|
|
||||||
|
|
||||||
var templates = await EntitySet.Where(t =>
|
|
||||||
t.RobotStatusCode == (int)RobotStatusEnum.InProgress
|
|
||||||
&& t.RobotAttemptsNumber >= robotAttemptsNumber
|
|
||||||
&& t.RobotLastStatusUpdated <= endDate
|
|
||||||
)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
if (!templates.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var template in templates)
|
|
||||||
{
|
|
||||||
template.RobotStatusCode = (int)RobotStatusEnum.Error;
|
|
||||||
template.DateModified = DateTimeOffset.UtcNow;
|
|
||||||
logger.LogInformation($"Устанавливаю RobotStatus: {RobotStatusEnum.Error} для шаблона {template.Name}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var result = await CommitAsync();
|
|
||||||
|
|
||||||
if (!result)
|
|
||||||
logger.LogError($"Ошибка при сохранении изменений RobotStatus у шаблонов на {RobotStatusEnum.Error}");
|
|
||||||
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public void ChangeRobotStatus(RobotStatusEnum status, ref Template template)
|
|
||||||
{
|
|
||||||
template.RobotStatusCode = (int)status;
|
|
||||||
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case RobotStatusEnum.InProgress:
|
|
||||||
template.RobotAttemptsNumber++;
|
|
||||||
template.RobotLastStatusUpdated = DateTimeOffset.UtcNow;
|
|
||||||
break;
|
|
||||||
//case RobotStatusEnum.Error:
|
|
||||||
// break;
|
|
||||||
case RobotStatusEnum.Complete:
|
|
||||||
template.RobotLastStatusUpdated = DateTimeOffset.UtcNow;
|
|
||||||
break;
|
|
||||||
case RobotStatusEnum.Wait:
|
|
||||||
template.RobotLastStatusUpdated = null;
|
|
||||||
template.RobotAttemptsNumber = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task<bool> CreateAsync(Template obj)
|
public override Task<bool> CreateAsync(Template obj)
|
||||||
{
|
{
|
||||||
// добавление роботов для шаблона
|
// добавление роботов для шаблона
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using PARR.DAL.Models;
|
|
||||||
using PARR.DAL.Services.Interfaces.Base;
|
|
||||||
|
|
||||||
namespace PARR.DAL.Services.Interfaces
|
|
||||||
{
|
|
||||||
public interface IRobotTemplateHistoryService : IBaseService<RobotTemplateHistory>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,21 +6,6 @@ namespace PARR.DAL.Services.Interfaces
|
|||||||
{
|
{
|
||||||
public interface ITemplateService : IBaseService<Template>
|
public interface ITemplateService : IBaseService<Template>
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Изменение статуса отработки робота (без коммита)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="status"></param>
|
|
||||||
/// <param name="template"></param>
|
|
||||||
void ChangeRobotStatus(RobotStatusEnum status, ref Template template);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Поиск шаблонов с просроченным временем выполнения роботом и превышенным кол-вом попыток. Установка им ошибочного статуса
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="robotAttemptsNumber">Максимальное кол-во ошибок</param>
|
|
||||||
/// <param name="robotWaitTime">Максимальное время выполнения</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task CheckAndSetErrorRobotStatusAsync(int robotAttemptsNumber, TimeSpan robotWaitTime);
|
|
||||||
|
|
||||||
Task<Template?> GetTemplateByNameAsync(string name);
|
Task<Template?> GetTemplateByNameAsync(string name);
|
||||||
|
|
||||||
IQueryable<Template> GetWithIncludes();
|
IQueryable<Template> GetWithIncludes();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using PARR.DAL.Contracts;
|
|||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
using PARR.EsppTemplateSync.Domain;
|
using PARR.EsppTemplateSync.Domain;
|
||||||
|
using PARR.EsppTemplateSync.MappingProfiles;
|
||||||
using PARR.EsppTemplateSync.Settings;
|
using PARR.EsppTemplateSync.Settings;
|
||||||
|
|
||||||
namespace PARR.EsppTemplateSync.Services
|
namespace PARR.EsppTemplateSync.Services
|
||||||
@@ -126,8 +127,10 @@ namespace PARR.EsppTemplateSync.Services
|
|||||||
|
|
||||||
private void SetUpdateStatus(ITemplateService templateService, Template template)
|
private void SetUpdateStatus(ITemplateService templateService, Template template)
|
||||||
{
|
{
|
||||||
template.StatusCode = (int)TaskStatusEnum.Updating;
|
//TODO: ChangeRobotStatus
|
||||||
templateService.ChangeRobotStatus(RobotStatusEnum.Wait, ref template);
|
//template.StatusCode = (int)TaskStatusEnum.Updating;
|
||||||
|
//templateService.ChangeRobotStatus(RobotStatusEnum.Wait, ref template);
|
||||||
|
throw new NotImplementedException("ChangeRobotStatus");
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsChanged(EsppTemplate template, EsppTemplate esppTemplate)
|
private bool IsChanged(EsppTemplate template, EsppTemplate esppTemplate)
|
||||||
|
|||||||
@@ -89,12 +89,8 @@ namespace PARR.GeneratorTemplates.Services
|
|||||||
Name = TemplateHelpers.GenerateTemplateName(settingsFromDb.TemplatePrefixName, host.Ek, appInWork.Work!.Name),
|
Name = TemplateHelpers.GenerateTemplateName(settingsFromDb.TemplatePrefixName, host.Ek, appInWork.Work!.Name),
|
||||||
IsActiveTemplate = true,
|
IsActiveTemplate = true,
|
||||||
IsActiveSchedule = true,
|
IsActiveSchedule = true,
|
||||||
StatusCode = (int)TaskStatusEnum.Creating,
|
|
||||||
ApplicationInWorkId = appInWork.Id,
|
ApplicationInWorkId = appInWork.Id,
|
||||||
HostId = host.Id,
|
HostId = host.Id
|
||||||
RobotAttemptsNumber = 0,
|
|
||||||
RobotLastStatusUpdated = null,
|
|
||||||
RobotStatusCode = (int)RobotStatusEnum.Wait
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!await templateService.CreateAsync(template) || !await templateService.CommitAsync())
|
if (!await templateService.CreateAsync(template) || !await templateService.CommitAsync())
|
||||||
@@ -104,7 +100,7 @@ namespace PARR.GeneratorTemplates.Services
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.LogInformation($"Создан шаблон: Name: {template.Name}, ApplicationInWorkId: {template.ApplicationInWorkId}, " +
|
logger.LogInformation($"Создан шаблон: Name: {template.Name}, ApplicationInWorkId: {template.ApplicationInWorkId}, " +
|
||||||
$"HostId: {template.HostId}, IsActive: {template.IsActiveTemplate}, StatusCode: {template.StatusCode}");
|
$"HostId: {template.HostId}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user