1
刘磊
2024-12-26 e5642daf4b6820d0706967e486b16e8d33a46d6d
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -1,5 +1,6 @@
using AutoMapper;
using HslCommunication;
using NetTaste;
using Newtonsoft.Json;
using Quartz;
using SqlSugar;
@@ -21,6 +22,7 @@
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_SignalR;
using WIDESEAWCS_Tasks.ConveyorLineJob;
@@ -31,7 +33,7 @@
    [DisallowConcurrentExecution]
    public partial class CommonConveyorLineJob : JobBase, IJob
    {
        public readonly ITaskService _taskService;
        private readonly ITaskService _taskService;
        private readonly ITaskRepository _taskRepository;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
@@ -42,8 +44,13 @@
        private readonly IDt_StationManagerRepository _stationManagerRepository;
        private readonly ICacheService _cacheService;
        private readonly INoticeService _noticeService;
        private readonly IDeviceInfoRepository _deviceInfoRepository;
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService)
        private static List<string>? userTokenIds;
        private static List<int>? userIds;
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService, IDeviceInfoRepository deviceInfoRepository)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
@@ -56,13 +63,12 @@
            _stationManagerRepository = stationManagerRepository;
            _cacheService = cacheService;
            _noticeService = noticeService;
            _deviceInfoRepository = deviceInfoRepository;
        }
        public async Task Execute(IJobExecutionContext context)
        {
            string jobName = context.JobDetail.Key.Name;
            //if (MemoryLockManager.TryAcquireLock(jobName))
            //{
            try
            {
                // 从JobDataMap中获取传递的参数
@@ -71,9 +77,11 @@
                {
                    // 查询所有子设备的位置
                    List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
                    // 并行处理每个子设备
                    var tasks = childDeviceCodes.Select(childDeviceCode => ProcessDeviceAsync(conveyorLine, childDeviceCode)).ToList();
                    await Task.WhenAll(tasks);
                    // 获取所有站点管理器
                    List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode);
@@ -93,7 +101,7 @@
                                    // 输出警告信息
                                    ConsoleHelper.WriteWarningLine($"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{station.stationChildCode}】空托盘请求扫码入库");
                                    // 处理入库请求
                                    NGRequestTaskInbound(conveyorLine, command, station.stationChildCode, 0, station.stationLocation);
                                    NGRequestTaskInbound(conveyorLine, command, station, 0);
                                }
                                else
                                {
@@ -138,64 +146,52 @@
                // 输出异常信息
                Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
            }
            //    finally
            //    {
            //        MemoryLockManager.ReleaseLock(jobName);
            //    }
            // }
            // else
            // {
            //     ConsoleHelper.WriteErrorLine($"[CommonConveyorLineJob]【{jobName}】任务已被锁定,无法处理");
            // }
            return;
        }
        private Task ProcessDeviceAsync(CommonConveyorLine conveyorLine, string childDeviceCode)
        {
            // 读取任务命令和设备命令
            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
            ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(childDeviceCode, "DeviceCommand");
            if (command != null && commandWrite != null)
            try
            {
                #region 调用事件总线通知前端
                // 获取缓存中的用户信息
                var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                if (tokenInfos != null && tokenInfos.Any())
                // 读取任务命令和设备命令
                ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
                ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(childDeviceCode, "DeviceCommand");
                if (command != null && commandWrite != null)
                {
                    var userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList();
                    var userIds = tokenInfos.Select(x => x.UserId).ToList();
                    #region 调用事件总线通知前端
                    // 构造通知数据
                    object obj = new
                    // 获取缓存中的用户信息
                    var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken");
                    if (tokenInfos != null && tokenInfos.Any())
                    {
                        command,
                        commandWrite
                    };
                    // 发送通知
                    _noticeService.LineData(userIds.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, childDeviceCode, data = obj });
                }
                        userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList();
                        userIds = tokenInfos.Select(x => x.UserId).ToList();
                #endregion 调用事件总线通知前端
                // 将交互信号转换为布尔数组
                var writeInteractiveSignal = commandWrite.WriteInteractiveSignal;
                var structs = BitConverter.GetBytes(writeInteractiveSignal).Reverse().ToArray().ToBoolArray();
                // 获取设备协议详情
                List<DeviceProtocolDetailDTO>? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.Where(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal)).ToList();
                if (deviceProtocolDetails != null)
                {
                    foreach (var item in deviceProtocolDetails)
                    {
                        int itemValue = item.ProtocalDetailValue.ObjToInt();
                        if (structs[itemValue] == true)
                        // 构造通知数据
                        object obj = new
                        {
                            var numRead = itemValue;
                            var numWrite = itemValue + 1;
                            // 输出警告信息
                            ConsoleHelper.WriteWarningLine($"【{conveyorLine.DeviceName}】【{childDeviceCode}】【{numRead.ToString()}】位输送线读取信号:【{structs[itemValue]}】 【{numWrite}】位WCS写入信号:【{structs[itemValue + 1]}】");
                            if (structs[itemValue + 1] != structs[itemValue])
                            command,
                            commandWrite
                        };
                        // 发送通知
                        _noticeService.LineData(userIds.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, childDeviceCode, data = obj });
                    }
                    #endregion 调用事件总线通知前端
                    // 将交互信号转换为布尔数组
                    var writeInteractiveSignal = commandWrite.WriteInteractiveSignal;
                    var structs = BitConverter.GetBytes(writeInteractiveSignal).Reverse().ToArray().ToBoolArray();
                    // 获取设备协议详情
                    List<DeviceProtocolDetailDTO>? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.Where(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal)).ToList();
                    if (deviceProtocolDetails != null)
                    {
                        foreach (var item in deviceProtocolDetails)
                        {
                            int itemValue = item.ProtocalDetailValue.ObjToInt();
                            if (structs[itemValue] == true)
                            {
                                // 获取处理方法
                                MethodInfo? method = GetType().GetMethod(item.ProtocolDetailType);
@@ -206,39 +202,47 @@
                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, itemValue });
                                }
                            }
                        }
                        else
                        {
                            // 发送完成信号
                            ConveyorLineSendFinish(conveyorLine, childDeviceCode, itemValue, false);
                        }
                    }
                }
                // 查询平台信息
                Platform platform = _platFormRepository.QueryFirst(x => x.PLCCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active");
                if (platform != null && !string.IsNullOrEmpty(platform.Location))
                {
                    var strings = platform.Location.Split(',').ToList();
                    foreach (var ite in strings)
                    {
                        // 读取任务命令
                        ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite);
                        if (command1.InteractiveSignal != 2)
                        {
                            command.InteractiveSignal = writeInteractiveSignal;
                            int count = strings.Count;
                            // 获取处理方法
                            MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod);
                            if (method != null)
                            else
                            {
                                command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
                                // 调用处理方法
                                method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
                            };
                                // 发送完成信号
                                ConveyorLineSendFinish(conveyorLine, childDeviceCode, itemValue, false);
                            }
                        }
                    }
                    // 查询平台信息
                    Platform platform = _platFormRepository.QueryFirst(x => x.PLCCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active");
                    if (platform != null && !string.IsNullOrEmpty(platform.Location))
                    {
                        var strings = platform.Location.Split(',').ToList();
                        foreach (var ite in strings)
                        {
                            // 读取任务命令
                            ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite);
                            if (command1.InteractiveSignal != 2)
                            {
                                command.InteractiveSignal = writeInteractiveSignal;
                                int count = strings.Count;
                                // 获取处理方法
                                MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod);
                                if (method != null)
                                {
                                    command.InteractiveSignal = commandWrite.WriteInteractiveSignal;
                                    // 调用处理方法
                                    method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform });
                                };
                            }
                        }
                    }
                    //if (conveyorLine.DeviceCode == "1001")
                    //{
                    //    ConsoleHelper.WriteSuccessLine("ProcessDeviceAsync方法结束时间:" + DateTime.Now.ToString("G") + $"点位:{childDeviceCode}");
                    //}
                }
            }
            catch (Exception ex)
            {
            }
            return Task.CompletedTask;
        }
