using Microsoft.AspNetCore.Mvc;
|
using NewLife.Net;
|
using System.Threading.Tasks;
|
using WIDESEA_DTO.AGV;
|
using WIDESEA_IStoragIntegrationServices;
|
using WIDESEA_StorageSocketServices;
|
|
namespace WIDESEA_WMSServer.Controllers
|
{
|
/// <summary>
|
/// AGV操作接口
|
/// </summary>
|
[Route("api/[controller]")]
|
[ApiController]
|
public class AGVController : Controller
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IAGVService _service;
|
public static bool Islock = true; // 锁,防止重复请求
|
|
public AGVController(IAGVService service, IHttpContextAccessor httpContextAccessor)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
_service = service;
|
}
|
/// <summary>
|
/// 请求入库任务
|
/// </summary>
|
/// <param name="aGVDTO"></param>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("RequestInTask"), AllowAnonymous]
|
public WebResponseContent RequestInTask([FromBody] AGVDTO aGVDTO)
|
{
|
return _service.RequestInTask(aGVDTO);
|
}
|
|
/// <summary>
|
/// AGV状态
|
/// </summary>
|
/// <param name="Status"></param>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("ReceiveAGVRuntimeStatus"), AllowAnonymous]
|
public WebResponseContent ReceiveAGVRuntimeStatus([FromBody] AGVStatus Status)
|
{
|
return _service.ReceiveAGVRuntimeStatus(Status);
|
}
|
|
/// <summary>
|
/// AGV任务开始或结束
|
/// </summary>
|
/// <param name="aGVDTO"></param>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("AGVStartOrEndJob"), AllowAnonymous]
|
public WebResponseContent AGVStartOrEndJob([FromBody] AGVDTO aGVDTO)
|
{
|
return _service.AGVStartOrEndJob(aGVDTO);
|
}
|
|
/// <summary>
|
/// 设备状态上报
|
/// </summary>
|
/// <param name="aGVDTO"></param>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("DeviceErrorResponse"), AllowAnonymous]
|
public WebResponseContent DeviceErrorResponse([FromBody] AGVDTO aGVDTO)
|
{
|
return _service.DeviceErrorResponse(aGVDTO);
|
}
|
|
/// <summary>
|
/// 设备异常上报
|
/// </summary>
|
/// <param name="DTO"></param>
|
/// <returns></returns>
|
[HttpGet, HttpPost, Route("DeviceWarning"), AllowAnonymous]
|
[TypeFilter(typeof(ThrottleFilter), Arguments = new object[] { 10 })] // 10秒节流
|
public async Task<WebResponseContent> DeviceWarning([FromBody] AGVDTO DTO)
|
{
|
WebResponseContent responseContent = new WebResponseContent();
|
try
|
{
|
// 使用真正的锁结构
|
if (Islock)
|
{
|
Islock = false;
|
try
|
{
|
return await _service.DeviceWarning(DTO);
|
}
|
finally
|
{
|
Islock = true;
|
}
|
}
|
else
|
{
|
return responseContent.Error("请求过于频繁,请稍后再试");
|
}
|
}
|
catch (Exception ex)
|
{
|
// 不需要在这里释放锁,因为TryEnter成功后会在finally中释放
|
return responseContent.Error($"设备异常上报失败: {ex.Message}");
|
}
|
}
|
}
|
}
|