1
zhangchengsong
18 小时以前 4d7c377173784d6ec495b2c4178395a65f4e2a76
ÏîÄ¿´úÂë/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -1,31 +1,43 @@
using Autofac.Core;
using HslCommunication;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Hosting;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using Quartz;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Eventing.Reader;
using System.DirectoryServices.Protocols;
using System.IO.Ports;
using System.Linq;
using System.Net;
using System.Reflection.Metadata;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using WIDESEA_Comm.Http;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.TaskInfo;
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;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks.StackerCraneJob;
using static WIDESEAWCS_Model.Models.System.JobError;
namespace WIDESEAWCS_Tasks
{
@@ -36,14 +48,19 @@
        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;
        }
        private static readonly Dictionary<string, bool> _deviceLastStatus = new Dictionary<string, bool>();
        public string urlWMSdeverror = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSdeverror"];
        public Task Execute(IJobExecutionContext context)
        {
@@ -52,26 +69,76 @@
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
                    //if (!commonStackerCrane.IsEventSubscribed)
                    //{
                    //    commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    //}
                WriteLog.Write_Log("堆垛机当前状态信息", $"{commonStackerCrane.DeviceCode}库堆垛机当前状态",
                                                $"堆垛机设备状态地址:【DB105.2.0】,读取的数据:【{commonStackerCrane.StackerCraneAutoStatusDes}】\n" +
                                               $"堆垛机工作模式地址:【DB105.3.0】,读取的数据:【{commonStackerCrane.StackerCraneStatusDes}】\n" +
                                               $"堆垛机作业状态地址:【DB105.22.0】,读取的数据:【{commonStackerCrane.StackerCraneWorkStatusDes}】\n" +
                                               $"堆垛机当前任务执行中地址:【DB105.18.0】,读取的数据:【{commonStackerCrane.CurrentTaskNum}】\n");
                    // èŽ·å–å½“å‰çŠ¶æ€
                    bool isFaultNow = commonStackerCrane.StackerCraneStatusDes.Equals("故障");
                    string deviceCode = commonStackerCrane.DeviceCode;
                    if ((int)commonStackerCrane.StackerCraneWorkStatusValue == 6)
                    if (!_deviceLastStatus.ContainsKey(deviceCode))
                    {
                        WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
                        if (webResponse.Status)
                        _deviceLastStatus[deviceCode] = isFaultNow;
                        if (isFaultNow)
                        {
                            SendDevError(commonStackerCrane, "66", "start", ReadStackerFaults(commonStackerCrane));
                        }
                    }
                    else
                    {
                        bool lastStatus = _deviceLastStatus[deviceCode];
                        if (!lastStatus && isFaultNow)
                        {
                            SendDevError(commonStackerCrane, "66", "start", ReadStackerFaults(commonStackerCrane));
                            _deviceLastStatus[deviceCode] = true;
                        }
                        else if (lastStatus && !isFaultNow)
                        {
                            SendDevError(commonStackerCrane, "99", "stop", "堆垛机恢复正常");
                            _deviceLastStatus[deviceCode] = false;
                        }
                    }
                            bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                    UpdateHandShake(commonStackerCrane.CurrentTaskNum, commonStackerCrane.StackerCraneWorkStatusDes);
                    //任务完成StackerCraneWorkStatus
                    if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.WorkCompleted)
                    {
                        //判断当前任务是否是盘点
                        Dt_Task? currtask = _taskService.CurrtaskInfo(commonStackerCrane.CurrentTaskNum);
                        if(currtask != null)
                        {
                            string PalletCode = "";
                            //判断任务类型
                            if (currtask.TaskType==  (int)TaskTypeEnum.Inventorybound)
                            {
                                //读取条码,进行配对
                                DeviceProDTO? deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == "SCBarcode");
                                byte[] bytes = commonStackerCrane.Communicator.Read(deviceProDTO.DeviceProAddress, 64);
                                //读取的托盘条码
                                PalletCode = Encoding.ASCII.GetString(bytes).Replace(" ", "");
                            }
                            WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum, PalletCode);
                            if (webResponse.Status)
                            {
                                Task.Run(() => WriteLog.Write_Log("堆垛机任务上报完成信息", "堆垛机任务上报完成信息", $"【{commonStackerCrane.DeviceCode}】库堆垛机上报任务号:【{commonStackerCrane.CurrentTaskNum}】完成信号!"));
                                bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                            }
                        }
                    }
                    if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                    {
                        if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                        {
                            Dt_Task? task = GetTask(commonStackerCrane);
                            if (task != null)
                            {
@@ -81,6 +148,8 @@
                                    bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                    if (sendFlag)
                                    {
                                        commonStackerCrane.Communicator.Write("DB105.52", 1);
                                        WebResponseContent webResponseContent=_taskService.UpdateTaskStatusToNext(task.TaskNum);
                                    }
                                }
@@ -92,28 +161,50 @@
            catch (Exception ex)
            {
                Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
                WriteLog.Write_Log("堆垛机报错信息", "堆垛机报错信息", $"堆垛机报错信息:【{ex.ToString()}】");
            }
            return Task.CompletedTask;
        }
        /// <summary>
        /// ä»»åŠ¡å®Œæˆäº‹ä»¶è®¢é˜…çš„æ–¹æ³•
        /// æ•…障上报(改为await调用,修复异步BUG)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommonStackerCrane_StackerCraneTaskCompletedEventHandler(object? sender, WIDESEAWCS_QuartzJob.StackerCrane.StackerCraneTaskCompletedEventArgs e)
        public void SendDevError(CommonStackerCrane crane, string errorcode, string dealType, string errorInfo = "")
        {
            CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
            if (commonStackerCrane != null)
            CommandResult commandResult = new CommandResult();
            try
            {
                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5 && e.TaskNum !=0)
                DeviceErrorRequest deviceErrorRequest = new DeviceErrorRequest
                {
                    //Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                    _taskService.StackCraneTaskCompleted(e.TaskNum);
                    commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                }
                    devErrorJsons = new List<DeviceErrorInfo>
                    {
                        new DeviceErrorInfo
                        {
                            devuuid = crane.DeviceCode,
                            id = "",
                            errorcode = errorcode,
                            errorinfo = errorInfo,
                            erroraddress = "DB107",
                            warehouse = crane.DeviceCode == "B" ? "ZR17":(crane.DeviceCode == "G"?"ZR18":"ZR16"),
                            remark = dealType == "start" ? "设备异常" : "设备恢复",
                            devname =  $"{crane.DeviceCode}库堆垛机",
                        }
                    },
                    dealType = dealType,
                    psd = "akjfapjfpadaoif",
                };
                commandResult = HttpHelper.Post<CommandResult>(urlWMSdeverror, deviceErrorRequest, "设备故障回调");
                WriteLog.Write_Log("同步给上游设备故障信息", "设备故障信息", $"设备id:【{crane.DeviceCode}】,成功", $"设备回调状态:【{dealType}】,异常信息:【{errorInfo}】\n" +
                    $"调用上游返回结果信息:【{commandResult?.ToJsonString() ?? "返回结果为null"}】");
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("故障上报失败", "错误", ex.ToString());
            }
        }
        /// <summary>
        /// èŽ·å–ä»»åŠ¡