@@ -252,12 +256,16 @@
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public async Task RequestInboundAsync(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        public async Task RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            try
            {
                // 输出警告信息,表示任务已到达子设备并请求扫码入库
                ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库");
                var log = $"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库";
                ConsoleHelper.WriteWarningLine(log);
                // 发送通知
                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
                WriteInfo(conveyorLine.DeviceName, log);
                // 查询条码对应的任务
                var task = _taskService.QueryBarCodeConveyorLineTask(command.Barcode, childDeviceCode);
@@ -352,37 +360,45 @@
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线入库完成");
            var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish)
            try
            {
                if (command.Barcode == task.PalletCode && childDeviceCode == task.NextAddress)
                ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线入库完成");
                var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish)
                {
                    //conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, "1000", childDeviceCode);
                    ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线入库完成,下一目标地址【等待分配货位,并写入1000】");
                    ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    if (task.TaskType == (int)TaskInboundTypeEnum.InNG)
                    if (command.Barcode == task.PalletCode && childDeviceCode == task.NextAddress)
                    {
                        int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
                        //conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, "1000", childDeviceCode);
                        var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress);
                        task.CurrentAddress = station.stationLocation;
                        task.NextAddress = station.stationNGLocation;
                        task.TargetAddress = task.NextAddress;
                        task.TaskState = nextStatus;
                        task.ModifyDate = DateTime.Now;
                        task.Modifier = "System";
                        _taskRepository.UpdateData(task);
                    }
                    else
                    {
                        WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
                        Console.Out.WriteLine(content.ToJsonString());
                        ConsoleHelper.WriteWarningLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线入库完成,下一目标地址【等待分配货位,并写入1000】");
                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                        if (task.TaskType == (int)TaskInboundTypeEnum.InNG)
                        {
                            int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
                            var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress);
                            task.CurrentAddress = station.stationLocation;
                            task.NextAddress = station.stationNGLocation;
                            task.TargetAddress = task.NextAddress;
                            task.TaskState = nextStatus;
                            task.ModifyDate = DateTime.Now;
                            task.Modifier = "System";
                            _taskRepository.UpdateData(task);
                        }
                        else
                        {
                            WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
                            Console.Out.WriteLine(content.ToJsonString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
@@ -399,41 +415,49 @@
        /// <param name="ProtocalDetailValue">线体当前bool读取偏移地址</param>
        public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            // 查询输送线任务,根据输送线设备和子设备代码获取任务信息
            var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
            // 输出成功信息,包括输送线名称、任务号、托盘条码和子设备代码,以及任务信息
            ConsoleHelper.WriteSuccessLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线请求出库,task{task.ToJsonString()}");
            // 如果任务不为空,则执行以下操作
            if (task != null)
            try
            {
                // 获取任务的下一目标地址
                var next = task.NextAddress;
                // 将任务命令映射到当前任务
                var taskCommand = MapTaskCommand(task, command);
                // 查询输送线任务,根据输送线设备和子设备代码获取任务信息
                var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
                // 恢复任务的下一目标地址
                task.NextAddress = next;
                // 输出成功信息,包括输送线名称、任务号、托盘条码和子设备代码,以及任务信息
                ConsoleHelper.WriteSuccessLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线请求出库,task{task.ToJsonString()}");
                // 输出成功信息,包括输送线名称、任务号、托盘条码、子设备代码和下一目标地址
                ConsoleHelper.WriteSuccessLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线请求出库,下一目标地址【{taskCommand.TargetAddress}】");
                // 向输送线发送命令
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                // 完成输送线发送任务,并更新任务状态
                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                // 更新任务状态到下一个状态
                _taskService.UpdateTaskStatusToNext(task);
                // 如果任务的目标地址是"1020-1",则再次更新任务状态到下一个状态
                if (task.TargetAddress == "1020-1")
                // 如果任务不为空,则执行以下操作
                if (task != null)
                {
                    // 获取任务的下一目标地址
                    var next = task.NextAddress;
                    // 将任务命令映射到当前任务
                    var taskCommand = MapTaskCommand(task, command);
                    // 恢复任务的下一目标地址
                    task.NextAddress = next;
                    // 输出成功信息,包括输送线名称、任务号、托盘条码、子设备代码和下一目标地址
                    ConsoleHelper.WriteSuccessLine($"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线请求出库,下一目标地址【{taskCommand.TargetAddress}】");
                    // 向输送线发送命令
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    // 完成输送线发送任务,并更新任务状态
                    ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    // 更新任务状态到下一个状态
                    _taskService.UpdateTaskStatusToNext(task);
                    // 如果任务的目标地址是"1020-1",则再次更新任务状态到下一个状态
                    if (task.TargetAddress == "1020-1")
                    {
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
@@ -493,64 +517,72 @@
        /// <param name="childDeviceCode">子设备编号</param>
        public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue)
        {
            // 打印成功信息,表示托盘已到达指定输送线并完成出库
            ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线出库完成");
            // 查询正在执行的输送线任务
            var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            // 如果任务存在
            if (task != null)
            try
            {
                // 如果任务中的托盘条码与命令中的托盘条码一致
                if (command.Barcode == task.PalletCode)
                // 打印成功信息,表示托盘已到达指定输送线并完成出库
                ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线出库完成");
                // 查询正在执行的输送线任务
                var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                // 如果任务存在
                if (task != null)
                {
                    // 创建一个空的WebResponseContent对象
                    WebResponseContent content = new WebResponseContent();
                    // 保存任务的下一目标地址
                    var next = task.NextAddress;
                    // 将任务映射为命令
                    var taskCommand = MapTaskCommand(task, command);
                    // 恢复任务的下一目标地址
                    task.NextAddress = next;
                    // 如果任务的托盘条码与命令中的托盘条码不一致或者任务备注为"NG"
                    if (task.PalletCode != command.Barcode || task.Remark == "NG")
                    // 如果任务中的托盘条码与命令中的托盘条码一致
                    if (command.Barcode == task.PalletCode)
                    {
                        // 查询目标地址的容量
                        var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity;
                        // 设置命令的目标地址为NG地址
                        taskCommand.TargetAddress = NGAddress;
                        // 创建一个空的WebResponseContent对象
                        WebResponseContent content = new WebResponseContent();
                        // 保存任务的下一目标地址
                        var next = task.NextAddress;
                        // 将任务映射为命令
                        var taskCommand = MapTaskCommand(task, command);
                        // 恢复任务的下一目标地址
                        task.NextAddress = next;
                        // 如果任务的托盘条码与命令中的托盘条码不一致或者任务备注为"NG"
                        if (task.PalletCode != command.Barcode || task.Remark == "NG")
                        {
                            // 查询目标地址的容量
                            var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity;
                            // 设置命令的目标地址为NG地址
                            taskCommand.TargetAddress = NGAddress;
                        }
                        else
                        {
                            // 设置命令的目标地址为1000
                            taskCommand.TargetAddress = 1000;
                        }
                        // 打印成功信息,表示托盘已到达指定输送线并完成出库,下一目标地址已确定
                        ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线出库完成,下一目标地址【{taskCommand.TargetAddress}】");
                        // 发送命令到输送线
                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        // 完成输送线发送
                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                        // 更新任务状态到下一个状态
                        content = _taskService.UpdateTaskStatusToNext(task);
                    }
                    else
                    {
                        // 设置命令的目标地址为1000
                        taskCommand.TargetAddress = 1000;
                        // 查询目标地址的容量
                        var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity;
                        // 打印成功信息,表示托盘已到达指定输送线并完成出库,下一目标地址已确定
                        ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线出库完成,下一目标地址【{NGAddress}】");
                        // 设置输送线的目标地址为NG地址
                        conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, NGAddress, childDeviceCode);
                        // 完成输送线发送
                        ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                        // 更新任务状态到下一个状态
                        _taskService.UpdateTaskStatusToNext(task);
                    }
                }
            }
            catch (Exception ex)
            {
                    // 打印成功信息,表示托盘已到达指定输送线并完成出库,下一目标地址已确定
                    ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线出库完成,下一目标地址【{taskCommand.TargetAddress}】");
                    // 发送命令到输送线
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    // 完成输送线发送
                    ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    // 更新任务状态到下一个状态
                    content = _taskService.UpdateTaskStatusToNext(task);
                }
                else
                {
                    // 查询目标地址的容量
                    var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity;
                    // 打印成功信息,表示托盘已到达指定输送线并完成出库,下一目标地址已确定
                    ConsoleHelper.WriteSuccessLine($"【{conveyorLine.DeviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】输送线出库完成,下一目标地址【{NGAddress}】");
                    // 设置输送线的目标地址为NG地址
                    conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, NGAddress, childDeviceCode);
                    // 完成输送线发送
                    ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    // 更新任务状态到下一个状态
                    _taskService.UpdateTaskStatusToNext(task);
                }
            }
        }
@@ -605,7 +637,7 @@
                else
                    taskOutboundTypeEnum = TaskOutboundTypeEnum.Outbound;
                // 调用检查并创建任务的方法
                await CheckAndCreateTask(taskOutboundTypeEnum, childDeviceCode, index, platform.Stacker, platform);
                await CheckAndCreateTask(taskOutboundTypeEnum, childDeviceCode, index, platform);
            }
            catch (Exception)
            {
@@ -616,7 +648,7 @@
        /// <summary>
        /// 检查任务并创建新任务
        /// </summary>
        private async Task CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, string roadWay, Platform platform)
        private async Task CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, Platform platform)
        {
            // 查询数据库中已有的任务
            var tasks = _taskRepository.QueryData(x => x.TaskType == (int)taskType && x.TargetAddress == childDeviceCode);
@@ -641,8 +673,11 @@
                }
                var wmsIpAddress = wmsBase + requestTrayOutTask;
                var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1" && x.DeviceRemark == platform.Id.ToString());
                var deviceCode = device.Select(x => x.DeviceCode).ToList();
                // 发送HTTP POST请求获取任务数据
                var result = await HttpHelper.PostAsync(wmsIpAddress, new { position = childDeviceCode, tag = (int)taskType, areaCdoe = roadWay, platform.ProductionLine }.ToJsonString());
                var result = await HttpHelper.PostAsync(wmsIpAddress, new { position = childDeviceCode, tag = (int)taskType, areaCdoe = platform.Stacker, AreaCdoes = deviceCode, platform.ProductionLine }.ToJsonString());
                // 解析返回的JSON数据
                WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result);
