From c020f31a67fc5aa5644511bddff075f7ecc85234 Mon Sep 17 00:00:00 2001
From: qinchulong <qinchulong@hnkhzn.com>
Date: 星期二, 27 五月 2025 15:35:27 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/HuaYiZhongHeng/ZhongHeLiTiKu

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 218 insertions(+), 0 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
new file mode 100644
index 0000000..f552139
--- /dev/null
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
@@ -0,0 +1,218 @@
+锘�#region << 鐗� 鏈� 娉� 閲� >>
+/*----------------------------------------------------------------
+ * 鍛藉悕绌洪棿锛歐IDESEAWCS_Tasks.ConveyorLineJob
+ * 鍒涘缓鑰咃細鑳$搴�
+ * 鍒涘缓鏃堕棿锛�2024/8/2 16:13:36
+ * 鐗堟湰锛歏1.0.0
+ * 鎻忚堪锛�
+ *
+ * ----------------------------------------------------------------
+ * 淇敼浜猴細
+ * 淇敼鏃堕棿锛�
+ * 鐗堟湰锛歏1.0.1
+ * 淇敼璇存槑锛�
+ * 
+ *----------------------------------------------------------------*/
+#endregion << 鐗� 鏈� 娉� 閲� >>
+
+using AutoMapper;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using Quartz;
+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_ITaskInfoService;
+using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DTO;
+using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_Tasks.ConveyorLineJob;
+
+namespace WIDESEAWCS_Tasks
+{
+    [DisallowConcurrentExecution]
+    public class CommonConveyorLineJob : IJob
+    {
+        private readonly ITaskService _taskService;
+        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
+        private readonly IRouterService _routerService;
+        private readonly IMapper _mapper;
+
+        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
+        {
+            _taskService = taskService;
+            _taskExecuteDetailService = taskExecuteDetailService;
+            _routerService = routerService;
+            _mapper = mapper;
+        }
+
+        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)
+                            {
+                                DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.InteractiveSignal.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal));
+                                if (deviceProtocolDetail != null)
+                                {
+                                    MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType);
+                                    if (method != null)
+                                    {
+                                        method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode });
+                                    }
+                                    else
+                                    {
+                                        //todo 鏈壘鍒版柟娉曟椂
+                                    }
+                                }
+                            }
+                        
+                    }
+
+                    Task.WaitAll(tasks.ToArray());
+                }
+
+            }
+            catch (Exception ex)
+            {
+                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