肖洋
2024-12-09 ad6f399066a747aeaba987360bce9ee40227302c
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs
@@ -14,6 +14,7 @@
using HslCommunication;
using WIDESEAWCS_DTO.WMS;
using WIDESEAWCS_Common;
using System.Text.RegularExpressions;
namespace WIDESEAWCS_Tasks
{
@@ -25,8 +26,11 @@
        private void HandleTaskOut(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue, Dt_Task taskOut)
        {
            if (taskOut == null) return;
            //ConveyorLineTaskCommand? taskCommand = MapTaskCommand(taskOut, command);
            var next = taskOut.NextAddress;
            var taskCommand = MapTaskCommand(taskOut, command);
            taskOut.NextAddress = next;
            bool isOutTray = taskOut.TaskType == (int)TaskOutboundTypeEnum.OutTray;
            bool isOutboundAndOutFinish = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.SC_OutFinish;
@@ -35,6 +39,9 @@
            if (isOutTray || isOutboundAndOutFinish || !isOutboundAndLineOutExecuting)
            {
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库,下一目标地址【{taskCommand.TargetAddress}】");
                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                _taskService.UpdateTaskStatusToNext(taskOut);
            }
@@ -47,20 +54,44 @@
        /// <summary>
        /// 处理新任务
        /// </summary>
        private void HandleNewTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        private async void HandleNewTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            if ((conveyorLine.DeviceCode == "1003" && childDeviceCode == "1016") || (conveyorLine.DeviceCode == "1005" && childDeviceCode == "1048"))
            var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode);
            switch (stationManager.stationType)
            {
                CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                case 1:
                    await RequestWmsTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                    break;
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                    await CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                    break;
                case 7:
                    RequestOutNextAddress(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                    break;
                case 10:
                    ConveyorLineOutFinish(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
                    break;
                default:
                    break;
            }
            else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1088") || (conveyorLine.DeviceCode == "1004" && childDeviceCode == "1339"))
            {
                RequestWmsTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
            }
            else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1068"))
            {
                ConveyorLineOutFinish(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
            }
            //if ((conveyorLine.DeviceCode == "1003" && childDeviceCode == "1016") || (conveyorLine.DeviceCode == "1005" && childDeviceCode == "1048"))
            //{
            //    await CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
            //}
            //else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1088") || (conveyorLine.DeviceCode == "1004" && childDeviceCode == "1339"))
            //{
            //    await RequestWmsTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
            //}
            //else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1068"))
            //{
            //    ConveyorLineOutFinish(conveyorLine, command, childDeviceCode, ProtocalDetailValue);
            //}
        }
        /// <summary>
@@ -68,6 +99,8 @@
        /// </summary>
        private ConveyorLineTaskCommand MapTaskCommand(Dt_Task task, ConveyorLineTaskCommand command)
        {
            // 使用正则表达式匹配类似 -数字 的模式,并替换为空字符串
            task.NextAddress = Regex.Replace(task.NextAddress, @"-(\d+)", "");
            var comm = _mapper.Map<ConveyorLineTaskCommand>(task);
            comm.InteractiveSignal = command.InteractiveSignal;
            return comm;
@@ -109,7 +142,7 @@
        /// <summary>
        /// 创建并发送空托盘任务
        /// </summary>
        public void CreateAndSendEmptyTrayTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        public Task CreateAndSendEmptyTrayTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            if (command.Barcode != "NoRead")
            {
@@ -118,7 +151,6 @@
                if (_taskRepository.QueryFirst(x => x.PalletCode == taskDTO.PalletCode) != null)
                {
                    WriteInfo(conveyorLine.DeviceName, "当前托盘存在任务");
                    return;
                }
                var content = CreateAndSendTask(taskDTO);
@@ -127,13 +159,21 @@
                    var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                    if (task != null)
                    {
                        //var taskCommand = MapTaskCommand(task, command);
                        var next = task.NextAddress;
                        var taskCommand = MapTaskCommand(task, command);
                        task.NextAddress = next;
                        ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库(空托盘),下一目标地址【{taskCommand.TargetAddress}】");
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
            return Task.CompletedTask;
        }
        /// <summary>
@@ -169,7 +209,7 @@
        /// <summary>
        /// 请求WMS任务
        /// </summary>
        private async void RequestWmsTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        private async Task RequestWmsTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            var content = await _taskService.RequestWMSTask(command.Barcode, childDeviceCode);
            if (content.Status)
@@ -177,7 +217,13 @@
                var task = _taskService.QueryBarCodeConveyorLineTask(command.Barcode, childDeviceCode);
                if (task != null)
                {
                    //var taskCommand = MapTaskCommand(task, command);
                    var next = task.NextAddress;
                    var taskCommand = MapTaskCommand(task, command);
                    task.NextAddress = next;
                    ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库(是胖),下一目标地址【{taskCommand.TargetAddress}】");
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    _taskService.UpdateTaskStatusToNext(task);
@@ -188,4 +234,3 @@
        }
    }
}