wanshenmean
2025-03-27 48fce55ab5d11a1821ab640742153425d594709c
CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/Task/RequestInbound.cs
@@ -1,7 +1,8 @@
//using HslCommunication;
using HslCommunication;
using Mapster;
using Masuit.Tools;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.CodeAnalysis;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -172,7 +173,7 @@
                        RoadWay = childDeviceCode,
                        SourceAddress = childDeviceCode,
                        TargetAddress = isTrue,
                        TaskState = (int)TaskOutStatusEnum.OutNew,
                        TaskState = (int)TaskOutStatusEnum.SC_OutFinish,
                        Id = 0,
                        TaskType = (int)TaskOutboundTypeEnum.TrayInToOut,
                        ProductionLine = result.ProductionLine,
@@ -283,10 +284,12 @@
        private async Task RequestWmsTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue, Dt_StationManager stationManager)
        {
            string isTrue = string.Empty;
            ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
            ResultTrayCellsStatus result = GetResultTrayCellsStatus(command, stationManager);
            if(result.SerialNos.Count == 0)
            if (result.SerialNos.Count == 0)
            {
                var Traycontent = await _taskService.RequestWMSTask(command.Barcode, childDeviceCode);
                if (Traycontent.Status)
@@ -399,7 +402,6 @@
            #endregion
        }
        /// <summary>
        /// 成化入静置
        /// </summary>
@@ -412,30 +414,50 @@
        /// <exception cref="InvalidOperationException"></exception>
        private async Task JZRequestInBound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue, Dt_StationManager stationManager)
        {
            ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
            ResultTrayCellsStatus resultTrayCellsStatus = GetResultTrayCellsStatus(command, stationManager);
            //todo判断是否为空框
            var serialNosError = resultTrayCellsStatus.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList();
            if (serialNosError.Count > 0)
            {
                //空框逻辑
                //NG流程
                var platform = _platFormRepository.QueryFirst(x => x.ProductionLine == resultTrayCellsStatus.ProductionLine);
                ConveyorLineTaskCommand conveyorLineTaskCommand = new ConveyorLineTaskCommand()
                {
                    TaskNum = 1,
                    TargetAddress=Convert.ToInt32( platform.Capacity),
                    Barcode= resultTrayCellsStatus.TrayBarcode,
                };
                conveyorLine.SendCommand(conveyorLineTaskCommand, childDeviceCode);
                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
                ConsoleHelper.WriteSuccessLine($"MOM数据异常,送至二封【{resultTrayCellsStatus.ProductionLine}】异常口【{Convert.ToInt32(platform.Capacity)}】");
                return;
            }
            if (resultTrayCellsStatus.SerialNos.Count == 0)
            {
                var Traycontent = await _taskService.RequestWMSTask(command.Barcode, childDeviceCode);
                if (Traycontent.Status)
                {
                    ConsoleHelper.WriteSuccessLine("化成空框请求回流静置");
                    ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
                    return;
                }
            }
            else
            {
                var configz = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
                var wmsbase = configz.Where(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE).FirstOrDefault()?.ConfigValue;
                var address = configz.Where(x => x.ConfigKey == SysConfigKeyConst.GetJZStockInfo).FirstOrDefault()?.ConfigValue;
                var address = configz.Where(x => x.ConfigKey == SysConfigKeyConst.QueryStockInfoForRealTrayJZAsync).FirstOrDefault()?.ConfigValue;
                if (wmsbase == null || address == null)
                {
                    throw new InvalidOperationException("WMS IP 未配置");
                }
                var wmsIpAddrss = wmsbase + address;
                var result = await HttpHelper.PostAsync(wmsIpAddrss);
                var result = await HttpHelper.PostAsync(wmsIpAddrss, new { ProductLine = resultTrayCellsStatus.ProductionLine }.ToJsonString());
                var StockInfocontent = JsonConvert.DeserializeObject<WebResponseContent>(result);
                if (StockInfocontent.Status)
                {
@@ -451,24 +473,34 @@
                            {
                                ConsoleHelper.WriteSuccessLine("化成实托请求入静置");
                                ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
                                return;
                            }
                            else
                            {
                                ConsoleHelper.WriteWarningLine("出库任务未完成");
                                return;
                            }
                        }
                        else if (task != null && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting)
                        {
                            ConsoleHelper.WriteWarningLine("已存在静置出库任务");
                            return;
                        }
                        else
                        {
                            ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
                            var Task = await _taskService.RequestWMSTask(command.Barcode, childDeviceCode);
                            if (Task.Status)
                            {
                                ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
                            }
                            return;
                        }
                    }
                    else
                    {
                        WriteInfo(conveyorLine.DeviceName, Taskcontent.Message);
                        return;
                    }
                }
                else
                {
@@ -493,7 +525,7 @@
                            RoadWay = isTrue,
                            SourceAddress = childDeviceCode,
                            TargetAddress = isTrue,
                            TaskState = (int)TaskOutStatusEnum.OutNew,
                            TaskState = (int)TaskOutStatusEnum.SC_OutFinish,
                            Id = 2,
                            TaskType = (int)TaskOutboundTypeEnum.InToOut,
                            ProductionLine = resultTrayCellsStatus.ProductionLine,
@@ -502,28 +534,30 @@
                        if (Taskcontent.Status)
                        {
                            ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
                            return;
                        }
                        else
                        {
                            WriteInfo(conveyorLine.DeviceName, Taskcontent.Message);
                            return;
                        }
                    }
                    else
                    {
                        var Task = await _taskService.RequestWMSTask(command.Barcode, childDeviceCode);
                        if (Task.Status)
                        {
                            ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode);
                        }
                        ConsoleHelper.WriteWarningLine("二封缓存位已满");
                        return;
                    }
                }
            }
        }
        /// <summary>
        /// 执行输送线任务
        /// </summary>
        /// <param name="conveyorLine">输送线对象</param>
        /// <param name="command">输送线任务命令</param>
        /// <param name="ProtocalDetailValue">协议明细值</param>
        /// <param name="childDeviceCode">子设备编号</param>
        //public void ExecuteConveyorLineTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, int ProtocalDetailValue, string childDeviceCode)
        //public void ExecuteConveyorLineTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, int ProtocalDetailValue ,string childDeviceCode)
        //{
        //    var task = _taskService.QueryBarCodeConveyorLineTask(command.Barcode, childDeviceCode);
        //    if (task != null)
