using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Mvc;
|
using RYB_PTL_API;
|
using System.Collections.Generic;
|
using System.Linq;
|
using WIDESEAWCS_DTO;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_ITaskInfoService;
|
|
namespace WIDESEAWCS_Server.Controllers
|
{
|
[Route("PTL")]
|
[ApiController]
|
public class PTLAPIController : ControllerBase
|
{
|
private readonly ITaskService _taskService;
|
private bool _eventSubscribed = false;
|
|
public PTLAPIController(ITaskService taskService)
|
{
|
_taskService = taskService;
|
SubscribeEvent();
|
}
|
|
/// <summary>
|
/// 订阅PTL事件
|
/// </summary>
|
private void SubscribeEvent()
|
{
|
if (!_eventSubscribed)
|
{
|
RYB_PTL.UserResultAvailable += new RYB_PTL.UserResultAvailableEventHandler(RYB_PTL_UserResultAvailable);
|
_eventSubscribed = true;
|
}
|
}
|
|
/// <summary>
|
/// 取消订阅PTL事件
|
/// </summary>
|
private void UnsubscribeEvent()
|
{
|
if (_eventSubscribed)
|
{
|
RYB_PTL.UserResultAvailable -= new RYB_PTL.UserResultAvailableEventHandler(RYB_PTL_UserResultAvailable);
|
_eventSubscribed = false;
|
}
|
}
|
/// <summary>
|
/// PTL回调事件处理(只处理手拍事件)
|
/// </summary>
|
private void RYB_PTL_UserResultAvailable(RYB_PTL.RtnValueStruct rs)
|
{
|
try
|
{
|
if (rs.KeyCode == null)
|
{
|
return;
|
}
|
// 构建回调数据
|
var pTLCallBackDTO = new PTLCallBackDTO
|
{
|
sIp = rs.Ip,
|
sTagID = rs.Tagid,
|
sValue = rs.Number,
|
sKeyCode = rs.KeyCode,
|
sLocator = rs.Locator
|
};
|
|
// 根据业务需要构建任务信息
|
var taskBackLight = new TaskBackLight()
|
{
|
TagNo = "B1",
|
TagCode = pTLCallBackDTO.sLocator,
|
};
|
|
// 调用服务处理手拍事件
|
_taskService.WMSLightBack(new List<TaskBackLight> { taskBackLight });
|
UnsubscribeEvent();
|
}
|
catch (Exception ex)
|
{
|
// 记录日志或处理异常
|
Console.WriteLine($"处理PTL手拍回调时出错: {ex.Message}");
|
}
|
}
|
/// <summary>
|
/// 播种墙下发(一期)
|
/// </summary>
|
[HttpPost, Route("RYB_PTL_CloseDigit5"), AllowAnonymous]
|
public EPLightContent RYB_PTL_CloseDigit5([FromBody] CloseDigit5DTO request)
|
{
|
var content = new EPLightContent();
|
try
|
{
|
bool isConnected = RYB_PTL.RYB_PTL_DspDigit5(
|
request.sIP,
|
request.sTagID,
|
request.iNum,
|
request.iMode,
|
request.iColorIndex);
|
}
|
catch (Exception ex)
|
{
|
return content.Error(ex.Message);
|
}
|
return content;
|
}
|
/// <summary>
|
/// 回调上传
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost, Route("RYB_PTL_UserResultAvailable"), AllowAnonymous]
|
public EPLightContent? RYB_PTL_UserResultAvailable([FromBody] List<PTLCallBackDTO> pTLCallBackDTOs)
|
{
|
EPLightContent content = new EPLightContent();
|
try
|
{
|
if (pTLCallBackDTOs == null)
|
{
|
return content.Error("传入不能为空");
|
}
|
|
List<TaskBackLight> taskBackLights = pTLCallBackDTOs.Select(x => new TaskBackLight()
|
{
|
TagNo = "B1",
|
TagCode = x.sLocator,
|
}).ToList();
|
content = _taskService.WMSLightBack(taskBackLights);
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 播种墙初始化(一期)
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost, Route("RYB_PTL_Connect"), AllowAnonymous]
|
public EPLightContent RYB_PTL_Connect([FromBody] ConnectDTO request)
|
{
|
EPLightContent content = new EPLightContent();
|
try
|
{
|
//RYB_PTL.UserResultAvailable += new RYB_PTL.UserResultAvailableEventHandler(RYB_PTL_UserResultAvailable);
|
bool isCfg = RYB_PTL.RYB_PTL_InitialConfiguration(new string[,] { { "11.2.30.252", "0001-0016" },{ "11.2.30.252", "1-16" } });
|
bool isConnected = RYB_PTL.RYB_PTL_Connect(request.sIp, request.iPort);
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 播种墙结束作业(一期)
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost, Route("RYB_PTL_Disconnect"), AllowAnonymous]
|
public EPLightContent RYB_PTL_Disconnect()
|
{
|
EPLightContent content = new EPLightContent();
|
try
|
{
|
bool isDisconnected = RYB_PTL.RYB_PTL_Disconnect();
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 资源释放(标记为不暴露给Swagger)
|
/// </summary>
|
[ApiExplorerSettings(IgnoreApi = true)]
|
public void Dispose()
|
{
|
UnsubscribeEvent();
|
}
|
}
|
}
|