#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) { // ´¦Àí processing Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼­£© 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) { // ´¦Àí pinMachine Ϊ¿ÕµÄÇé¿ö£¨¿É¸ù¾Ýʵ¼ÊÒµÎñÐèÇóÌí¼Ó´¦ÀíÂß¼­£© 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); _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()); } } /// /// Èë¿â¾ÐÊø»úÇëÇó´¦Àí /// /// /// /// /// public void InboundConstraintMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, ConstraintMachine? constraint, string childDeviceCode) { //Èë¿â¾ÐÊø»úÇëÇó´¦ÀíÂß¼­ bool materialReq = constraint.GetValue(ConstraintMachineDBName.MaterialRequestUpper); bool outputReq = constraint.GetValue(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); } } /// /// Èë¿â²å°Î¶¤»úÇëÇó´¦Àí /// /// /// /// /// public void InboundPinMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, PinMachine? pinMachine, string childDeviceCode) { //Èë¿â²å°Î¶¤»úÇëÇó´¦ÀíÂß¼­ bool materialReq = pinMachine.GetValue(PinMachineDBName.MaterialRequestUpper); bool outputReq = pinMachine.GetValue(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); } } /// /// ³ö¿â¾ÐÊø»úÇëÇó´¦Àí /// /// /// /// /// public void OutConstraintMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, ConstraintMachine? constraint, string childDeviceCode) { //³ö¿â¾ÐÊø»úÇëÇó´¦ÀíÂß¼­ bool materialReq = constraint.GetValue(ConstraintMachineDBName.MaterialRequestLower); bool outputReq = constraint.GetValue(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); } } /// /// ³ö¿â²å°Î¶¤»úÇëÇó´¦Àí /// /// /// /// /// public void OutPinMachineRequest(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, PinMachine? pinMachine, string childDeviceCode) { //³ö¿â²å°Î¶¤»úÇëÇó´¦ÀíÂß¼­ bool materialReq = pinMachine.GetValue(PinMachineDBName.MaterialRequestLower); bool outputReq = pinMachine.GetValue(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); } } /// /// ͨÓõÄÉ豸ÇëÇó´¦Àí·½·¨ /// 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); } } } }