From 804051e9e3013a3ad6b3e47757050e32893cf4fb Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 27 二月 2026 17:22:25 +0800
Subject: [PATCH] WCS堆垛机流程

---
 代码管理/WCS/WCSServers/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs |  102 +++++++++++++++++---------------------------------
 1 files changed, 35 insertions(+), 67 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCSServers/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCSServers/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs"
index eac52d3..ebce3f6 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCSServers/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCSServers/WIDESEAWCS_QuartzJob/QuartzNet/QuartzNetExtension.cs"
@@ -2,6 +2,7 @@
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_QuartzJob.DTO;
+using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
 
 namespace WIDESEAWCS_QuartzJob.QuartzNet
@@ -41,95 +42,62 @@
                 List<DispatchInfoDTO> dispatches = _dispatchInfoService.QueryDispatchInfos();
                 List<DeviceInfoDTO> deviceInfos = await _deviceInfoService.QueryDeviceProInfos();
 
-                deviceInfos.ForEach(x =>
+                deviceInfos.ForEach(delegate (DeviceInfoDTO x)
                 {
-                    if (!Storage.Devices.Exists(d => d.DeviceCode == x.DeviceCode))
+                    DeviceInfoDTO x2 = x;
+                    if (!Storage.Devices.Exists((IDevice d) => d.DeviceCode == x2.DeviceCode) && !x.DeviceName.Contains("鍫嗗灈鏈�"))
                     {
                         try
                         {
-                            if (!x.DeviceName.Contains("鍫嗗灈鏈�"))
+                            Type type = Assembly.Load("WIDESEAWCS_Communicator").GetType("WIDESEAWCS_Communicator." + x2.DevicePlcType);
+                            object obj = Activator.CreateInstance(type, x2.DeviceIp, x2.DevicePort, x2.DeviceName);
+                            if (new bool?((bool)type.InvokeMember("Connect", BindingFlags.InvokeMethod, null, obj, new object[0])).GetValueOrDefault())
                             {
-                                #region 杩炴帴PLC
-
-                                // 鍔犺浇绋嬪簭闆�
-                                Assembly assembly = Assembly.Load($"WIDESEAWCS_Communicator");
-                                // 鑾峰彇绫诲瀷
-                                Type? type = assembly.GetType($"WIDESEAWCS_Communicator.{x.DevicePlcType}");
-                                // 鍒涘缓瀹炰緥
-                                object? obj = Activator.CreateInstance(type, new object[] { x.DeviceIp, x.DevicePort, x.DeviceName });
-                                // 璋冪敤杩炴帴鏂规硶
-                                bool? connectResult = (bool)type.InvokeMember("Connect", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, new object[] { });
-                                // 鍒ゆ柇杩炴帴缁撴灉
-                                if (connectResult ?? false) ConsoleHelper.WriteSuccessLine(type.Name + x.DeviceCode + "杩炴帴鎴愬姛"); else ConsoleHelper.WriteErrorLine(type.Name + x.DeviceCode + "杩炴帴澶辫触");
-
-                                #endregion 杩炴帴PLC
-
-                                #region 瀹炰緥鍖栬澶囧璞�
-
-                                List<DeviceProDTO> devicePros = x.ProtocolList.Select(d => new DeviceProDTO
-                                {
-                                    // 璁惧瀛愮紪鐮�
-                                    DeviceChildCode = d.DeviceChildCode,
-                                    // 璁惧鏁版嵁绫诲瀷
-                                    DeviceDataType = d.DeviceProDataType,
-                                    // 璁惧ID
-                                    DeviceId = d.DeviceId,
-                                    // 璁惧鍗忚ID
-                                    DeviceProId = d.Id,
-                                    // 璁惧鍗忚鏁版嵁鍧�
-                                    DeviceProDataBlock = d.DeviceProDataBlock,
-                                    // 璁惧鍗忚鏁版嵁闀垮害
-                                    DeviceProDataLength = d.DeviceProDataLength,
-                                    // 璁惧鍗忚鍋忕Щ閲�
-                                    DeviceProOffset = d.DeviceProOffset,
-                                    // 璁惧鍗忚鍙傛暟鎻忚堪
-                                    DeviceProParamDes = d.DeviceProParamDes,
-                                    // 璁惧鍗忚鍙傛暟鍚嶇О
-                                    DeviceProParamName = d.DeviceProParamName,
-                                    // 璁惧鍗忚鍙傛暟绫诲瀷
-                                    DeviceProParamType = d.DeviceProParamType,
-                                    // 璁惧PLC绫诲瀷
-                                    DevicePlcType = x.DevicePlcType
-                                }).ToList();
-
-                                // 鏍规嵁璁惧绫诲瀷鑾峰彇璁惧鍗忚璇︽儏
-                                List<DeviceProtocolDetailDTO> deviceProtocolDetails = _deviceProtocolDetailService.GetDeviceProtocolDetailsByDeviceType(x.DeviceType);
-
-                                // 鍔犺浇璁惧绋嬪簭闆�
-                                Assembly assemblyDevice = Assembly.Load($"WIDESEAWCS_QuartzJob");
-                                // 鑾峰彇璁惧绫诲瀷瀵瑰簲鐨勭被鍨�
-                                Type typeDevice = assemblyDevice.GetType($"WIDESEAWCS_QuartzJob.{x.DeviceType}");
-                                // 鍒涘缓璁惧瀹炰緥
-                                object deviceInstance = Activator.CreateInstance(typeDevice, new object[] { obj, devicePros, deviceProtocolDetails, x.DeviceCode, x.DeviceName });
-
-                                #endregion 瀹炰緥鍖栬澶囧璞�
-
-                                x.Device = (IDevice)deviceInstance;
-
-                                Storage.Devices.Add((IDevice)deviceInstance);
+                                (type.Name + x2.DeviceCode + "杩炴帴鎴愬姛").WriteSuccessLine();
                             }
+                            else
+                            {
+                                (type.Name + x2.DeviceCode + "杩炴帴澶辫触").WriteErrorLine();
+                            }
+
+                            List<DeviceProDTO> list = x2.ProtocolList.Select((Dt_DeviceProtocol d) => new DeviceProDTO
+                            {
+                                DeviceChildCode = d.DeviceChildCode,
+                                DeviceDataType = d.DeviceProDataType,
+                                DeviceId = d.DeviceId,
+                                DeviceProId = d.Id,
+                                DeviceProDataBlock = d.DeviceProDataBlock,
+                                DeviceProDataLength = d.DeviceProDataLength,
+                                DeviceProOffset = d.DeviceProOffset,
+                                DeviceProParamDes = d.DeviceProParamDes,
+                                DeviceProParamName = d.DeviceProParamName,
+                                DeviceProParamType = d.DeviceProParamType,
+                                DevicePlcType = x2.DevicePlcType
+                            }).ToList();
+                            List<DeviceProtocolDetailDTO> deviceProtocolDetailsByDeviceType = _deviceProtocolDetailService.GetDeviceProtocolDetailsByDeviceType(x2.DeviceType);
+                            object obj2 = Activator.CreateInstance(Assembly.Load("WIDESEAWCS_QuartzJob").GetType("WIDESEAWCS_QuartzJob." + x2.DeviceType), obj, list, deviceProtocolDetailsByDeviceType, x2.DeviceCode, x2.DeviceName);
+                            x2.Device = (IDevice)obj2;
+                            Storage.Devices.Add((IDevice)obj2);
                         }
-                        catch (Exception ex)
+                        catch (Exception ex2)
                         {
-                            Console.WriteLine("璋冨害鏈嶅姟寮�鍚紓甯�" + ex.ToString());
+                            Console.WriteLine("璋冨害鏈嶅姟寮�鍚紓甯�" + ex2.ToString());
                         }
                     }
                     else
                     {
-                        x.Device = Storage.Devices.FirstOrDefault(d => d.DeviceCode == x.DeviceCode);
+                        x2.Device = Storage.Devices.FirstOrDefault((IDevice d) => d.DeviceCode == x2.DeviceCode);
                     }
                 });
                 for (int i = 0; i < dispatches.Count; i++)
                 {
                     var targetDevice = deviceInfos.FirstOrDefault(x => x.Id == dispatches[i].Id);
 
-                    if (targetDevice is null) continue;
-
                     // 浣跨敤妯″紡鍖归厤
                     dispatches[i].JobParams = targetDevice switch
                     {
                         { DeviceName: var name } when name.Contains("鍫嗗灈鏈�")
-                            => new RobotCraneDevice { DeviceCode = targetDevice.DeviceCode, DeviceName = targetDevice.DeviceName, IPAddress = targetDevice.DeviceIp + ":" + targetDevice.DevicePort },
+                            => new StackerCraneDevice { DeviceCode = targetDevice.DeviceCode, DeviceName = targetDevice.DeviceName, IPAddress = targetDevice.DeviceIp + ":" + targetDevice.DevicePort },
                         _ => targetDevice.Device
                     };
                     WebResponseContent responseContent = await _schedulerCenter.AddScheduleJobAsync(dispatches[i]);

--
Gitblit v1.9.3