using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Mvc;
|
using RYB_PTL_API;
|
using System.Security.Policy;
|
using WIDESEAWCS_DTO;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_IBasicInfoRepository;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_QuartzJob.Repository;
|
|
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 += RYB_PTL_UserResultAvailable;
|
// _eventSubscribed = true;
|
// }
|
//}
|
|
///// <summary>
|
///// 取消订阅PTL事件
|
///// </summary>
|
//private void UnsubscribeEvent()
|
//{
|
// if (_eventSubscribed)
|
// {
|
// RYB_PTL.UserResultAvailable -= RYB_PTL_UserResultAvailable;
|
// _eventSubscribed = false;
|
// }
|
//}
|
|
///// <summary>
|
///// PTL回调事件处理
|
///// </summary>
|
//private void RYB_PTL_UserResultAvailable(RYB_PTL.RtnValueStruct rs)
|
//{
|
// try
|
// {
|
// var content = new EPLightContent();
|
// 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 });
|
// }
|
// 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
|
{
|
bool isConnected;
|
|
if (request.iTimeOut.HasValue)
|
{
|
isConnected = RYB_PTL.RYB_PTL_Connect(request.sIp, request.iPort, request.iTimeOut.Value);
|
}
|
else
|
{
|
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>
|
///// 资源释放
|
///// </summary>
|
//public void Dispose()
|
//{
|
// UnsubscribeEvent();
|
//}
|
}
|
|
}
|