#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;
}
///
/// ÐÄÌø´¦Àí
///
///
///
///
public void HeartBeat(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
{
//ÐÄÌø´¦ÀíÂß¼
conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, 0, childDeviceCode);
}
///
/// ÊäËÍÏßÇëÇóÈë¿â
///
/// ÊäËÍÏßʵÀý¶ÔÏó
/// ¶ÁÈ¡µÄÇëÇóÐÅÏ¢
/// ×ÓÉ豸±àºÅ
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(task);
taskCommand.WCS_ACK = command.WCS_ACK;
conveyorLine.SendCommand(taskCommand, childDeviceCode);
_taskService.UpdateTaskStatusToNext(task);
}
}
}
///
/// ÊäËÍÏßÇëÇóÈë¿âÏÂÒ»µØÖ·
///
/// ÊäËÍÏßʵÀý¶ÔÏó
/// ¶ÁÈ¡µÄÇëÇóÐÅÏ¢
/// ×ÓÉ豸±àºÅ
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().FirstOrDefault(d => d.DeviceName == ConstraintMachineName);
if (constraint == null) return;
ProcessDeviceRequest(conveyorLine, constraint, childDeviceCode,
() => constraint.GetValue(ConstraintMachineDBName.MaterialRequestUpper),
() => constraint.GetValue(ConstraintMachineDBName.OutputRequestUpper),
outputReq => constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyUpper, outputReq ? 1 : 0));
}
else if (string.Equals(task.NextAddress, PinMachineName, StringComparison.Ordinal))
{
PinMachine? pinMachine = devices.OfType().FirstOrDefault(d => d.DeviceName == PinMachineName);
if (pinMachine == null) return;
ProcessDeviceRequest(conveyorLine, pinMachine, childDeviceCode,
() => pinMachine.GetValue(PinMachineDBName.MaterialRequestUpper),
() => pinMachine.GetValue(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);
}
}
}
///
/// ÊäËÍÏßÈë¿âÍê³É
///
/// ÊäËÍÏßʵÀý¶ÔÏó
/// ¶ÁÈ¡µÄÇëÇóÐÅÏ¢
/// ×ÓÉ豸±àºÅ
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());
}
}
///
/// ÊäËÍÏßÇëÇó³öÐÅÏ¢
///
/// ÊäËÍÏßʵÀý¶ÔÏó
/// ¶ÁÈ¡µÄÇëÇóÐÅÏ¢
/// ×ÓÉ豸±àºÅ
public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode)
{
Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
if (task != null)
{
//ConveyorLineTaskCommandNew taskCommand = _mapper.Map(task);
//taskCommand.WCS_ACK = command.WCS_ACK;
//conveyorLine.SendCommand(taskCommand, childDeviceCode);
conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, task.TaskNum, childDeviceCode);
conveyorLine.SetValue(ConveyorLineDBNameNew.Barcode, task.PalletCode, childDeviceCode);
conveyorLine.SetValue(ConveyorLineDBNameNew.Target, task.TargetAddress, childDeviceCode);
conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, 1, childDeviceCode);
_taskService.UpdateTaskStatusToNext(task);
}
}
///
/// ÊäËÍÏßÇëÇó³ö¿âÏÂÒ»µØÖ·
///
/// ÊäËÍÏßʵÀý¶ÔÏó
/// ¶ÁÈ¡µÄÇëÇóÐÅÏ¢
/// ×ÓÉ豸±àºÅ
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().FirstOrDefault(d => d.DeviceName == ConstraintMachineName);
if (constraint == null)
{
// ´¦Àí processing Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼£©
return;
}
ProcessDeviceRequest(conveyorLine, constraint, childDeviceCode,
() => constraint.GetValue(ConstraintMachineDBName.MaterialRequestLower),
() => constraint.GetValue(ConstraintMachineDBName.OutputRequestLower),
outputReq => constraint.SetValue(ConstraintMachineDBName.ConstraintTrayOutputReadyLower, outputReq ? 1 : 0));
}
else if (string.Equals(task.NextAddress, PinMachineName, StringComparison.Ordinal))
{
PinMachine? pinMachine = devices.OfType().FirstOrDefault(d => d.DeviceName == PinMachineName);
if (pinMachine == null)
{
// ´¦Àí pinMachine Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼£©
return;
}
ProcessDeviceRequest(conveyorLine, pinMachine, childDeviceCode,
() => pinMachine.GetValue(PinMachineDBName.MaterialRequestLower),
() => pinMachine.GetValue(PinMachineDBName.OutputRequestLower),
outputReq => pinMachine.SetValue(PinMachineDBName.PlugPinTrayOutputReadyLower, outputReq ? 1 : 0));
}
Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
}
}
///
/// ÊäËÍÏß³ö¿âÍê³É
///
/// ÊäËÍÏßʵÀý¶ÔÏó
/// ¶ÁÈ¡µÄÇëÇóÐÅÏ¢
/// ×ÓÉ豸±àºÅ
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());
}
}
///
/// ͨÓõÄÉ豸ÇëÇó´¦Àí·½·¨
///
private void ProcessDeviceRequest(CommonConveyorLine conveyorLine, T device, string childDeviceCode,
Func getMaterialRequest, Func getOutputRequest, Action 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);
}
}
}
}