From d100db102ded4dc2047f1b92f4ed0ed4c18d8ee4 Mon Sep 17 00:00:00 2001
From: Huangxiaoqiang-03 <1247017146@qq.com>
Date: 星期一, 11 十一月 2024 13:56:48 +0800
Subject: [PATCH] 1

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  104 +++++++++++++++++++++++----------------------------
 1 files changed, 47 insertions(+), 57 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
index 46b03de..e050312 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs"
@@ -1,4 +1,6 @@
-锘縰sing Microsoft.AspNetCore.Components.Routing;
+锘縰sing HslCommunication;
+using Microsoft.AspNetCore.Components.Routing;
+using Newtonsoft.Json;
 using Quartz;
 using SqlSugar.Extensions;
 using System;
@@ -6,14 +8,18 @@
 using System.Diagnostics.CodeAnalysis;
 using System.Linq;
 using System.Net;
+using System.Reflection.Metadata;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.Log;
+using WIDESEA_Core.Enums;
 using WIDESEAWCS_Core.Enums;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DeviceBase;
+using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
 using WIDESEAWCS_Tasks.StackerCraneJob;
@@ -41,31 +47,30 @@
             try
             {
                 SpeStackerCrane speStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
-                GetStackerObject getStackerObject = new GetStackerObject();
+                GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
                 if (speStackerCrane != null)
                 {
-                    if (getStackerObject.StackerCraneTaskCompletedValue(speStackerCrane) == StackerCraneTaskCompleted.WorkCompleted)
+                    if (!getStackerObject.IsEventSubscribed)
                     {
-                        Console.WriteLine(1);
+                        getStackerObject.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢
                     }
-                    else
+                    if (getStackerObject.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && getStackerObject.StackerCraneStatusValue == StackerCraneStatus.Ready)
                     {
-                        if (getStackerObject.StackerCraneAutoStatusValue(speStackerCrane) == StackerCraneAutoStatus.Automatic && getStackerObject.StackerCraneStatusValue(speStackerCrane) == StackerCraneStatus.Ready)
+                        getStackerObject.CheckStackerCraneTaskCompleted();//妫�娴嬪畬鎴愪簨浠�
+
+                        if(getStackerObject.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                         {
-                            if (getStackerObject.StackerCraneWorkStatusValue(speStackerCrane) == StackerCraneWorkStatus.Standby)
+                            Dt_Task? task = GetTask(speStackerCrane);
+                            if (task != null)
                             {
-                                Dt_Task? task = GetTask(speStackerCrane);
-                                if (task != null)
+                                StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
+                                if (stackerCraneTaskCommand != null)
                                 {
-                                    StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
-                                    if (stackerCraneTaskCommand != null)
+                                    bool sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand);
+                                    if (sendFlag)
                                     {
-                                        bool sendFlag = speStackerCrane.SendCommand(stackerCraneTaskCommand);
-                                        if (sendFlag)
-                                        {
-                                            speStackerCrane.LastTaskType = task.TaskType;
-                                            _taskService.UpdateTaskStatusToNext(task.TaskNum);
-                                        }
+                                        speStackerCrane.LastTaskType = task.TaskType;
+                                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
                                     }
                                 }
                             }
@@ -75,7 +80,7 @@
             }
             catch (Exception ex)
             {
-                Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
+                WriteLog.GetLog($"鍫嗗灈鏈哄紓甯�").Write($"{nameof(CommonStackerCraneJob)}:{ex.Message}", "鍫嗗灈鏈哄紓甯�");
             }
             return Task.CompletedTask;
         }
@@ -106,15 +111,15 @@
         /// <returns></returns>
         private Dt_Task? GetTask(SpeStackerCrane speStackerCrane)
         {
-            Dt_Task task;
+            Dt_Task? task;
             if (speStackerCrane.LastTaskType == null)
             {
                 task = _taskService.QueryStackerCraneTask(speStackerCrane.DeviceCode);
             }
             else
             {
-                bool flag = speStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup;
-                if (flag)
+                bool flag = speStackerCrane.LastTaskType == TaskTypeEnum.Inbound.ObjToInt() || speStackerCrane.LastTaskType == TaskTypeEnum.PalletInbound.ObjToInt();
+                if (flag == false)
                 {
                     task = _taskService.QueryStackerCraneInTask(speStackerCrane.DeviceCode);
                     if (task == null)
@@ -127,19 +132,6 @@
                     task = _taskService.QueryStackerCraneOutTask(speStackerCrane.DeviceCode);
                 }
             }
-
-            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-            {
-
-                List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(speStackerCrane.DeviceCode, task.TargetAddress);
-                foreach (var item in tasks)
-                {
-                    return task;
-                }
-                return task;
-
-            }
-
             return task;
         }
 
@@ -173,7 +165,6 @@
             }
             return null;
         }
-
         /// <summary>
         /// 浠诲姟瀹炰綋杞崲鎴愬懡浠odel
         /// </summary>
@@ -188,16 +179,16 @@
             stackerCraneTaskCommand.TaskNum = task.TaskNum;
             stackerCraneTaskCommand.WorkType = 1;
             stackerCraneTaskCommand.TrayType = 0;
-            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
+            if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
             {
                 if (task.SourceAddress != null && task.TargetAddress != null)
                 {
                     string[] sourceCodes = task.SourceAddress.Split("-");
                     if (sourceCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
-                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
-                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
+                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
+                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
+                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                     }
                     else
                     {
@@ -208,9 +199,9 @@
                     string[] targetCodes = task.TargetAddress.Split("-");
                     if (targetCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
-                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
-                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
+                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
+                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
+                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                     }
                     else
                     {
@@ -225,16 +216,16 @@
                     return null;
                 }
             }
-            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+            else if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt())
             {
                 if (task.SourceAddress != null && task.TargetAddress != null)
                 {
                     string[] targetCodes = task.TargetAddress.Split("-");
                     if (targetCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
-                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
-                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
+                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
+                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
+                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                     }
                     else
                     {
@@ -245,9 +236,9 @@
                     string[] sourceCodes = task.SourceAddress.Split("-");
                     if (sourceCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
-                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
-                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
+                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
+                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
+                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                     }
                     else
                     {
@@ -262,16 +253,16 @@
                     return null;
                 }
             }
-            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
+            else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt())
             {
                 if (task.SourceAddress != null && task.TargetAddress != null)
                 {
                     string[] targetCodes = task.TargetAddress.Split("-");
                     if (targetCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
-                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
-                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
+                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
+                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
+                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
                     }
                     else
                     {
@@ -282,9 +273,9 @@
                     string[] sourceCodes = task.SourceAddress.Split("-");
                     if (sourceCodes.Length == 3)
                     {
-                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
-                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
-                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
+                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[1]);
+                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[2]);
+                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[3]);
                     }
                     else
                     {
@@ -300,6 +291,5 @@
             }
             return stackerCraneTaskCommand;
         }
-
     }
 }

--
Gitblit v1.9.3