From 29f20b28392d212c04c0c40a512894f8622cfa53 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 16 四月 2025 09:32:01 +0800
Subject: [PATCH] 合并

---
 CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs |  168 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 159 insertions(+), 9 deletions(-)

diff --git a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs
index 6704cde..f4e72e0 100644
--- a/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs
+++ b/CodeManagement/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_GW/GWTask/RequestInbound.cs
@@ -1,13 +1,17 @@
 锘縰sing Masuit.Tools;
+using Masuit.Tools.Systems;
 using Newtonsoft.Json;
+using System.Threading.Tasks;
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.MOM;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_DTO.WMS;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DeviceBase;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
 using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
 
@@ -162,7 +166,7 @@
                     AbNormalStationBZTask(conveyorLine, command, childDeviceCode);
                     break;
                 case 1:
-                    RequestWmsTask(conveyorLine, command, childDeviceCode);
+                    RequestWmsTask(conveyorLine, command, childDeviceCode, stationManager);
                     break;
             }
         }
@@ -173,6 +177,7 @@
         private ConveyorLineTaskCommand_After MapTaskCommand(Dt_Task task, ConveyorLineTaskCommand_After command)
         {
             var comm = _mapper.Map<ConveyorLineTaskCommand_After>(task);
+            comm.ResponState = 1;
             comm.InteractiveSignal = command.InteractiveSignal;
             return comm;
         }
@@ -216,14 +221,148 @@
         {
             if (command.ConveyorLineBarcode != "NoRead")
             {
-                
-                var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode);
+                #region
+                //var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
+                //var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.MOMIP_BASE)?.ConfigValue;
+                //var ipAddress = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.TrayCellsStatus)?.ConfigValue;
+                //if (wmsBase == null || ipAddress == null)
+                //{
+                //    throw new InvalidOperationException("MOM IP 鏈厤缃�");
+                //}
+                //var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode);
+                //TrayCellsStatusDto trayCells = new TrayCellsStatusDto()
+                //{
+                //    Software = "WMS",
+                //    TrayBarcode = command.ConveyorLineBarcode,
+                //    EquipmentCode = stationManager.stationEquipMOM,
+                //    SessionId = Guid.NewGuid().ToString(),
+                //    EmployeeNo = "MITest",
+                //    SceneType = "4",
+                //    RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
+                //};
 
-                if (_taskRepository.QueryFirst(x => x.PalletCode == taskDTO.PalletCode) != null)
+                //var MOMIpAddress = wmsBase + ipAddress;
+
+                //var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.ToJsonString()).Result;
+                //WriteInfo("鍏ョ珯鏍¢獙", $"銆恵stationManager.stationChildCode}銆戝叆绔欐牎楠岃姹傚弬鏁般�恵trayCells.ToJsonString()}銆�");
+                //WriteInfo("鍏ョ珯鏍¢獙", "");
+                //WriteInfo("鍏ョ珯鏍¢獙", $"銆恵stationManager.stationChildCode}銆戝叆绔欐牎楠岃繑鍥炲弬鏁般�恵result}銆�");
+                //ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result);
+
+                //if (result1.Success)
+                //{
+                //    var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList();
+                //    if (serialNosError.Count > 0)
+                //    {
+                //        if (result1.ProcessCode == "AG01")
+                //        {
+                //            var strings = new List<string>() { "2234", "2226", "2218" };
+                //            foreach (var item in strings)
+                //            {
+                //                var station = _stationManagerRepository.QueryFirst(x => x.productLine == result1.ProductionLine && x.stationChildCode == item);
+                //                if (station != null)
+                //                {
+                //                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == station.stationPLC);
+                //                    if (device != null)
+                //                    {
+                //                        CommonConveyorLine_After CommonConveyorLine_After = (CommonConveyorLine_After)device;
+
+                //                        ConveyorLineTaskCommand_After taskCommand = new ConveyorLineTaskCommand_After()
+                //                        {
+                //                            ConveyorLineTaskNum = Convert.ToInt32(1),
+                //                            ConveyorLineTargetAddress = Convert.ToInt16(2234),
+                //                            ConveyorLineBarcode = command.ConveyorLineBarcode.ToString(),
+                //                        };
+                //                        CommonConveyorLine_After.SendCommand(taskCommand, station.stationChildCode);
+                //                        CommonConveyorLine_After.SetValue(ConveyorLineDBName_After.ResponState, 1, station.stationChildCode);
+                //                    }
+                //                    //鍙戦�佸埌鍒嗗
+                //                    return;
+                //                }
+                //            }
+                //        }
+                //    }
+                //    else
+                //    {
+                //        var strings = new List<string>() { "2142", "2094", "2046" };
+
+                //        foreach (var item in strings)
+                //        {
+                //            var station = _stationManagerRepository.QueryFirst(x => x.productLine == result1.ProductionLine && x.stationChildCode == item);
+                //            if (station != null)
+                //            {
+                //                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == station.stationPLC);
+                //                if (device != null)
+                //                {
+                //                    CommonConveyorLine_After CommonConveyorLine_After = (CommonConveyorLine_After)device;
+                //                    ConveyorLineTaskCommand_After conveyorLineAfter = CommonConveyorLine_After.ReadCustomer<ConveyorLineTaskCommand_After>(Convert.ToInt32(station.stationChildCode).ToString());
+                //                    if (conveyorLineAfter.InteractiveSignal == 16)
+                //                    {
+                //                        var TaskNum = SnowFlake.LongId;
+                //                        Dt_Task task = new Dt_Task()
+                //                        {
+                //                            TaskNum = _taskRepository.GetTaskNo().Result,
+                //                            Grade = 1,
+                //                            PalletCode = command.ConveyorLineBarcode,
+                //                            Roadway = station.Roadway,
+                //                            SourceAddress = childDeviceCode,
+                //                            TargetAddress = station.stationChildCode,
+                //                            CurrentAddress = childDeviceCode,
+                //                            NextAddress = station.stationChildCode,
+                //                            TaskState = (int)TaskInStatusEnum.InNew,
+                //                            ExceptionMessage = "",
+                //                            TaskId = 0,
+                //                            TaskType = (int)TaskInboundTypeEnum.InTray,
+                //                            ProductionLine = result1.ProductionLine,
+                //                        };
+                //                        _taskRepository.AddData(task);
+                //                        ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
+                //                        conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                //                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
+                //                        _taskService.UpdateTaskStatusToNext(task);
+                //                    }
+                //                }
+                //                //鍙戦�佸埌鍒嗗
+                //                return;
+                //            }
+                //        }
+                //        var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode);
+
+                //        if (_taskRepository.QueryFirst(x => x.PalletCode == taskDTO.PalletCode) != null)
+                //        {
+                //            WriteInfo(conveyorLine.DeviceName, "褰撳墠鎵樼洏瀛樺湪浠诲姟");
+                //            return;
+                //        }
+
+                //        var content = CreateAndSendTask(taskDTO);
+                //        if (content.Status)
+                //        {
+                //            var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
+                //            if (task != null)
+                //            {
+                //                var taskCommand = MapTaskCommand(task, command);
+                //                conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                //                _taskService.UpdateTaskStatusToNext(task);
+                //            }
+                //        }
+                //    }
+
+                //}
+                //else
+                //{
+                //    ConsoleHelper.WriteErrorLine(result1.MOMMessage);
+                //}
+                #endregion
+
+                if (_taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode) != null)
                 {
                     WriteInfo(conveyorLine.DeviceName, "褰撳墠鎵樼洏瀛樺湪浠诲姟");
                     return;
                 }
