1
dengjunjie
6 天以前 8f316cbca92dc248151863320c506f961ed95db8
´úÂë¹ÜÀí/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -1,12 +1,7 @@
using Microsoft.AspNetCore.Components.Routing;
using Quartz;
using System;
using System.Collections.Generic;
using Quartz;
using SqlSugar.Extensions;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.Enums;
using WIDESEA_Core.Enums;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
@@ -14,7 +9,7 @@
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_QuartzJob.StackerCrane;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
@@ -27,11 +22,11 @@
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService)
        public CommonStackerCraneJob(ITaskService taskService, ITaskRepository taskRepository, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
        }
@@ -39,30 +34,38 @@
        {
            try
            {
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                SpeStackerCrane speStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (speStackerCrane != null)
                {
                    if (!commonStackerCrane.IsEventSubscribed)
                    GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
                    if (!getStackerObject.IsEventSubscribed)
                    {
                        commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                        getStackerObject.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    }
                    if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                    {
                        commonStackerCrane.CheckStackerCraneTaskCompleted();//防止任务完成事件监测超时,再手动触发一次
                    getStackerObject.CheckStackerCraneTaskCompleted();//检测堆垛机任务完成事件
                        if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                    if (getStackerObject.StackerCraneStatusValue == StackerCraneStatus.Ready)
                    {
                        Dt_Task? task = GetTask(speStackerCrane);
                        if (task != null)
                        {
                            Dt_Task? task = GetTask(commonStackerCrane);
                            if (task != null)
                            bool sendFlag = true;
                            //if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt())
                            //{
                            //    //向WMS申请出入库口是否有空托盘
                            //    sendFlag = false;
                            //}
                            if(sendFlag)
                            {
                                StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                                if (stackerCraneTaskCommand != null)
                                {
                                    bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                    sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand);
                                    if (sendFlag)
                                    {
                                        commonStackerCrane.LastTaskType = task.TaskType;
                                        speStackerCrane.SetValue(StackerCraneDBName.CommandSend, 1);//启动命令
                                        speStackerCrane.LastTaskType = task.TaskType;
                                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                    }
                                }
@@ -73,7 +76,7 @@
            }
            catch (Exception ex)
            {
                Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
                //WriteLog.GetLog($"堆垛机异常").Write($"{nameof(CommonStackerCraneJob)}:{ex.Message}", "堆垛机异常");
            }
            return Task.CompletedTask;
        }
@@ -83,16 +86,15 @@
        /// </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)
            SpeStackerCrane? speStackerCrane = sender as SpeStackerCrane;
            if (speStackerCrane != null)
            {
                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
                if (speStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.CommandSend) != 2)
                {
                    Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                    _taskService.StackCraneTaskCompleted(e.TaskNum);
                    commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                    speStackerCrane.SetValue(StackerCraneDBName.CommandSend, 2);
                    _taskService.StackCraneTaskCompleted(e.TaskNum, "堆垛机");
                }
            }
        }
@@ -102,50 +104,33 @@
        /// </summary>
        /// <param name="commonStackerCrane">堆垛机对象</param>
        /// <returns></returns>
        private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
        private Dt_Task? GetTask(SpeStackerCrane speStackerCrane)
        {
            Dt_Task task;
            if (commonStackerCrane.LastTaskType == null)
            Dt_Task? task;
            if (speStackerCrane.LastTaskType == null)
            {
                task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
                task = _taskService.QueryStackerCraneTask(speStackerCrane.DeviceCode);
            }
            else
            {
                if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
                bool flag = speStackerCrane.LastTaskType == TaskTypeEnum.Inbound.ObjToInt() || speStackerCrane.LastTaskType == TaskTypeEnum.PalletInbound.ObjToInt();
                if (flag == false)
                {
                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                    task = _taskService.QueryStackerCraneInTask(speStackerCrane.DeviceCode);
                    if (task == null)
                    {
                        task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
                        task = _taskService.QueryStackerCraneOutTask(speStackerCrane.DeviceCode);
                    }
                }
                else
                {
                    task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
                }
            }
            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            {
                if (OutTaskStationIsOccupied(task) != null)
                {
                    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)
                    task = _taskService.QueryStackerCraneOutTask(speStackerCrane.DeviceCode);
                    if (task == null)
                    {
                        if (OutTaskStationIsOccupied(task) != null)
                        {
                            return task;
                        }
                        task = _taskService.QueryStackerCraneInTask(speStackerCrane.DeviceCode);
                    }
                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
                }
            }
            return task;
        }
@@ -179,7 +164,6 @@
            }
            return null;
        }
        /// <summary>
        /// ä»»åŠ¡å®žä½“è½¬æ¢æˆå‘½ä»¤Model
        /// </summary>
@@ -192,52 +176,69 @@
            stackerCraneTaskCommand.Barcode = task.PalletCode;
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 0;
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())//判断是否是入库任务
            {
                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.Roadway);
                if (routers.Count > 0)
                stackerCraneTaskCommand.WorkType = 1;
                if (task.SourceAddress != null && task.TargetAddress != null)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
                    string[] targetCodes = task.NextAddress.Split("-");
                    if (targetCodes.Length == 3)
                    string[] sourceCodes = task.SourceAddress.Split("-");
                    if (sourceCodes.Length == 5)
                    {
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库任务终点错误,起点:【{task.NextAddress}】");
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库任务终点错误,起点:【{task.SourceAddress}】");
                        return null;
                    }
                    string[] targetCodes = task.TargetAddress.Split("-");
                    if (targetCodes.Length == 5)
                    {
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库任务终点错误,起点:【{task.TargetAddress}】");
                        return null;
                    }
                }
                else
                {
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.NextAddress}】信息,无法获取对应的堆垛机取货站台信息");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到站台【{task.TargetAddress},{task.SourceAddress}】信息,无法获取对应的堆垛机取货站台信息");
                    return null;
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            else if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt())
            {
                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.Roadway, task.TargetAddress);
                if (routers.Count > 0)
                stackerCraneTaskCommand.WorkType = 2;
                if (task.SourceAddress != null && task.TargetAddress != null)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
                    string[] sourceCodes = task.CurrentAddress.Split("-");
                    if (sourceCodes.Length == 3)
                    string[] targetCodes = task.TargetAddress.Split("-");
                    if (targetCodes.Length == 5)
                    {
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务终点错误,起点:【{task.SourceAddress}】");
                        return null;
                    }
                    string[] sourceCodes = task.SourceAddress.Split("-");
                    if (sourceCodes.Length == 5)
                    {
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                    }
                    else
                    {
@@ -252,33 +253,41 @@
                    return null;
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
            else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt())
            {
                string[] targetCodes = task.NextAddress.Split("-");
                if (targetCodes.Length == 3)
                stackerCraneTaskCommand.WorkType = 3;
                if (task.SourceAddress != null && task.TargetAddress != null)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
                    string[] targetCodes = task.TargetAddress.Split("-");
                    if (targetCodes.Length == 5)
                    {
                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务终点错误,起点:【{task.TargetAddress}】");
                        return null;
                    }
                    string[] sourceCodes = task.SourceAddress.Split("-");
                    if (sourceCodes.Length == 5)
                    {
                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                    }
                    else
                    {
                        //数据配置错误
                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.SourceAddress}】");
                        return null;
                    }
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务终点错误,起点:【{task.NextAddress}】");
                    return null;
                }
                string[] sourceCodes = task.CurrentAddress.Split("-");
                if (sourceCodes.Length == 3)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点终点错误,起点:【{task.SourceAddress}】,终点:【{task.TargetAddress}】");
                }
            }
            return stackerCraneTaskCommand;