@@ -542,45 +576,40 @@
        //            ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
        //        }
        //        else if (task.TargetAddress == "1020-1")
        //        {
        //            var next = task.NextAddress;
        //            var taskCommand = MapTaskCommand(task, command);
        //            task.NextAddress = next;
        //            var log = $"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库(实盘),下一目标地址【{taskCommand.TargetAddress}】";
        //            ConsoleHelper.WriteWarningLine(log);
        //            _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
        //            WriteInfo(conveyorLine.DeviceName, log);
        //            conveyorLine.SendCommand(taskCommand, childDeviceCode);
        //            ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
        //            var taskHty = task.Adapt<Dt_Task_Hty>();
        //            _task_HtyRepository.AddData(taskHty);
        //            _taskService.DeleteData(task);
        //        }
        //        else
        //        {
        //            if (task.Roadway.Contains("JZ"))
        //            {
        //                var outJZTask = _taskRepository.QueryData(x => x.Roadway== task.Roadway && x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting || x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting || x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish);
        //                if (outJZTask.IsNullOrEmpty())
        //                {
        //                    var next = task.NextAddress;
        //                    var taskCommand = MapTaskCommand(task, command);
        //                    task.NextAddress = next;
        //            var next = task.NextAddress;
        //            var taskCommand = MapTaskCommand(task, command);
        //            task.NextAddress = next;
        //                    var log = $"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库(实盘),下一目标地址【{taskCommand.TargetAddress}】";
        //                    ConsoleHelper.WriteWarningLine(log);
        //            var log = $"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库(实盘),下一目标地址【{taskCommand.TargetAddress}】";
        //            ConsoleHelper.WriteWarningLine(log);
        //                    _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
        //                    WriteInfo(conveyorLine.DeviceName, log);
        //            _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
        //            WriteInfo(conveyorLine.DeviceName, log);
        //                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
        //                    ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
        //                    _taskService.UpdateTaskStatusToNext(task);
        //                }
        //                else
        //                {
        //                    ConsoleHelper.WriteWarningLine("已存在静置出库任务,静置入库任务无法下发线体");
        //                }
        //            }
        //            else
        //            {
        //                var next = task.NextAddress;
        //                var taskCommand = MapTaskCommand(task, command);
        //                task.NextAddress = next;
        //                var log = $"【{conveyorLine._deviceName}】任务号:【{command.TaskNum}】,托盘条码:【{command.Barcode}】已到达【{childDeviceCode}】请求扫码入库(实盘),下一目标地址【{taskCommand.TargetAddress}】";
        //                ConsoleHelper.WriteWarningLine(log);
        //                _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" });
        //                WriteInfo(conveyorLine.DeviceName, log);
        //                conveyorLine.SendCommand(taskCommand, childDeviceCode);
        //                ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
        //                _taskService.UpdateTaskStatusToNext(task);
        //            }
        //            conveyorLine.SendCommand(taskCommand, childDeviceCode);
        //            ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
        //            _taskService.UpdateTaskStatusToNext(task);
        //        }
        //    }
        //}
@@ -596,6 +625,7 @@
        {
            // 查询任务信息
            var task = _taskService.QueryBarCodeConveyorLineTask(command.Barcode, childDeviceCode);
            if (task == null) return;
            // 获取配置值并转换为列表
@@ -610,6 +640,7 @@
            {
                // 设置目标地址为 "1000"
                conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, "1000", childDeviceCode);
                // 记录日志并发送完成信号
                LogAndSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, logMessage, "1000");
            }
@@ -625,10 +656,13 @@
                {
                    // 映射任务命令
                    var taskCommand = MapTaskCommand(task, command);
                    // 记录日志并发送完成信号
                    LogAndSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, logMessage, taskCommand.TargetAddress.ToString());
                    // 发送任务命令
                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                    // 记录日志并发送完成信号
                    LogAndSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, logMessage, taskCommand.TargetAddress.ToString());
                    // 更新任务状态
                    _taskService.UpdateTaskStatusToNext(task);
                }
@@ -641,10 +675,13 @@
            {
                // 映射任务命令
                var taskCommand = MapTaskCommand(task, command);
                // 记录日志并发送完成信号
                LogAndSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, logMessage, taskCommand.TargetAddress.ToString());
                // 发送任务命令
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
                // 记录日志并发送完成信号
                LogAndSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, logMessage, taskCommand.TargetAddress.ToString());
                // 更新任务状态
                _taskService.UpdateTaskStatusToNext(task);
            }