+
+
+                var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode);
+
 
                 var content = CreateAndSendTask(taskDTO);
                 if (content.Status)
@@ -233,10 +372,10 @@
                     {
                         var taskCommand = MapTaskCommand(task, command);
                         conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                        conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
                         _taskService.UpdateTaskStatusToNext(task);
                     }
                 }
-                //}
             }
         }
 
@@ -253,7 +392,7 @@
 
             var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress);
             var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue;
-            var requestTrayInTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayInTask)?.ConfigValue;
+            var requestTrayInTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTask)?.ConfigValue;
             if (wmsBase == null || requestTrayInTask == null)
             {
                 throw new InvalidOperationException("WMS IP 鏈厤缃�");
@@ -273,9 +412,19 @@
         /// <summary>
         /// 璇锋眰WMS浠诲姟
         /// </summary>
-        private async void RequestWmsTask(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode)
+        private async void RequestWmsTask(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_StationManager stationManager)
         {
             if (command.ConveyorLineBarcode.IsNullOrEmpty()) return;
+
+            var Hastask = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode);
+            if (Hastask != null)
+            {
+                ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(Hastask);
+                conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
+                return;
+            }
+
             var content = await _taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode);
             if (content.Status)
             {
@@ -283,15 +432,16 @@
                 if (task != null)
                 {
                     ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task);
-                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
                     conveyorLine.SendCommand(taskCommand, childDeviceCode);
-                    //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true);
+                    conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
                     _taskService.UpdateTaskStatusToNext(task);
                 }
             }
             else
             {
                 WriteInfo(conveyorLine.DeviceName, content.Message);
+                conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, stationManager.stationNGChildCode, childDeviceCode);
+                conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode);
                 ConsoleHelper.WriteErrorLine($"銆恵conveyorLine.DeviceName}銆戞墭鐩樺彿锛氥�恵command.ConveyorLineBarcode}銆戣姹傜偣浣嶏細銆恵childDeviceCode}銆戝紓甯镐俊鎭�恵content.Message}銆�");
             }
         }

--
Gitblit v1.9.3