@@ -124,21 +215,25 @@
        {
            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))
                            if (OutTaskStationIsOccupied(taskItem.NextAddress,taskItem.Roadway))
                            {
                                return taskItem;
                            }
                        }
                        else if (taskItem.TaskType == (int)TaskInboundTypeEnum.Inbound)
                        else if ((InTaskStationIsOccupied(taskItem.SourceAddress, taskItem.Roadway) && taskItem.TaskType == (int)TaskTypeEnum.Inbound) || taskItem.TaskType == (int)TaskTypeEnum.Inventorybound)
                        {
                            return taskItem;
                        }
                    }
@@ -158,16 +253,60 @@
        /// </summary>
        /// <param name="task">任务实体</param>
        /// <returns>如果未被占用,返回传入的任务信息,否则,返回null</returns>
        private bool OutTaskStationIsOccupied(string NextAddress)
        private bool OutTaskStationIsOccupied(string NextAddress,string Roadway)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1002");
            if (device == null) return false;
            CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
            DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationFree");
            if (deviceProDTO == null) return false;
            return conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
        }
            try
            {
                    CommonConveyorLine? conveyorLine = null;
                    string deviceCode = Roadway == "C" ? "1004" : "1003";
                    conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
                if (conveyorLine == null) return false;
                DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationNum");
                DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "HandShake");
                if (deviceProDTO == null || HandShakeprodto == null) return false;
                int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
                WriteLog.Write_Log("出库库口状态信息", "出库库口状态信息", $"库口是【{NextAddress}】,申请状态地址:【{HandShakeprodto.DeviceProAddress}】,读取的数据:【{HandShake}】\n库口是否有货状态地址:【{deviceProDTO.DeviceProAddress}】,读取的数据【{StationNum}】");
                  if (Roadway == "C" || Roadway == "G") return StationNum == 0 && HandShake == 0;
                return (StationNum == 1 && HandShake == 0 && Roadway == "B");
            }
            catch (Exception ex)
            {
              Console.WriteLine("读取站台信息错误:" + ex.Message);
                return false;
            }
        }
        /// <summary>
        /// å…¥åº“任务库口有货无货状态
        /// </summary>
        public bool InTaskStationIsOccupied(string SourceAddress, string Roadway)
        {
            try
            {
                CommonConveyorLine? conveyorLine = null;
                    string deviceCode = Roadway == "C" ? "1004" : "1003";
                    conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
                if (conveyorLine == null) return false;
                DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "StationNum");
                DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SourceAddress && x.DeviceProParamName == "HandShake");
                if (deviceProDTO == null || HandShakeprodto == null) return false;
                int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
                WriteLog.Write_Log("入库库口状态信息", "入库库口状态信息", $"库口是【{SourceAddress}】,申请状态地址:【{HandShakeprodto.DeviceProAddress}】,读取的数据:【{HandShake}】\n库口是否有货状态地址:【{deviceProDTO.DeviceProAddress}】,读取的数据【{StationNum}】");
                return StationNum == 1;
            }
            catch (Exception ex)
            {
               Console.WriteLine("读取站台信息错误:" + ex.Message);
                return false;
            }
        }
        /// <summary>
        /// ä»»åŠ¡å®žä½“è½¬æ¢æˆå‘½ä»¤Model
