From 2cc4dfef234b47bef364edf798b5051a25f33217 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期五, 30 八月 2024 10:58:56 +0800
Subject: [PATCH] 1

---
 WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  242 ++++++++++++++++++++++++++++-------------------
 1 files changed, 144 insertions(+), 98 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs b/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
index 8e5b535..67bdf60 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -21,15 +21,16 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
-using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DTO;
+using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
 
 namespace WIDESEAWCS_Tasks
@@ -52,115 +53,40 @@
 
         public Task Execute(IJobExecutionContext context)
         {
+            Console.Out.WriteLine(DateTime.Now);
             try
             {
                 CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                 if (conveyorLine != null)
                 {
                     List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
-
+                    List<Task> tasks = new List<Task>();
                     foreach (string childDeviceCode in childDeviceCodes)
                     {
-                        ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
-                        if (command != null)
-                        {
-                            List<int> signalTypes = Enum.GetValues(typeof(PLCSignalType)).Cast<int>().ToList();
-                            if (!signalTypes.Contains(command.InteractiveSignal))
+                        //Task task = Task.Run(() =>
+                        //{
+                            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
+                            if (command != null)
                             {
-                                continue;
-                            }
-
-                            DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.InteractiveSignal.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal));
-                            if (deviceProtocolDetail != null)
-                            {
-                                PLCSignalType signalType = Enum.Parse<PLCSignalType>(deviceProtocolDetail.ProtocolDetailType);
-                                switch (signalType)
+                                DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.InteractiveSignal.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal));
+                                if (deviceProtocolDetail != null)
                                 {
-                                    case PLCSignalType.RequestInbound:
-                                        {
-                                            if (_taskService.RequestWMsTask(command.Barcode, childDeviceCode).Status)
-                                            {
-                                                Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
-                                                if (task != null)
-                                                {
-                                                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
-                                                    taskCommand.InteractiveSignal = command.InteractiveSignal;
-                                                    bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
-
-                                                    _taskService.UpdateTaskStatusToNext(task.TaskNum);
-                                                }
-                                            }
-                                        }
-                                        break;
-                                    case PLCSignalType.RequestInNextAddress:
-                                        {
-                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
-                                            if (task != null)
-                                            {
-                                                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
-                                                if (newTask != null)
-                                                {
-                                                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
-                                                    taskCommand.InteractiveSignal = command.InteractiveSignal;
-                                                    bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
-                                                }
-                                            }
-                                        }
-                                        break;
-                                    case PLCSignalType.ConveyorLineInFinish:
-                                        {
-                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
-                                            if (task != null)
-                                            {
-                                                bool t = conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
-                                                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task.TaskNum);
-                                                Console.Out.WriteLine(content.Serialize());
-                                            }
-                                        }
-                                        break;
-                                    case PLCSignalType.RequestOutbound:
-                                        {
-                                            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
-                                            if (task != null)
-                                            {
-                                                ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
-                                                taskCommand.InteractiveSignal = command.InteractiveSignal;
-                                                bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
-
-                                                _taskService.UpdateTaskStatusToNext(task.TaskNum);
-                                            }
-                                        }
-                                        break;
-                                    case PLCSignalType.RequestOutNextAddress:
-                                        {
-                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
-                                            if (task != null)
-                                            {
-                                                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
-                                                if (newTask != null)
-                                                {
-                                                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
-                                                    taskCommand.InteractiveSignal = command.InteractiveSignal;
-                                                    bool t = conveyorLine.SendCommand(taskCommand, childDeviceCode);
-                                                }
-                                            }
-                                        }
-                                        break;
-                                    case PLCSignalType.ConveyorLineOutFinish:
-                                        {
-                                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
-                                            if (task != null)
-                                            {
-                                                bool t = conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
-                                                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task.TaskNum);
-                                                Console.Out.WriteLine(content.Serialize());
-                                            }
-                                        }
-                                        break;
+                                    MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType);
+                                    if (method != null)
+                                    {
+                                        method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
+                                    }
+                                    else
+                                    {
+                                        //todo 鏈壘鍒版柟娉曟椂
+                                    }
                                 }
                             }
-                        }
+                        //});
+                        //tasks.Add(task);
                     }
+
+                    Task.WaitAll(tasks.ToArray());
                 }
 
             }
@@ -168,8 +94,128 @@
             {
                 Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
             }
-
+            finally
+            {
+                Console.Out.WriteLine(DateTime.Now);
+            }
             return Task.CompletedTask;
         }
+
+        /// <summary>
+        /// 杈撻�佺嚎璇锋眰鍏ュ簱
+        /// </summary>
+        /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
+        /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
+        /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
+        public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command,string childDeviceCode)
+        {
+            if (_taskService.RequestWMSTask(command.Barcode, childDeviceCode).Status)
+            {
+                Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
+                if (task != null)
+                {
+                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
+                    taskCommand.InteractiveSignal = command.InteractiveSignal;
+                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
+
+                    _taskService.UpdateTaskStatusToNext(task);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 杈撻�佺嚎璇锋眰鍏ュ簱涓嬩竴鍦板潃
+        /// </summary>
+        /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
+        /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
+        /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
+        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+            if (task != null)
+            {
+                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
+                if (newTask != null)
+                {
+                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
+                    taskCommand.InteractiveSignal = command.InteractiveSignal;
+                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 杈撻�佺嚎鍏ュ簱瀹屾垚
+        /// </summary>
+        /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
+        /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
+        /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
+        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+            if (task != null)
+            {
+                conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
+                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
+                Console.Out.WriteLine(content.Serialize());
+            }
+        }
+
+        /// <summary>
+        /// 杈撻�佺嚎璇锋眰鍑轰俊鎭�
+        /// </summary>
+        /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
+        /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
+        /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
+        public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
+            if (task != null)
+            {
+                ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
+                taskCommand.InteractiveSignal = command.InteractiveSignal;
+                conveyorLine.SendCommand(taskCommand, childDeviceCode);
+
+                _taskService.UpdateTaskStatusToNext(task);
+            }
+        }
+
+        /// <summary>
+        /// 杈撻�佺嚎璇锋眰鍑哄簱涓嬩竴鍦板潃
+        /// </summary>
+        /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
+        /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
+        /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
+        public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+            if (task != null)
+            {
+                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
+                if (newTask != null)
+                {
+                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask);
+                    taskCommand.InteractiveSignal = command.InteractiveSignal;
+                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 杈撻�佺嚎鍑哄簱瀹屾垚
+        /// </summary>
+        /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
+        /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
+        /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
+        public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        {
+            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
+            if (task != null)
+            {
+                conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
+                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
+                Console.Out.WriteLine(content.Serialize());
+            }
+        }
     }
 }

--
Gitblit v1.9.3