1
huanghongfeng
2 天以前 279077bf41bc726b474ca5d76cd2b8393d41d867
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -117,75 +117,13 @@
                {
                    var TaskNum = speStackerCrane.GetValue<StackerCraneDBName, Int32>(StackerCraneDBName.CurrentTaskNum);
                    WriteInfo("堆垛机任务完成", $"任务号:{TaskNum}");
                    StackerCraneTaskCompleted(e.TaskNum, speStackerCrane.DeviceCode);
                    _taskService.StackCraneTaskCompleted(e.TaskNum);
                    WriteInfo("堆垛机任务完成反馈任务号", $"任务信息,任务号:{e.TaskNum}");
                    speStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                }
            }
        }
        public WebResponseContent StackerCraneTaskCompleted(int taskNum, string deviceCode)
        {
            try
            {
                Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                if (task != null)
                {
                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                    {
                        Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StackerCraneStationCode == task.NextAddress && x.StackerCraneCode == deviceCode);
                        if (stationManger == null)
                        {
                            //_taskExecuteDetailService.AddTaskExecuteDetail(taskNum, $"输送线出库站点未配置,{task.NextAddress}");
                            _taskService.UpdateTaskExceptionMessage(taskNum, $"输送线出库站点未配置,{task.NextAddress}");
                            WriteError(deviceCode, $"输送线出库站点未配置,{task.NextAddress}");
                            return WebResponseContent.Instance.Error($"输送线出库站点未配置,{task.NextAddress}");
                        }
                        Dt_Router router = _routerRepository.QueryFirst(x => x.InOutType == task.TaskType && x.StartPosi == stationManger.StationCode);
                        if (router == null)
                        {
                            router = _routerRepository.QueryFirst(x => x.ChildPosi == deviceCode && x.ChildPosiDeviceCode == stationManger.StationDeviceCode && x.NextPosi == stationManger.StationCode && x.InOutType == task.TaskType && x.IsEnd);
                            if (router != null && router.IsEnd)
                            {
                                _taskService.TaskCompleted(taskNum);
                            }
                            else
                            {
                                _taskService.UpdateTaskExceptionMessage(taskNum, $"未找到路由信息,{task.NextAddress}");
                                WriteError(deviceCode, $"未找到路由信息,{task.NextAddress}");
                                return WebResponseContent.Instance.Error($"未找到路由信息,{task.NextAddress}");
                            }
                        }
                        if (task.TargetAddress.Contains("1030") || task.TargetAddress.Contains("1026")) //自动一线
                        {
                            _taskService.UpdateTask(task, TaskStatusEnum.Line_Execute, deviceCode: stationManger.StationDeviceCode, currentAddress: router.NextPosi);
                        }
                    }
                    else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup || task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
                    {
                        _taskService.TaskCompleted(taskNum);
                    }
                    else
                    {
                        WriteError(deviceCode, $"未找到该任务类型回调WMS任务完成接口,{task.TaskType}");
                        _taskService.UpdateTaskExceptionMessage(taskNum, $"未找到该任务类型回调WMS任务完成接口,{task.TaskType}");
                    }
                }
                else
                {
                    WriteError(deviceCode, $"未找到任务信息,任务号:{taskNum}");
                    return WebResponseContent.Instance.Error($"未找到任务信息,任务号:{taskNum}");
                }
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                WriteError(deviceCode, $"任务完成错误", ex);
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// èŽ·å–ä»»åŠ¡
        /// </summary>
@@ -195,51 +133,69 @@
        {
            Dt_Task? task;
            //堆垛机执行中
            if (_taskRepository.QueryFirst(x => x.DeviceCode == commonStackerCrane.DeviceCode && x.TaskState == TaskStatusEnum.SC_Executing.ObjToInt()) != null)
            {
                return null;
            }
            if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);         //获取入库任务
            if(task != null)
            {
                task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                if (task == null)
                {
                    task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
                }
                return task;    //如果有任务则直接下发给堆垛机
            }
            else
            {
                task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
                if (task == null)
                //进行获取堆垛机出库任务
                List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode);
                foreach (var item in tasks)
                {
                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                }
            }
            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                if (OutTaskStationIsOccupied(task) != null || true)
                {
                    return task;
                }
                else
                {
                    List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList();
                    List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes);
                    foreach (var item in tasks)
                    if (OutTaskStationIsOccupied(item) != null)
                    {
                        if (OutTaskStationIsOccupied(task) != null)
                        if(item.Roadway== "SC01")
                        {
                            return task;
                            if (item.Depth == 1) return item;
                            //调取WMS接口进行判断是否需要进行移库
                            Dt_Task dt_Task= OutTaskMovelibrary(item);
                            if (dt_Task != null) return dt_Task;
                        }
                        else
                        {
                            return item;
                        }
                    }
                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                }
            }
            return task;
        }
        private Dt_Task? OutTaskMovelibrary([NotNull] Dt_Task task)
        {
            string[] targetCodes = task.SourceAddress.Split("-");
            if (targetCodes[1] == "001")
            {
                targetCodes[1] = "002";
            }
            else if (targetCodes[1] == "004")
            {
                targetCodes[1] = "003";
            }
            targetCodes[4] = "01";
            string SourceAddress = string.Join("-", targetCodes); //组装浅库位地址
            Dt_Task? tasks = _taskService.QueryStationIsOccupiedOutTasks(task.Roadway, SourceAddress); //找浅库位是否有任务
            if (tasks != null) return tasks;
        //向wms申请判断浅库位是否有货,是否需要进行移库
            Dt_Task? taskst = _taskService.RequestWMSTaskMovelibrary(task);
            if (taskst != null) return taskst;
            return null;
        }
        /// <summary>
        /// å‡ºåº“任务判断出库站台是否被占用
        /// </summary>
@@ -285,10 +241,13 @@
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 1;
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            if (task.TaskType==(int)TaskInboundTypeEnum.Inbound)//判断是否是入库任务
            {
                string[] startCodes = task.SourceAddress.Split("-");
                Dt_StationManger dt_StationManger=_stationMangerRepository.QueryFirst(x=>x.StationCode==task.SourceAddress);
                string[] startCodes = dt_StationManger.StackerCraneStationCode.Split("-");
                if (startCodes.Length == 3)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(startCodes[0]);
@@ -312,21 +271,22 @@
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
            {
                Dt_StationManger dt_StationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == task.TargetAddress);
                string[] targetCodes = task.TargetAddress.Split("-");
                string[] targetCodes = dt_StationManger.StackerCraneStationCode.Split("-");
                stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
                stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                string[] sourceCodes = task.SourceAddress.Split("-");
                if (sourceCodes.Length == 3)
                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
                {
@@ -336,14 +296,14 @@
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
            else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)   //判断移库任务
            {
                string[] targetCodes = task.NextAddress.Split("-");
                if (targetCodes.Length == 3)
                if (targetCodes.Length == 5)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                }
                else
                {
@@ -352,11 +312,11 @@
                    return null;
                }
                string[] sourceCodes = task.CurrentAddress.Split("-");
                if (sourceCodes.Length == 3)
                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
                {