@@ -179,18 +318,41 @@
        {
            StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
            stackerCraneTaskCommand.Barcode = ""; /*task.PalletCode;*/
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 0;
            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//判断是否是入库任务
            if (task.Roadway == "B" || task.Roadway == "C")
            {
                string[] targetCodest = task.SourceAddress.Split("-");
                if (targetCodest.Length == 5)
                //判断 task.PalletCode æ˜¯ä¸æ˜¯ä¸€ä¸ªæœ‰æ•ˆçš„ GUID
                stackerCraneTaskCommand.Barcode = stackerCraneTaskCommand.Barcode = Guid.TryParse(task.PalletCode, out var guid) ? guid.ToString("N")[0..6] : task.PalletCode;
            }
            else if (task.Roadway == "G" )
            {
                if (Guid.TryParse(task.PalletCode, out var palletGuid))
                {
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(targetCodest[1]);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(targetCodest[2]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(targetCodest[3]);
                    stackerCraneTaskCommand.Barcode = palletGuid.ToString("N")[0..6];
                    // æ ‡å‡†GUID就是36位,所以直接判断长度即可
                    stackerCraneTaskCommand.TrayType = (short)(task.PalletCode.Length == 36 ? 1 : 2);
                }
                else
                {
                    stackerCraneTaskCommand.Barcode = task.PalletCode;
                    stackerCraneTaskCommand.TrayType = 2;
                }
            }
            if (task.TaskType == (int)TaskTypeEnum.Inbound)//判断是否是入库任务
            {
                //获取站台编号
                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.SourceAddress);
                string[] targetCodest = dt_Platform.Station_storey.Split("-");
                if (targetCodest.Length == 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 +360,15 @@
                    _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);
                    string SCEndRow = LaneModification(task.Roadway, int.Parse(EndRow));
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEndRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
                else
                {
@@ -212,14 +377,16 @@
                    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);
                    string SCStartRow = LaneModification(task.Roadway, int.Parse(StartRow));
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(SCStartRow);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                }
                else
                {
@@ -227,12 +394,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.NextAddress);
                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,36 +412,114 @@
                    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]);
                    string EndRow = EndCodest[0].Substring(1);
                    string SCEnRow = LaneModification(task.Roadway, int.Parse(EndRow));
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEnRow);
                    stackerCraneTaskCommand.EndColumn = (short)(Convert.ToInt16(EndCodest[1]) + 1);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务终点错误,起点:【{task.NextAddress}】");
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"盘点任务起点错误,起点:【{task.CurrentAddress}】");
                    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]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
            }
            return stackerCraneTaskCommand;
        }
        public string LaneModification(string Roadway,int SCRow)
        {
            if (Roadway == "G")
            {
                return SCRow == 1 ? "3" : "4";
            }else if(Roadway == "C")
            {
                return SCRow == 1 ? "5" : "6";
            }
            else
            {
                return SCRow.ToString();
            }
        }
        /// <summary>
        /// ç›‘测G库、C库出库放货时屏蔽光栅
        /// </summary>
        /// <param name="taskNum"></param>
        /// <param name="stackerCraneWorkStatusDes"></param>
        public void UpdateHandShake(int taskNum, string stackerCraneWorkStatusDes)
        {
                try
                {
                    var dtTask = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                    if (dtTask == null) return;
                    string[] targets = { "G02", "G03", "G04", "C02", "C01" };
                    if (dtTask.TaskType != 100 || !targets.Contains(dtTask.TargetAddress)) return;
                    short writeValue = stackerCraneWorkStatusDes switch
                    {
                        "放货中" => 1,
                        "任务完成" => 0,
                        _ => -1
                    };
                    if (writeValue == -1) return;
                    CommonConveyorLine? conveyorLine = null;
                    lock (Storage.Devices)
                    {
                        string deviceCode = dtTask.CurrentAddress.StartsWith("C") ? "1004" : "1003";
                        conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode) as CommonConveyorLine;
                    }
                    if (conveyorLine == null) return;
                    var handShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == dtTask.TargetAddress && x.DeviceProParamName == "HandShake");
                    if (handShake == null) return;
                    conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, writeValue);
                }
                catch
                { }
        }
        /// <summary>
        /// è¯»å–故障(优化GC)
        /// </summary>
        public string ReadStackerFaults(CommonStackerCrane crane)
        {
            try
            {
                foreach (StackerFault fault in Enum.GetValues(typeof(StackerFault)))
                {
                    try
                    {
                        bool isFault = crane.Communicator.Read<bool>(fault.ToPlcAddress());
                        if (isFault)
                            return fault.GetDesc();
                    }
                    catch { }
                }
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("DB107故障读取异常", "错误", ex.ToString());
            }
            return string.Empty;
        }
    }
}