@@ -675,9 +710,9 @@
        #endregion 检测空盘实盘任务
        #region 化成NG口入库
        #region 设备NG口入库
        public void NGRequestTaskInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue, string TargetAddress)
        public void NGRequestTaskInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, Dt_StationManager stationManager, int ProtocalDetailValue)
        {
            var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
            var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.MOMIP_BASE)?.ConfigValue;
@@ -686,7 +721,6 @@
            {
                throw new InvalidOperationException("MOM IP 未配置");
            }
            Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode);
            TrayCellsStatusDto trayCells = new TrayCellsStatusDto()
            {
                Software = "WMS",
@@ -701,41 +735,36 @@
            var MOMIpAddress = wmsBase + ipAddress;
            var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.ToJsonString()).Result;
            WriteInfo("入站校验", $"【{childDeviceCode}】入站校验请求参数【{trayCells.ToJsonString()}】");
            WriteInfo("入站校验", $"【{stationManager.stationChildCode}】入站校验请求参数【{trayCells.ToJsonString()}】");
            WriteInfo("入站校验", "");
            WriteInfo("入站校验", $"【{childDeviceCode}】入站校验返回参数【{result}】");
            WriteInfo("入站校验", $"【{stationManager.stationChildCode}】入站校验返回参数【{result}】");
            ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result);
            var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1).ToList();
            if (serialNosError.Count > 0)
            if (result1.Success)
            {
                return;
            }
            if (result1.SerialNos.Count <= 0)
            {
                // 空托盘入库逻辑
                Dt_Task dt_Task = new Dt_Task()
                var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1).ToList();
                if (serialNosError.Count > 0)
                {
                    TargetAddress = TargetAddress,
                    PalletCode = command.Barcode,
                    NextAddress = TargetAddress,
                    TaskNum = 0
                };
                    return;
                }
                var next = dt_Task.NextAddress;
                var taskCommand = MapTaskCommand(dt_Task, command);
                dt_Task.NextAddress = next;
                if (result1.SerialNos.Count <= 0)
                {
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, stationManager.stationLocation, stationManager.stationChildCode);
                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                    ConveyorLineSendFinish(conveyorLine, stationManager.stationChildCode, ProtocalDetailValue, true);
                }
                else
                {
                    conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, 1000, stationManager.stationChildCode);
                    ConveyorLineSendFinish(conveyorLine, stationManager.stationChildCode, ProtocalDetailValue, true);
                }
            }
            else
            {
                conveyorLine.SetValue(ConveyorLineDBName.ConveyorLineTargetAddress, 1000, childDeviceCode);
                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                ConsoleHelper.WriteErrorLine(result1.MOMMessage);
            }
        }