feat(api,core,domain): Изменен контроллер RobotTaskRobotStatusController, метод изменения статуса задания вынесен в сервисы. Добавлена логика успрешного переименования шаблона.
This commit is contained in:
@@ -1,40 +1,34 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
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.API.Services.Interfaces;
|
||||
using PARR.Core.Repositories.Interfaces;
|
||||
using PARR.Core.Services.RobotTaskRobotStatus.Interfaces;
|
||||
using PARR.Domain.Common.Roles;
|
||||
using PARR.Domain.Entities;
|
||||
using PARR.Domain.Entities.RobotEntities;
|
||||
using PARR.Domain.Enums;
|
||||
using PARR.Domain.DTOs.RobotTaskRobotStatus;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
[Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
|
||||
public class RobotTaskRobotStatusController : BaseApiController
|
||||
{
|
||||
private readonly IRobotConfigurationRepository robotConfigurationService;
|
||||
private readonly IRobotHistoryRepository robotHistoryService;
|
||||
private readonly IMapper mapper;
|
||||
private readonly IClientService clientService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IClientService _clientService;
|
||||
private readonly IRobotTaskRobotStatusService _robotTaskRobotStatusService;
|
||||
|
||||
public RobotTaskRobotStatusController(
|
||||
IRobotConfigurationRepository robotConfigurationService,
|
||||
IRobotHistoryRepository robotHistoryService,
|
||||
IMapper mapper,
|
||||
IClientService clientService
|
||||
IClientService clientService,
|
||||
IRobotTaskRobotStatusService robotTaskRobotStatusService
|
||||
)
|
||||
{
|
||||
this.robotConfigurationService = robotConfigurationService;
|
||||
this.robotHistoryService = robotHistoryService;
|
||||
this.mapper = mapper;
|
||||
this.clientService = clientService;
|
||||
_mapper = mapper;
|
||||
_clientService = clientService;
|
||||
_robotTaskRobotStatusService = robotTaskRobotStatusService;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,47 +40,58 @@ namespace PARR.API.Controllers.V1
|
||||
[HttpPut(ApiRoutes.RobotTaskRobotStatus.ChangeRobotStatus)]
|
||||
public async Task<IActionResult> ChangeStatus([FromRoute] Guid taskId, [FromBody] RobotTaskChangeRobotStatusRequest request)
|
||||
{
|
||||
var config = await robotConfigurationService.Get()
|
||||
.FirstOrDefaultAsync(t => t.Id == taskId);
|
||||
#region Old
|
||||
|
||||
if (config == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найдено задание с id: {taskId}" } }));
|
||||
//var config = await _robotConfigurationRepository.Get()
|
||||
// .FirstOrDefaultAsync(t => t.Id == taskId);
|
||||
|
||||
//изменение статуса робота
|
||||
robotConfigurationService.ChangeRobotStatus(request.RobotStatusCode, config);
|
||||
//if (config == null)
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найдено задание с id: {taskId}" } }));
|
||||
|
||||
//если успех, изменяем статус задания на успех
|
||||
if (request.RobotStatusCode == RobotStatusEnum.Complete)
|
||||
robotConfigurationService.ChangeTaskStatus(TaskStatusEnum.Ok, config);
|
||||
////изменение статуса робота
|
||||
//_robotConfigurationRepository.ChangeRobotStatus(request.RobotStatusCode, config);
|
||||
|
||||
if (!await robotConfigurationService.CommitAsync())
|
||||
return BadRequest("Ошибка при изменении статуса работы робота.");
|
||||
////если успех, изменяем статус задания на успех
|
||||
//if (request.RobotStatusCode == RobotStatusEnum.Complete)
|
||||
// _robotConfigurationRepository.ChangeTaskStatus(TaskStatusEnum.Ok, config);
|
||||
|
||||
//записываем в лог робота
|
||||
if (request.RobotStatusCode == RobotStatusEnum.InProgress || request.RobotStatusCode == RobotStatusEnum.Complete)
|
||||
{
|
||||
var historyLevel = request.RobotStatusCode == RobotStatusEnum.InProgress ? RobotHistoryLevelEnum.Start : RobotHistoryLevelEnum.Complete;
|
||||
//if (!await _robotConfigurationRepository.CommitAsync())
|
||||
// return BadRequest("Ошибка при изменении статуса работы робота.");
|
||||
|
||||
var history = new RobotHistory
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
HistoryLevel = (int)historyLevel,
|
||||
TaskStatusCode = config.TaskStatusCode,
|
||||
RobotConfigurationId = config.Id,
|
||||
RobotIp = clientService.GetClientIp()?.ToString(),
|
||||
RobotId = request.RobotId
|
||||
};
|
||||
await robotHistoryService.CreateAsync(history);
|
||||
await robotHistoryService.CommitAsync();
|
||||
}
|
||||
////записываем в лог робота
|
||||
//if (request.RobotStatusCode == RobotStatusEnum.InProgress || request.RobotStatusCode == RobotStatusEnum.Complete)
|
||||
//{
|
||||
// var historyLevel = request.RobotStatusCode == RobotStatusEnum.InProgress ? RobotHistoryLevelEnum.Start : RobotHistoryLevelEnum.Complete;
|
||||
|
||||
var configToResponse = await robotConfigurationService.Get()
|
||||
.Include(t => t.Robot)
|
||||
.Include(t => t.TaskStatus)
|
||||
.Include(t => t.RobotStatus)
|
||||
.FirstOrDefaultAsync(t => t.Id == taskId);
|
||||
// var history = new RobotHistory
|
||||
// {
|
||||
// Id = Guid.NewGuid(),
|
||||
// HistoryLevel = (int)historyLevel,
|
||||
// TaskStatusCode = config.TaskStatusCode,
|
||||
// RobotConfigurationId = config.Id,
|
||||
// RobotIp = _clientService.GetClientIp()?.ToString(),
|
||||
// RobotId = request.RobotId
|
||||
// };
|
||||
// await _robotHistoryRepository.CreateAsync(history);
|
||||
// await _robotHistoryRepository.CommitAsync();
|
||||
//}
|
||||
|
||||
var response = mapper.Map<RobotConfigurationResponse>(configToResponse);
|
||||
//var configToResponse = await _robotConfigurationRepository.Get()
|
||||
// .Include(t => t.Robot)
|
||||
// .Include(t => t.TaskStatus)
|
||||
// .Include(t => t.RobotStatus)
|
||||
// .FirstOrDefaultAsync(t => t.Id == taskId);
|
||||
|
||||
//var response = _mapper.Map<RobotConfigurationResponse>(configToResponse);
|
||||
|
||||
//return Ok(new Response<RobotConfigurationResponse>(response, true));
|
||||
|
||||
#endregion
|
||||
|
||||
var changeRequest = new ChangeRobotStatus(taskId, request.RobotStatusCode, request.RobotId, _clientService.GetClientIp()?.ToString());
|
||||
var result = await _robotTaskRobotStatusService.ChangeStatusAsync(changeRequest);
|
||||
|
||||
var response = _mapper.Map<RobotConfigurationResponse>(result);
|
||||
|
||||
return Ok(new Response<RobotConfigurationResponse>(response, true));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ using PARR.Domain.DTOs.Matching;
|
||||
using PARR.Domain.DTOs.RobotMetrics;
|
||||
using PARR.Domain.DTOs.RobotSnapshotDTO;
|
||||
using PARR.Domain.DTOs.RobotTask;
|
||||
using PARR.Domain.DTOs.RobotTaskRobotStatus;
|
||||
using PARR.Domain.DTOs.Shared;
|
||||
using PARR.Domain.DTOs.Shortcode;
|
||||
using PARR.Domain.DTOs.TaskDTO;
|
||||
using PARR.Domain.DTOs.User;
|
||||
@@ -258,10 +260,17 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
CreateMap<PARR.Domain.Entities.RobotEntities.TaskStatus, TaskStatusResponse>();
|
||||
|
||||
CreateMap<RobotConfiguration, RobotConfigurationResponse>()
|
||||
.ForMember(d => d.Robot, o => o.MapFrom(s => s.Robot))
|
||||
.ForMember(d => d.TaskStatus, o => o.MapFrom(s => s.TaskStatus))
|
||||
.ForMember(d => d.RobotStatus, o => o.MapFrom(s => s.RobotStatus));
|
||||
//CreateMap<RobotConfiguration, RobotConfigurationResponse>()
|
||||
// .ForMember(d => d.Robot, o => o.MapFrom(s => s.Robot))
|
||||
// .ForMember(d => d.TaskStatus, o => o.MapFrom(s => s.TaskStatus))
|
||||
// .ForMember(d => d.RobotStatus, o => o.MapFrom(s => s.RobotStatus));
|
||||
|
||||
CreateMap<RobotDto, RobotResponse>();
|
||||
CreateMap<RobotTaskStatusDto, TaskStatusResponse>();
|
||||
CreateMap<RobotStatusDto, RobotStatusResponse>();
|
||||
|
||||
CreateMap<RobotConfigurationResult, RobotConfigurationResponse>();
|
||||
|
||||
// === RobotConfiguration ===
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user