feat(api): Обновил респонс для шаблона под измененную таблицу
This commit is contained in:
9
PARR.API/Contracts/V1/Responses/RobotStatusResponse.cs
Normal file
9
PARR.API/Contracts/V1/Responses/RobotStatusResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Responses
|
||||||
|
{
|
||||||
|
public class RobotStatusResponse
|
||||||
|
{
|
||||||
|
public int Code { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,11 @@
|
|||||||
public required string Solution { get; set; }
|
public required string Solution { get; set; }
|
||||||
public required string TemplateDuration { get; set; }
|
public required string TemplateDuration { get; set; }
|
||||||
|
|
||||||
|
public int RobotAttemptsNumber { get; set; }
|
||||||
|
public DateTimeOffset? RobotLastStatusUpdated { get; set; }
|
||||||
|
public RobotStatusResponse? RobotStatus { get; set; }
|
||||||
|
|
||||||
|
|
||||||
//work
|
//work
|
||||||
//public required string Title { get; set; }
|
//public required string Title { get; set; }
|
||||||
//public required string SlaInterval { get; set; }
|
//public required string SlaInterval { get; set; }
|
||||||
|
|||||||
@@ -104,11 +104,34 @@ namespace PARR.API.Controllers.V1
|
|||||||
[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;
|
||||||
//нужно вводить статус, что эл уже занят
|
|
||||||
var template = await templateService.GetWithIncludes()
|
//1.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 11.Находим, **выбрали эту запись, конец**.
|
||||||
|
//2.Поиск шаблонов со `StatusCode` 10 или 20 и `RobotStatusCode` = 22
|
||||||
|
//3.Далее проверяется `RobotLastStatusUpdated`, что время последнего смены статуса не превышает допустимого(берется из настроек, поле `RobotWaitTime`) и что текущая попытка не больше разрешенной(берется из настроек, поле `RobotAttemptsNumber`) - если это так, берется эта запись.
|
||||||
|
//4.Если `RobotStatusCode` = 22 и `RobotLastStatusUpdated` истекло и `RobotAttemptsNumber` >= допустимому, то ставим `RobotStatusCode`= 33
|
||||||
|
|
||||||
|
//1.
|
||||||
|
template = await templateService.GetWithIncludes()
|
||||||
.AsSplitQuery()
|
.AsSplitQuery()
|
||||||
.FirstOrDefaultAsync(t => t.StatusCode == statusCode);
|
.FirstOrDefaultAsync(t => t.StatusCode == statusCode && t.RobotStatusCode ==(int)RobotStatusEnum.Wait);
|
||||||
|
|
||||||
|
//if (template == null)
|
||||||
|
//{
|
||||||
|
// // переходим к шагам 2,3
|
||||||
|
// template = await templateService.GetWithIncludes()
|
||||||
|
// .AsSplitQuery()
|
||||||
|
// //todo
|
||||||
|
// .FirstOrDefaultAsync(t => t.StatusCode == statusCode && t.RobotStatusCode == (int)RobotStatusEnum.InProgress);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////Тут узкое место, так как возвращается первый, если будет много роботов, то будет возвращаться им один и тот же элемент.
|
||||||
|
////нужно вводить статус, что эл уже занят
|
||||||
|
// template = await templateService.GetWithIncludes()
|
||||||
|
// .AsSplitQuery()
|
||||||
|
// .FirstOrDefaultAsync(t => t.StatusCode == statusCode);
|
||||||
|
|
||||||
if (template == null)
|
if (template == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ namespace PARR.API.MappingProfiles
|
|||||||
.ForMember(d => d.Status, o => o.MapFrom(s => s.EkStatus!.Name))
|
.ForMember(d => d.Status, o => o.MapFrom(s => s.EkStatus!.Name))
|
||||||
.ForMember(d => d.ResponseArea, o => o.MapFrom(s => s.ResponseArea!.Name));
|
.ForMember(d => d.ResponseArea, o => o.MapFrom(s => s.ResponseArea!.Name));
|
||||||
|
|
||||||
|
CreateMap<RobotStatus, RobotStatusResponse>();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ 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)
|
||||||
|
|||||||
Reference in New Issue
Block a user