Admin
2026-03-23 f679f58dba34055bd579a603762c13fbe1650c9b
ÏîÄ¿´úÂë/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -12,13 +12,16 @@
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
@@ -36,13 +39,15 @@
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly ITaskRepository _taskRepository;
        private readonly IRouterService _routerService;
        private readonly IDt_PlatformStationService _DtPlatformStationService;
        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService)
        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IDt_PlatformStationService dt_PlatformStationService)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _taskRepository = taskRepository;
            _routerService = routerService;
            _DtPlatformStationService= dt_PlatformStationService;
        }
        public Task Execute(IJobExecutionContext context)
@@ -57,13 +62,35 @@
                    //    commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    //}
                    if ((int)commonStackerCrane.StackerCraneWorkStatusValue == 6)
                    {
                        WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
                        if (webResponse.Status)
                        //判断当前任务是否是盘点
                        Dt_Task? currtask = _taskService.CurrtaskInfo(commonStackerCrane.CurrentTaskNum);
                        if(currtask != null)
                        {
                            //判断任务类型
                            if(currtask.TaskType==  (int)TaskTypeEnum.Inventorybound)
                            {
                                //读取条码,进行配对
                            bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                                DeviceProDTO? deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == "SCBarcode");
                                byte[] bytes = commonStackerCrane.Communicator.Read(deviceProDTO.DeviceProAddress, 64);
                                string result = Encoding.ASCII.GetString(bytes).Replace(" ", "");
                                bool pandianBort = false;
                                if(currtask.PalletCode== result) pandianBort= true;
                            }
                            WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
                            if (webResponse.Status)
                            {
                                bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                            }
                        }
                    }
@@ -124,20 +151,23 @@
        {
            try 
            {
                List<Dt_Task> task;
                task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
                //判断当前堆垛机是否有在执行的任务
                if (_taskService.CutStackerCraneTask(commonStackerCrane.DeviceCode) != null) return null;
                List<Dt_Task> task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
                if (task.Count > 0)
                {
                    foreach (Dt_Task taskItem in task)
                    {
                        if (taskItem.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                        if (taskItem.TaskType == (int)TaskTypeEnum.Outbound)
                        {
                            if (OutTaskStationIsOccupied(taskItem.NextAddress))
                            {
                                return taskItem;
                            }
                        }
                        else if (taskItem.TaskType == (int)TaskInboundTypeEnum.Inbound)
                        else if (taskItem.TaskType == (int)TaskTypeEnum.Inbound || taskItem.TaskType == (int)TaskTypeEnum.Inventorybound)
                        {
                            return taskItem;
                        }
@@ -160,7 +190,7 @@
        /// <returns>如果未被占用,返回传入的任务信息,否则,返回null</returns>
        private bool OutTaskStationIsOccupied(string NextAddress)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1002");
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1003");
            if (device == null) return false;
            CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
            DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationFree");
@@ -179,18 +209,22 @@
        {
            StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
            stackerCraneTaskCommand.Barcode = ""; /*task.PalletCode;*/
            stackerCraneTaskCommand.Barcode = task.PalletCode;
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 0;
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            if (task.TaskType == (int)TaskTypeEnum.Inbound)//判断是否是入库任务
            {
                string[] targetCodest = task.SourceAddress.Split("-");
                if (targetCodest.Length == 5)
                //获取站台编号
                Dt_PlatformStation dt_Platform=_DtPlatformStationService.getStatiomInfo(task.SourceAddress);
                string[] targetCodest = dt_Platform.Station_storey.Split("-");
                if (targetCodest.Length == 3)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(targetCodest[1]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(targetCodest[2]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(targetCodest[3]);
                    string StartRow = targetCodest[0].Substring(1);
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(StartRow);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(targetCodest[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(targetCodest[2]);
                }
                else
                {
@@ -198,12 +232,13 @@
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"入库起点错误,起点:【{task.SourceAddress}】");
                    return null;
                }
                string[] targetCodes = task.NextAddress.Split("-");
                if (targetCodes.Length == 5)
                string[] EndCodest = task.NextAddress.Split("-");
                if (EndCodest.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                    string EndRow = EndCodest[0].Substring(1);
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
                else
                {
@@ -212,14 +247,15 @@
                    return null;
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
            else if (task.TaskType == (int)TaskTypeEnum.Outbound)
            {
                string[] sourceCodes = task.CurrentAddress.Split("-");
                if (sourceCodes.Length == 5)
                if (sourceCodes.Length == 3)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                    string StartRow = sourceCodes[0].Substring(1);
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(StartRow);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                }
                else
                {
@@ -227,12 +263,16 @@
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"出库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
                string[] sourceCodest = task.TargetAddress.Split("-");
                if (sourceCodest.Length == 5)
                //获取站台编号
                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.SourceAddress);
                string[] EndCodest = dt_Platform.Station_storey.Split("-");
                if (EndCodest.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(sourceCodest[1]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(sourceCodest[2]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(sourceCodest[3]);
                    string EndRow = EndCodest[0].Substring(1);
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
                else
                {
@@ -241,27 +281,21 @@
                    return null;
                }
            }
            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
            else if (task.TaskType == (int)TaskTypeEnum.Inventorybound)
            {
                string[] targetCodes = task.NextAddress.Split("-");
                if (targetCodes.Length == 5)
                stackerCraneTaskCommand.WorkType = 6;
                stackerCraneTaskCommand.StartRow = Convert.ToInt16(0);
                stackerCraneTaskCommand.StartColumn = Convert.ToInt16(0);
                stackerCraneTaskCommand.StartLayer = Convert.ToInt16(0);
                string[] EndCodest = task.NextAddress.Split("-");
                if (EndCodest.Length == 3)
                {
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务终点错误,起点:【{task.NextAddress}】");
                    return null;
                }
                string[] sourceCodes = task.CurrentAddress.Split("-");
                if (sourceCodes.Length == 5)
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                    string EndRow = EndCodest[0].Substring(1);
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
                else
                {
@@ -269,6 +303,8 @@
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
            }
            return stackerCraneTaskCommand;
        }