wangxinhui
2025-11-18 b513ce3a4527e998da66c6f179a279472c7262a8
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Tasks/Ô­ÁÏ¿â/StackerCraneJob_YLSC3.cs
@@ -25,6 +25,7 @@
using WIDESEAWCS_Core.Helper;
using HslCommunication.WebSocket;
using WIDESEAWCS_DTO.Equipment;
using WIDESEAWCS_QuartzJob.StackerCrane;
namespace WIDESEAWCS_Tasks
{
@@ -63,7 +64,14 @@
                        commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    }
                    commonStackerCrane.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
                    if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                    //获取当前堆垛机状态
                    if (commonStackerCrane.CurrentTaskNum>0 && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.WorkCompleted)
                    {
                        StackerCraneTaskCompletedEventArgs e = new StackerCraneTaskCompletedEventArgs(commonStackerCrane.CurrentTaskNum);
                        CommonStackerCrane_StackerCraneTaskCompletedEventHandler(commonStackerCrane, e);
                    }
                    else if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal && commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)//判断下发
                    {
                        short stackerError = commonStackerCrane.Communicator.Read<short>("DB1000.54.0");
                        if (stackerError == 0)
@@ -80,8 +88,7 @@
                                        commonStackerCrane.LastTaskType = task.TaskType;
                                        task.Dispatchertime = DateTime.Now;
                                        task.ExceptionMessage = "";
                                        _taskService.UpdateTask(task, TaskStatusEnum.SC_Executing);
                                        //_taskService.UpdateTaskStatusToNext(task);
                                        _taskService.UpdateTaskStatusToNext(task);
                                        commonStackerCrane.Communicator.Write("DB1000.20.0", true);
                                        //延时1s
                                        Thread.Sleep(1000);
@@ -123,7 +130,7 @@
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
        private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender,StackerCraneTaskCompletedEventArgs e)
        {
            CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
            if (commonStackerCrane != null)
@@ -146,14 +153,19 @@
                {
                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                    {
                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneStationCode == task.NextAddress && x.StackerCraneCode == deviceCode);
                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.NextAddress && x.StackerCraneCode == deviceCode);
                        if (stationManger == null)
                        {
                            _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"输送线出库站点未配置,{task.NextAddress}");
                            _taskService.UpdateTaskExceptionMessage(taskNum, $"输送线出库站点未配置,{task.NextAddress}");
                            return WebResponseContent.Instance.Error($"输送线出库站点未配置,{task.NextAddress}");
                        }
                        Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && x.StartPosi == stationManger.StationCode && x.ChildPosi == stationManger.StationDeviceCode);
                        bool depth = false;
                        if (task.Grade > 0 && task.TaskType == TaskTypeEnum.PrintYLOutbound.ObjToInt())
                        {
                            depth = true;
                        }
                        Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && x.StartPosi == stationManger.StationCode && x.ChildPosi == stationManger.StationDeviceCode && (depth ? x.Depth == 2 : true));
                        if (router == null)
                        {
                            _taskService.UpdateTaskExceptionMessage(taskNum, $"未找到路由信息,{task.NextAddress}");
@@ -164,8 +176,21 @@
                        //原料一楼出库下发线体逻辑
                        if (stationManger.StationDeviceCode == "CL1_YL")
                        {
                            // å †åž›æœºå®Œæˆ
                            _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: stationManger.StationDeviceCode, currentAddress: stationManger.StationCode, nextAddress: router.NextPosi);
                            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode);
                            if (device != null)
                            {
                                OtherDevice otherDevice = (OtherDevice)device;
                                otherDevice.SetValue(WR_CLineYLDB.WR_Task, taskNum, stationManger.StationCode);
                                // å †åž›æœºå®Œæˆ
                                _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: stationManger.StationDeviceCode, currentAddress: stationManger.StationCode, nextAddress: router.NextPosi);
                            }
                            else
                            {
                                WriteError(deviceCode, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                                _taskService.UpdateTaskExceptionMessage(taskNum, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                                return WebResponseContent.Instance.Error($"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                            }
                        }
                        else//原料二楼出库下发线体逻辑
                        {
@@ -176,13 +201,14 @@
                                conveyorLine.SetValue(ConveyorLineDBName.TaskNum, taskNum, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.TargetAddress, router.NextPosi, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.Width, task.TaskLength, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.Height, task.HeightType, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.Barcode, task.PalletCode, stationManger.StationCode);
                                conveyorLine.SetValue(ConveyorLineDBName.ResponState, 86, stationManger.StationCode);
                                _taskService.UpdateTaskStatusToNext(task);
                            }
                            else
                            {
                                WriteInfo(deviceCode, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                                WriteError(deviceCode, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                                _taskService.UpdateTaskExceptionMessage(taskNum, $"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                                return WebResponseContent.Instance.Error($"未找到出库站台【{stationManger.StationDeviceCode}】对应的通讯对象,无法发送输送线出库信号");
                            }
@@ -193,19 +219,23 @@
                    }
                    else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup || task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
                    {
                        WriteInfo(deviceCode, $"堆垛机任务完成,任务号:{taskNum}");
                        _taskService.TaskCompleted(taskNum);
                        WebResponseContent responseContent = _taskService.TaskCompleted(taskNum);
                        if (!responseContent.Status)
                        {
                            _taskService.UpdateTaskExceptionMessage(taskNum, $"{responseContent.Message}");
                        }
                        WriteInfo(deviceCode, $"堆垛机入库任务完成,任务号:{taskNum}");
                    }
                    else
                    {
                        WriteInfo(deviceCode, $"未找到该任务类型回调WMS任务完成接口,{task.TaskType}");
                        WriteError(deviceCode, $"未找到该任务类型回调WMS任务完成接口,{task.TaskType}");
                        _taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"未找到该任务类型回调WMS任务完成接口,{task.TaskType}");
                        _taskService.UpdateTaskExceptionMessage(taskNum, $"未找到该任务类型回调WMS任务完成接口,{task.TaskType}");
                    }
                }
                else
                {
                    WriteInfo(deviceCode, $"未找到任务信息,任务号:{taskNum}");
                    WriteError(deviceCode, $"未找到任务信息,任务号:{taskNum}");
                    return WebResponseContent.Instance.Error($"未找到任务信息,任务号:{taskNum}");
                }
@@ -226,6 +256,13 @@
        /// <returns></returns>
        private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
        {
            //判断是否有正执行的任务,如果有则不下发
            Dt_Task? taskOld = _taskRepository.QueryFirst(x => x.DeviceCode == commonStackerCrane.DeviceCode && x.Roadway == commonStackerCrane.DeviceCode && x.TaskState == TaskStatusEnum.SC_Executing.ObjToInt());
            if (taskOld != null)
            {
                return null;
            }
            Dt_Task? task;
            if (commonStackerCrane.LastTaskType == null)
            {
@@ -301,9 +338,14 @@
                        OtherDevice client = (OtherDevice)device;
                        if (client.GetValue<WR_CLineYLDB, short>(WR_CLineYLDB.WR_Request, stationManger.StationCode) != 99)//出库站台未被占用
                        {
                            task.NextAddress = stationManger.StackerCraneStationCode;
                            _taskRepository.UpdateData(task);
                            //task.NextAddress = stationManger.StackerCraneStationCode;
                            //_taskRepository.UpdateData(task);
                            return task;
                        }
                        else
                        {
                            task.ExceptionMessage = "出库站台无法下发";
                            _taskRepository.UpdateData(task);
                        }
                    }
                    else
@@ -323,6 +365,11 @@
                            task.NextAddress = stationManger.StackerCraneStationCode;
                            _taskRepository.UpdateData(task);
                            return task;
                        }
                        else
                        {
                            task.ExceptionMessage = "出库站台无法下发";
                            _taskRepository.UpdateData(task);
                        }
                    }
                    else
@@ -350,9 +397,9 @@
        {
            YLStackerCraneTaskCommand stackerCraneTaskCommand = new YLStackerCraneTaskCommand();
            stackerCraneTaskCommand.PalletType = Convert.ToInt16(task.PalletType);
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 5;
            stackerCraneTaskCommand.PalletType = Convert.ToInt16(task.PalletType);
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            {
@@ -384,12 +431,13 @@
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//判断是否是出库任务
            {
                string[] targetCodes = task.NextAddress.Split("-");
                Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x=>x.StationCode==task.NextAddress && x.StackerCraneCode==task.DeviceCode);
                string[] targetCodes = stationManger.StackerCraneStationCode.Split("-");
                if (targetCodes.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                }
                else
                {
@@ -400,9 +448,9 @@
                string[] sourceCodes = task.CurrentAddress.Split("-");
                if (sourceCodes.Length == 5)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                }
                else
                {