From 36230cd4dd0ebe5d21eede3eff6216908f7f7a8e Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期三, 06 十一月 2024 16:48:32 +0800
Subject: [PATCH] AGV任务下发,AGV任务状态更新

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs |  150 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 92 insertions(+), 58 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
index 67bdf60..3ea01ce 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs"
@@ -24,11 +24,15 @@
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Common.ConveyorLineEnum;
+using WIDESEAWCS_Common.TaskEnum;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_DTO.WMSInfo;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.ConveyorLine.Enum;
 using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_Tasks.ConveyorLineJob;
@@ -36,7 +40,7 @@
 namespace WIDESEAWCS_Tasks
 {
     [DisallowConcurrentExecution]
-    public class CommonConveyorLineJob : IJob
+    public class CommonConveyorLineJob : JobBase, IJob
     {
         private readonly ITaskService _taskService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
@@ -53,7 +57,6 @@
 
         public Task Execute(IJobExecutionContext context)
         {
-            Console.Out.WriteLine(DateTime.Now);
             try
             {
                 CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
@@ -63,32 +66,32 @@
                     List<Task> tasks = new List<Task>();
                     foreach (string childDeviceCode in childDeviceCodes)
                     {
-                        //Task task = Task.Run(() =>
-                        //{
-                            ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode);
-                            if (command != null)
+                        ConveyorLineTaskCommandR command = conveyorLine.ReadCustomer<ConveyorLineTaskCommandR>(childDeviceCode);
+                        if (command != null && command.Status == (ushort)ConveyorStatus.Stored)//娣诲姞杈撻�佺嚎鐘舵�丆onveyorLineStatus enum
+                        {
+                            switch (childDeviceCode)
                             {
-                                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 鏈壘鍒版柟娉曟椂
-                                    }
-                                }
+                                case "102":
+                                    RequestInbound(conveyorLine, command, childDeviceCode);
+                                    break;
+                                case "104":
+                                    ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
+                                    break;
+                                //case "105":
+                                //    RequestOutbound(conveyorLine, command, childDeviceCode);
+                                //    break;
+                                case "108":
+                                    ConveyorLineOutFinish(conveyorLine, command, childDeviceCode);
+                                    break;
+                                    //default:
+                                    //    RequestInNextAddress(conveyorLine, command, childDeviceCode);
+                                    //    RequestOutNextAddress(conveyorLine, command, childDeviceCode);
+                                    //    break;
                             }
-                        //});
-                        //tasks.Add(task);
+                        }
                     }
-
                     Task.WaitAll(tasks.ToArray());
                 }
-
             }
             catch (Exception ex)
             {
@@ -96,7 +99,7 @@
             }
             finally
             {
-                Console.Out.WriteLine(DateTime.Now);
+                //Console.Out.WriteLine(DateTime.Now);
             }
             return Task.CompletedTask;
         }
@@ -107,18 +110,41 @@
         /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
         /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
-        public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command,string childDeviceCode)
+        public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
         {
-            if (_taskService.RequestWMSTask(command.Barcode, childDeviceCode).Status)
+            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.Barcode);
+            if (task != null)
             {
-                Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
-                if (task != null)
+                ConveyorLineDTO lineDTO = new ConveyorLineDTO()
                 {
-                    ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
-                    taskCommand.InteractiveSignal = command.InteractiveSignal;
-                    conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                    //TaskNum = task.TaskNum,
+                    stationCode = childDeviceCode,
+                    Barcode = command.Barcode,
+                    Spec = command.Spec,
+                    Weight = command.Weight,
+                };
+                var content = _taskService.RequestWMSTask(lineDTO);
 
-                    _taskService.UpdateTaskStatusToNext(task);
+                if (content.Status)
+                {
+                    task.TargetAddress = AppSettings.Configuration["OKAddress"];
+                    task.NextAddress = task.TargetAddress;
+                    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
+
+                    if (conveyorLine.SendCommand(taskCommand, childDeviceCode))
+                        _taskService.UpdateTaskStatusToNext(task);
+                }
+                else
+                {
+                    if (content.Code == 404)//淇敼缁堢偣鍦板潃
+                    {
+                        task.TargetAddress = AppSettings.Configuration["NGAddress"];
+                        task.NextAddress = task.TargetAddress;
+                        task.ExceptionMessage = content.Message;
+                        task.TaskState = (int)TaskInStatusEnum.InException;
+                        ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
+                        if (conveyorLine.SendCommand(taskCommand, childDeviceCode)) _taskService.UpdateData(task);
+                    }
                 }
             }
         }
@@ -129,18 +155,18 @@
         /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
         /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
-        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR 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);
-                }
+                //if (newTask != null)
+                //{
+                //    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(newTask);
+
+                //    conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                //}
             }
         }
 
@@ -150,15 +176,23 @@
         /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
         /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
-        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
         {
             Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
-            if (task != null)
+            if (task != null) _taskService.UpdateTaskStatusToNext(task);
+
+            task = _taskService.QueryCompletedConveyorLineTask(command.TaskNum, childDeviceCode);
+            if (task != null && string.IsNullOrEmpty(task.TargetAddress))
             {
-                conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
-                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
-                Console.Out.WriteLine(content.Serialize());
+                _taskService.StackerCraneRequestInbound(task);
             }
+            //if (task != null)
+            //{
+            //    //conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
+            //    //鍚慦MS鏇存柊浠诲姟鐘舵�侊紝WMS杩斿洖鍏ュ簱浠诲姟缁堢偣
+            //    WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
+            //    //Console.Out.WriteLine(content.Serialize());
+            //}
         }
 
         /// <summary>
@@ -167,13 +201,13 @@
         /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
         /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
-        public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
         {
-            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode);
+            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.Barcode);
             if (task != null)
             {
-                ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(task);
-                taskCommand.InteractiveSignal = command.InteractiveSignal;
+                ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
+
                 conveyorLine.SendCommand(taskCommand, childDeviceCode);
 
                 _taskService.UpdateTaskStatusToNext(task);
@@ -186,18 +220,18 @@
         /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
         /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
-        public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR 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);
-                }
+                //if (newTask != null)
+                //{
+                //    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(newTask);
+
+                //    conveyorLine.SendCommand(taskCommand, childDeviceCode);
+                //}
             }
         }
 
@@ -207,14 +241,14 @@
         /// <param name="conveyorLine">杈撻�佺嚎瀹炰緥瀵硅薄</param>
         /// <param name="command">璇诲彇鐨勮姹備俊鎭�</param>
         /// <param name="childDeviceCode">瀛愯澶囩紪鍙�</param>
-        public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode)
+        public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
         {
             Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
             if (task != null)
             {
-                conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
+                //conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
                 WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
-                Console.Out.WriteLine(content.Serialize());
+                //Console.Out.WriteLine(content.Serialize());
             }
         }
     }

--
Gitblit v1.9.3