feat(api): Просмотр истории роботов
This commit is contained in:
@@ -75,7 +75,7 @@
|
||||
|
||||
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/";
|
||||
}
|
||||
|
||||
|
||||
23
PARR.API/Contracts/V1/Requests/Queries/RobotHistoryQuery.cs
Normal file
23
PARR.API/Contracts/V1/Requests/Queries/RobotHistoryQuery.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using PARR.DAL.Contracts;
|
||||
|
||||
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||
{
|
||||
public class RobotHistoryQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Фильтр по ИД шаблона
|
||||
/// </summary>
|
||||
public Guid? TemplateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Фильтр по ИД робота
|
||||
/// </summary>
|
||||
public RobotsEnum? RobotCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Фильтр по уровню истории
|
||||
/// </summary>
|
||||
public RobotHistoryLevelEnum? HistoryLevel { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||
{
|
||||
public class RobotTemplateHistoryQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Фильтр по ИД шаблона
|
||||
/// </summary>
|
||||
public Guid? TemplateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Фильтр по ИД серии
|
||||
/// </summary>
|
||||
public Guid? IdSeries { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,19 @@
|
||||
|
||||
public string? EsppMessage { get; set; }
|
||||
|
||||
public int TaskStatusCode { get; set; }
|
||||
//public int TaskStatusCode { get; set; }
|
||||
|
||||
public TaskStatusResponse? TaskStatus { get; set; }
|
||||
|
||||
public Guid TaskId { get; set; }
|
||||
|
||||
public RobotHistoryLevelResponse? Level { get; set; }
|
||||
|
||||
public Guid TemplateId { get; set; }
|
||||
|
||||
public string? TemplateName { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,13 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
@@ -38,39 +41,43 @@ namespace PARR.API.Controllers.V1
|
||||
}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// Получить историю робота шаблонов
|
||||
///// </summary>
|
||||
///// <param name="paginationQuery"></param>
|
||||
///// <param name="filter"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpGet(ApiRoutes.RobotTemplateHistory.GetAll)]
|
||||
//public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] RobotTemplateHistoryQuery filter)
|
||||
//{
|
||||
// var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
/// <summary>
|
||||
/// Просмотр истории работы робота
|
||||
/// </summary>
|
||||
/// <param name="paginationQuery"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.RobotHistory.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] RobotHistoryQuery request)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
// IQueryable<RobotTemplateHistory> query = historyService.Get()
|
||||
// .Include(t => t.Template)
|
||||
// .Include(t => t.RobotHistoryLevel)
|
||||
// .OrderByDescending(t => t.DateCreated).ThenBy(t => t.IdSeries);
|
||||
IQueryable<RobotHistory> query = robotHistoryService.Get()
|
||||
.Include(t => t.RobotConfiguration)
|
||||
.ThenInclude(t=>t!.Template)
|
||||
.Include(t => t.RobotHistoryLevel)
|
||||
.Include(t => t.StatusTask)
|
||||
.OrderByDescending(t => t.DateCreated);
|
||||
|
||||
// if (filter.IdSeries != null)
|
||||
// query = query.Where(t => t.IdSeries == filter.IdSeries);
|
||||
if (request.TemplateId.HasValue)
|
||||
query = query.Where(t => t.RobotConfiguration!.TemplateId == request.TemplateId.Value);
|
||||
|
||||
// if (filter.TemplateId != null)
|
||||
// query = query.Where(t => t.TemplateId == filter.TemplateId);
|
||||
if (request.RobotCode.HasValue)
|
||||
query = query.Where(t => t.RobotConfiguration!.RobotCode == (int)request.RobotCode);
|
||||
|
||||
if (request.HistoryLevel.HasValue)
|
||||
query = query.Where(t => t.HistoryLevel == (int)request.HistoryLevel);
|
||||
|
||||
// var history = await historyService.GetPage(query, paginationFilter).ToListAsync();
|
||||
var history = await robotHistoryService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
// if (!history.Any())
|
||||
// return NoContent();
|
||||
if (!history.Any())
|
||||
return NoContent();
|
||||
|
||||
// var response = mapper.Map<List<RobotTemplateHistoryResponse>>(history);
|
||||
// var paginationResponse = new PagedResponse<RobotTemplateHistoryResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
||||
var response = mapper.Map<List<RobotHistoryResponse>>(history);
|
||||
var paginationResponse = new PagedResponse<RobotHistoryResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
// return Ok(paginationResponse);
|
||||
//}
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -105,7 +112,9 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
var createdObj = await robotHistoryService.Get()
|
||||
.Include(t => t.RobotConfiguration)
|
||||
.ThenInclude(t => t!.Template)
|
||||
.Include(t => t.RobotHistoryLevel)
|
||||
.Include(t => t.StatusTask)
|
||||
.FirstOrDefaultAsync(t => t.Id == history.Id);
|
||||
|
||||
var response = mapper.Map<RobotHistoryResponse>(createdObj);
|
||||
|
||||
@@ -71,7 +71,10 @@ namespace PARR.API.MappingProfiles
|
||||
CreateMap<RobotHistory, RobotHistoryResponse>()
|
||||
.ForMember(d => d.Level, o => o.MapFrom(s => s.RobotHistoryLevel))
|
||||
.ForMember(d => d.Date, o => o.MapFrom(s => s.DateCreated))
|
||||
.ForMember(d => d.TaskId, o => o.MapFrom(s => s.RobotConfigurationId));
|
||||
.ForMember(d => d.TaskId, o => o.MapFrom(s => s.RobotConfigurationId))
|
||||
.ForMember(d => d.TaskStatus, o => o.MapFrom(s => s.StatusTask))
|
||||
.ForMember(d => d.TemplateId, o => o.MapFrom(s => s.RobotConfiguration!.TemplateId))
|
||||
.ForMember(d => d.TemplateName, o => o.MapFrom(s => s.RobotConfiguration!.Template!.Name));
|
||||
|
||||
|
||||
// --- RobotConfiguration ---
|
||||
|
||||
Reference in New Issue
Block a user