2023-10-06 11:38:33 +10:00
|
|
|
|
using AutoMapper;
|
2023-12-04 10:16:00 +10:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-10-06 11:38:33 +10:00
|
|
|
|
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;
|
2024-07-22 14:48:44 +10:00
|
|
|
|
using PARR.API.Services.Interfaces;
|
2026-07-23 14:39:55 +10:00
|
|
|
|
using PARR.Core.Services.RobotTaskRobotStatus.Interfaces;
|
2026-04-14 12:01:49 +10:00
|
|
|
|
using PARR.Domain.Common.Roles;
|
2026-07-23 14:39:55 +10:00
|
|
|
|
using PARR.Domain.DTOs.RobotTaskRobotStatus;
|
2023-10-06 11:38:33 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Controllers.V1
|
|
|
|
|
|
{
|
2023-12-04 10:16:00 +10:00
|
|
|
|
[Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
|
2023-10-06 11:38:33 +10:00
|
|
|
|
public class RobotTaskRobotStatusController : BaseApiController
|
|
|
|
|
|
{
|
2026-07-23 14:39:55 +10:00
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
private readonly IClientService _clientService;
|
|
|
|
|
|
private readonly IRobotTaskRobotStatusService _robotTaskRobotStatusService;
|
2023-10-06 11:38:33 +10:00
|
|
|
|
|
|
|
|
|
|
public RobotTaskRobotStatusController(
|
2024-07-22 14:48:44 +10:00
|
|
|
|
IMapper mapper,
|
2026-07-23 14:39:55 +10:00
|
|
|
|
IClientService clientService,
|
|
|
|
|
|
IRobotTaskRobotStatusService robotTaskRobotStatusService
|
2023-10-06 11:38:33 +10:00
|
|
|
|
)
|
|
|
|
|
|
{
|
2026-07-23 14:39:55 +10:00
|
|
|
|
_mapper = mapper;
|
|
|
|
|
|
_clientService = clientService;
|
|
|
|
|
|
_robotTaskRobotStatusService = robotTaskRobotStatusService;
|
2023-10-06 11:38:33 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Изменить статус выполнения задания роботом по ИД задания
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="taskId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPut(ApiRoutes.RobotTaskRobotStatus.ChangeRobotStatus)]
|
|
|
|
|
|
public async Task<IActionResult> ChangeStatus([FromRoute] Guid taskId, [FromBody] RobotTaskChangeRobotStatusRequest request)
|
|
|
|
|
|
{
|
2026-07-23 14:39:55 +10:00
|
|
|
|
#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);
|
2023-10-06 11:38:33 +10:00
|
|
|
|
|
|
|
|
|
|
return Ok(new Response<RobotConfigurationResponse>(response, true));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|