102 lines
4.4 KiB
C#
102 lines
4.4 KiB
C#
using AutoMapper;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
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.Services.RobotTaskRobotStatus.Interfaces;
|
||
using PARR.Domain.Common.Roles;
|
||
using PARR.Domain.DTOs.RobotTaskRobotStatus;
|
||
|
||
namespace PARR.API.Controllers.V1
|
||
{
|
||
[Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
|
||
public class RobotTaskRobotStatusController : BaseApiController
|
||
{
|
||
private readonly IMapper _mapper;
|
||
private readonly IClientService _clientService;
|
||
private readonly IRobotTaskRobotStatusService _robotTaskRobotStatusService;
|
||
|
||
public RobotTaskRobotStatusController(
|
||
IMapper mapper,
|
||
IClientService clientService,
|
||
IRobotTaskRobotStatusService robotTaskRobotStatusService
|
||
)
|
||
{
|
||
_mapper = mapper;
|
||
_clientService = clientService;
|
||
_robotTaskRobotStatusService = robotTaskRobotStatusService;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Изменить статус выполнения задания роботом по ИД задания
|
||
/// </summary>
|
||
/// <param name="taskId"></param>
|
||
/// <returns></returns>
|
||
[HttpPut(ApiRoutes.RobotTaskRobotStatus.ChangeRobotStatus)]
|
||
public async Task<IActionResult> ChangeStatus([FromRoute] Guid taskId, [FromBody] RobotTaskChangeRobotStatusRequest request)
|
||
{
|
||
#region Old
|
||
|
||
//var config = await _robotConfigurationRepository.Get()
|
||
// .FirstOrDefaultAsync(t => t.Id == taskId);
|
||
|
||
//if (config == null)
|
||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Не найдено задание с id: {taskId}" } }));
|
||
|
||
////изменение статуса робота
|
||
//_robotConfigurationRepository.ChangeRobotStatus(request.RobotStatusCode, config);
|
||
|
||
////если успех, изменяем статус задания на успех
|
||
//if (request.RobotStatusCode == RobotStatusEnum.Complete)
|
||
// _robotConfigurationRepository.ChangeTaskStatus(TaskStatusEnum.Ok, config);
|
||
|
||
//if (!await _robotConfigurationRepository.CommitAsync())
|
||
// return BadRequest("Ошибка при изменении статуса работы робота.");
|
||
|
||
////записываем в лог робота
|
||
//if (request.RobotStatusCode == RobotStatusEnum.InProgress || request.RobotStatusCode == RobotStatusEnum.Complete)
|
||
//{
|
||
// var historyLevel = request.RobotStatusCode == RobotStatusEnum.InProgress ? RobotHistoryLevelEnum.Start : RobotHistoryLevelEnum.Complete;
|
||
|
||
// 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 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));
|
||
}
|
||
|
||
|
||
}
|
||
}
|