#region << °æ ±¾ ×¢ ÊÍ >>
|
|
/*----------------------------------------------------------------
|
* ÃüÃû¿Õ¼ä£ºWIDESEAWCS_Tasks.ConveyorLineJob
|
* ´´½¨ÕߣººúͯÇì
|
* ´´½¨Ê±¼ä£º2024/8/2 16:13:36
|
* °æ±¾£ºV1.0.0
|
* ÃèÊö£º
|
*
|
* ----------------------------------------------------------------
|
* ÐÞ¸ÄÈË£º
|
* ÐÞ¸Äʱ¼ä£º
|
* °æ±¾£ºV1.0.1
|
* ÐÞ¸Ä˵Ã÷£º
|
*
|
*----------------------------------------------------------------*/
|
|
#endregion << °æ ±¾ ×¢ ÊÍ >>
|
|
using AutoMapper;
|
using System.Data;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.Service;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
public class ConveyorLineDispatchHandler
|
{
|
private readonly ITaskService _taskService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly IRouterService _routerService;
|
private readonly IMapper _mapper;
|
|
public ConveyorLineDispatchHandler(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
|
{
|
_taskService = taskService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_routerService = routerService;
|
_mapper = mapper;
|
}
|
|
/// <summary>
|
/// ÐÄÌø´¦Àí
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="command"></param>
|
/// <param name="childDeviceCode"></param>
|
public void HeartBeat(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
|
{
|
//ÐÄÌø´¦ÀíÂß¼
|
conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, 0, childDeviceCode);
|
}
|
|
/// <summary>
|
/// ÊäËÍÏßÇëÇóÈë¿â
|
/// </summary>
|
/// <param name="conveyorLine">ÊäËÍÏßʵÀý¶ÔÏó</param>
|
/// <param name="command">¶ÁÈ¡µÄÇëÇóÐÅÏ¢</param>
|
/// <param name="childDeviceCode">×ÓÉ豸±àºÅ</param>
|
public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
|
{
|
if (_taskService.RequestWMSTask(command.Barcode, childDeviceCode).Status)
|
{
|
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
|
if (task != null)
|
{
|
ConveyorLineTaskCommandNew taskCommand = _mapper.Map<ConveyorLineTaskCommandNew>(task);
|
taskCommand.WCS_ACK = command.WCS_ACK;
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
|
_taskService.UpdateTaskStatusToNext(task);
|
}
|
}
|
}
|
|
/// <summary>
|
/// ÊäËÍÏßÇëÇóÈë¿âÏÂÒ»µØÖ·
|
/// </summary>
|
/// <param name="conveyorLine">ÊäËÍÏßʵÀý¶ÔÏó</param>
|
/// <param name="command">¶ÁÈ¡µÄÇëÇóÐÅÏ¢</param>
|
/// <param name="childDeviceCode">×ÓÉ豸±àºÅ</param>
|
public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
|
if (task != null)
|
{
|
const string ConstraintMachineName = "¾ÐÊø»ú";
|
const string PinMachineName = "²å°Î¶¤»ú";
|
|
var devices = Storage.Devices;
|
|
if (string.Equals(task.NextAddress, ConstraintMachineName, StringComparison.Ordinal))
|
{
|
ConstraintMachine? constraint = devices.OfType<ConstraintMachine>().FirstOrDefault(d => d.DeviceName == ConstraintMachineName);
|
if (constraint == null)
|
{
|
// ´¦Àí processing Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼£©
|
return;
|
}
|
|
ProcessDeviceRequest(conveyorLine, constraint, childDeviceCode,
|
() => constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.MaterialRequestUpper),
|
() => constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.OutputRequestUpper),
|
outputReq => constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyUpper, outputReq ? 1 : 0));
|
}
|
else if (string.Equals(task.NextAddress, PinMachineName, StringComparison.Ordinal))
|
{
|
PinMachine? pinMachine = devices.OfType<PinMachine>().FirstOrDefault(d => d.DeviceName == PinMachineName);
|
if (pinMachine == null)
|
{
|
// ´¦Àí pinMachine Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼£©
|
return;
|
}
|
|
ProcessDeviceRequest(conveyorLine, pinMachine, childDeviceCode,
|
() => pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.MaterialRequestUpper),
|
() => pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.OutputRequestUpper),
|
outputReq => pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyUpper, outputReq ? 1 : 0));
|
}
|
|
Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
|
//if (newTask != null)
|
//{
|
// _taskService.UpdateTaskStatusToNext(task);
|
//}
|
}
|
}
|
|
/// <summary>
|
/// ÊäËÍÏßÈë¿âÍê³É
|
/// </summary>
|
/// <param name="conveyorLine">ÊäËÍÏßʵÀý¶ÔÏó</param>
|
/// <param name="command">¶ÁÈ¡µÄÇëÇóÐÅÏ¢</param>
|
/// <param name="childDeviceCode">×ÓÉ豸±àºÅ</param>
|
public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
|
if (task != null)
|
{
|
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
|
WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
|
Console.Out.WriteLine(content.Serialize());
|
}
|
}
|
|
/// <summary>
|
/// ÊäËÍÏßÇëÇó³öÐÅÏ¢
|
/// </summary>
|
/// <param name="conveyorLine">ÊäËÍÏßʵÀý¶ÔÏó</param>
|
/// <param name="command">¶ÁÈ¡µÄÇëÇóÐÅÏ¢</param>
|
/// <param name="childDeviceCode">×ÓÉ豸±àºÅ</param>
|
public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
|
if (task != null)
|
{
|
ConveyorLineTaskCommandNew taskCommand = _mapper.Map<ConveyorLineTaskCommandNew>(task);
|
taskCommand.WCS_ACK = command.WCS_ACK;
|
conveyorLine.SendCommand(taskCommand, childDeviceCode);
|
|
_taskService.UpdateTaskStatusToNext(task);
|
}
|
}
|
|
/// <summary>
|
/// ÊäËÍÏßÇëÇó³ö¿âÏÂÒ»µØÖ·
|
/// </summary>
|
/// <param name="conveyorLine">ÊäËÍÏßʵÀý¶ÔÏó</param>
|
/// <param name="command">¶ÁÈ¡µÄÇëÇóÐÅÏ¢</param>
|
/// <param name="childDeviceCode">×ÓÉ豸±àºÅ</param>
|
public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
|
if (task != null)
|
{
|
const string ConstraintMachineName = "¾ÐÊø»ú";
|
const string PinMachineName = "²å°Î¶¤»ú";
|
|
var devices = Storage.Devices;
|
|
if (string.Equals(task.NextAddress, ConstraintMachineName, StringComparison.Ordinal))
|
{
|
ConstraintMachine? constraint = devices.OfType<ConstraintMachine>().FirstOrDefault(d => d.DeviceName == ConstraintMachineName);
|
if (constraint == null)
|
{
|
// ´¦Àí processing Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼£©
|
return;
|
}
|
ProcessDeviceRequest(conveyorLine, constraint, childDeviceCode,
|
() => constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.MaterialRequestLower),
|
() => constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.OutputRequestLower),
|
outputReq => constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyLower, outputReq ? 1 : 0));
|
}
|
else if (string.Equals(task.NextAddress, PinMachineName, StringComparison.Ordinal))
|
{
|
PinMachine? pinMachine = devices.OfType<PinMachine>().FirstOrDefault(d => d.DeviceName == PinMachineName);
|
if (pinMachine == null)
|
{
|
// ´¦Àí pinMachine Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼£©
|
return;
|
}
|
ProcessDeviceRequest(conveyorLine, pinMachine, childDeviceCode,
|
() => pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.MaterialRequestLower),
|
() => pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.OutputRequestLower),
|
outputReq => pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyLower, outputReq ? 1 : 0));
|
}
|
|
Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
|
}
|
}
|
|
/// <summary>
|
/// ÊäËÍÏß³ö¿âÍê³É
|
/// </summary>
|
/// <param name="conveyorLine">ÊäËÍÏßʵÀý¶ÔÏó</param>
|
/// <param name="command">¶ÁÈ¡µÄÇëÇóÐÅÏ¢</param>
|
/// <param name="childDeviceCode">×ÓÉ豸±àºÅ</param>
|
public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
|
{
|
Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNo, childDeviceCode);
|
if (task != null)
|
{
|
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
|
WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
|
Console.Out.WriteLine(content.Serialize());
|
}
|
}
|
|
/// <summary>
|
/// Èë¿â¾ÐÊø»úÇëÇó´¦Àí
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="command"></param>
|
/// <param name="constraint"></param>
|
/// <param name="childDeviceCode"></param>
|
public void InboundConstraintMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, ConstraintMachine? constraint, string childDeviceCode)
|
{
|
//Èë¿â¾ÐÊø»úÇëÇó´¦ÀíÂß¼
|
bool materialReq = constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.MaterialRequestUpper);
|
bool outputReq = constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.OutputRequestUpper);
|
|
if (materialReq)
|
{
|
conveyorLine.SetValue(ConveyorLineDBNameNew.Target, 1, childDeviceCode);
|
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
|
}
|
else
|
{
|
constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyUpper, outputReq ? 1 : 0);
|
}
|
}
|
|
/// <summary>
|
/// Èë¿â²å°Î¶¤»úÇëÇó´¦Àí
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="command"></param>
|
/// <param name="pinMachine"></param>
|
/// <param name="childDeviceCode"></param>
|
public void InboundPinMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, PinMachine? pinMachine, string childDeviceCode)
|
{
|
//Èë¿â²å°Î¶¤»úÇëÇó´¦ÀíÂß¼
|
bool materialReq = pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.MaterialRequestUpper);
|
bool outputReq = pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.OutputRequestUpper);
|
if (materialReq)
|
{
|
conveyorLine.SetValue(ConveyorLineDBNameNew.Target, 1, childDeviceCode);
|
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
|
}
|
else
|
{
|
pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyUpper, outputReq ? 1 : 0);
|
}
|
}
|
|
/// <summary>
|
/// ³ö¿â¾ÐÊø»úÇëÇó´¦Àí
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="command"></param>
|
/// <param name="constraint"></param>
|
/// <param name="childDeviceCode"></param>
|
public void OutConstraintMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, ConstraintMachine? constraint, string childDeviceCode)
|
{
|
//³ö¿â¾ÐÊø»úÇëÇó´¦ÀíÂß¼
|
|
bool materialReq = constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.MaterialRequestLower);
|
bool outputReq = constraint.GetValue<ConstraintMachineDBName, bool>(ConstraintMachineDBName.OutputRequestLower);
|
|
if (materialReq)
|
{
|
conveyorLine.SetValue(ConveyorLineDBNameNew.Target, 1, childDeviceCode);
|
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
|
}
|
else
|
{
|
constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyLower, outputReq ? 1 : 0);
|
}
|
}
|
|
/// <summary>
|
/// ³ö¿â²å°Î¶¤»úÇëÇó´¦Àí
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="command"></param>
|
/// <param name="pinMachine"></param>
|
/// <param name="childDeviceCode"></param>
|
public void OutPinMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, PinMachine? pinMachine, string childDeviceCode)
|
{
|
//³ö¿â²å°Î¶¤»úÇëÇó´¦ÀíÂß¼
|
bool materialReq = pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.MaterialRequestLower);
|
bool outputReq = pinMachine.GetValue<PinMachineDBName, bool>(PinMachineDBName.OutputRequestLower);
|
if (materialReq)
|
{
|
conveyorLine.SetValue(ConveyorLineDBNameNew.Target, 1, childDeviceCode);
|
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
|
}
|
else
|
{
|
pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyLower, outputReq ? 1 : 0);
|
}
|
}
|
|
/// <summary>
|
/// ͨÓõÄÉ豸ÇëÇó´¦Àí·½·¨
|
/// </summary>
|
private void ProcessDeviceRequest<T>(CommonConveyorLine conveyorLine, T device, string childDeviceCode,
|
Func<bool> getMaterialRequest, Func<bool> getOutputRequest, Action<bool> setOutputReady)
|
{
|
bool materialReq = getMaterialRequest();
|
bool outputReq = getOutputRequest();
|
|
if (materialReq)
|
{
|
conveyorLine.SetValue(ConveyorLineDBNameNew.Target, 1, childDeviceCode);
|
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
|
}
|
else
|
{
|
setOutputReady(outputReq);
|
}
|
}
|
}
|
}
|