From 208a9afadac81484fa150c0a236618facab93c52 Mon Sep 17 00:00:00 2001
From: duyongjia <adu_555@163.com>
Date: 星期一, 02 十二月 2024 11:17:39 +0800
Subject: [PATCH] 最新修改上传

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  439 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 303 insertions(+), 136 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 1f79946..0b7f0c0 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,81 +1,343 @@
-锘縰sing Microsoft.AspNetCore.Components.Routing;
+锘縰sing HslCommunication;
+using Microsoft.AspNetCore.Components.Routing;
+using Newtonsoft.Json;
 using Quartz;
 using System;
 using System.Collections.Generic;
 using System.Diagnostics.CodeAnalysis;
 using System.Linq;
+using System.Reflection.Metadata;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
+using WIDESEAWCS_Common.LocationEnum;
+using WIDESEAWCS_Common.ServiceLog;
 using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Communicator;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_DTO.TaskInfo;
+using WIDESEAWCS_IBasicRepository;
 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_QuartzJob.StackerCrane;
 using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+using WIDESEAWCS_TaskInfoService;
 using WIDESEAWCS_Tasks.StackerCraneJob;
 
 namespace WIDESEAWCS_Tasks
 {
     [DisallowConcurrentExecution]
-    public class CommonStackerCraneJob : IJob
+    public class CommonStackerCraneJob : JobBase, IJob
     {
         private readonly ITaskService _taskService;
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
         private readonly ITaskRepository _taskRepository;
         private readonly IRouterService _routerService;
+        private readonly ILocationInfoRepository _locationInfoRepository;
 
-        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService)
+        public CommonStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService,  ILocationInfoRepository locationInfoRepository)
         {
             _taskService = taskService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskRepository = taskRepository;
             _routerService = routerService;
+            _locationInfoRepository = locationInfoRepository;
         }
 
         public Task Execute(IJobExecutionContext context)
         {
+            //WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", "寮�濮嬫椂闂�" + DateTime.Now);
+            Console.WriteLine("褰撳墠绾跨▼鏁�"+ThreadPool.ThreadCount); 
+             //CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
+             CommonStackerCrane commonStackerCrane = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "SC01") as CommonStackerCrane;
             try
-            {
-                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
+            {  
                 if (commonStackerCrane != null)
                 {
-                    if (!commonStackerCrane.IsEventSubscribed)
-                    {
-                        commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢
-                    }
+                   WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", $"澶у爢鍨涙満浠诲姟鎵ц涓�...");
+                    //if (!commonStackerCrane.IsEventSubscribed)
+                    //{
+                    //    commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//璁㈤槄浠诲姟瀹屾垚浜嬩欢
+                    //}
 
                     if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                     {
                         commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆�
-
+                        
                         if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                         {
                             Dt_Task? task = GetTask(commonStackerCrane);
                             if (task != null)
                             {
+                                
+                                WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", $"澶у爢鍨涙満浠诲姟鍙穥task.TaskNum}");
                                 StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                                 if (stackerCraneTaskCommand != null)
                                 {
                                     bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                     if (sendFlag)
                                     {
-                                        commonStackerCrane.LastTaskType = task.TaskType;
-                                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
+                                      
+                                        if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
+                                        {
+                                            _taskService.UpdateTaskStatus(task.TaskId, (int)TaskInStatusEnum.SC_InExecuting);
+                                            _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"鍫嗗灈鏈哄叆搴撴墽琛屼腑");
+                                        }
+                                        else if(task.TaskType == (int)TaskOutboundTypeEnum.OutInventory|| task.TaskType == (int)TaskOutboundTypeEnum.OutPick|| task.TaskType == (int)TaskRelocationTypeEnum.Relocation)
+                                        {
+                                            _taskService.UpdateTaskStatus(task.TaskId, (int)TaskOutStatusEnum.SC_OutExecuting);
+                                            _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"鍫嗗灈鏈哄嚭搴撴墽琛屼腑");
+                                        }
+
+                                        //绌鸿溅鍑哄簱鍛戒护鍙戦�佹垚鍔熷悗锛屽洖浼� status=1锛�
+                                        if (task.TaskType == (int)TaskOutboundTypeEnum.OutPick)
+                                        {
+                                            Dt_LocationInfo srcLocation = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
+                                            srcLocation.LocationStatus = (int)LocationStatusEnum.Free;
+                                            _locationInfoRepository.UpdateData(srcLocation);
+                                            MESSendCMD sendcmd = new MESSendCMD { cmd = 201, task_id = task.TaskNum, status = 1 };
+                                            MESResponse res = ApiInvoke.SendTaskCMD(sendcmd);
+                                            WriteDebug(nameof(CommonStackerCraneJob), $"鍫嗗灈鏈哄洖浼燬tatus:1,鐢ㄤ簬鐢熸垚鍑哄簱浠诲姟,浠诲姟鍙穥task.TaskNum}");
+                                        }
+                                    }
+                                    else
+                                    {
+                                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, "鍫嗗灈鏈烘墽琛屼换鍔″懡浠ゅけ璐ワ紒");
+                                        WriteDebug(nameof(CommonStackerCraneJob), "鍫嗗灈鏈烘墽琛屼换鍔″懡浠ゅけ璐ワ紒");
                                     }
                                 }
                             }
                         }
                     }
                 }
+                else
+                {
+                    WriteDebug(nameof(DoubleStackerCraneJob), "鏈煡璇㈠埌褰撳墠鍙互鎵ц涓婃枡浠诲姟鐨勫ぇ鍫嗗灈鏈猴紒");
+                }
             }
             catch (Exception ex)
             {
-                Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
+                WriteError(nameof(CommonStackerCraneJob), "澶у爢鍨涙満鎵ц浠诲姟寮傚父锛�",ex);
             }
+
+
+
+            //Task.Run(delegate
+            //{
+            try
+            {
+                if (commonStackerCrane != null)
+                {
+                    //璇诲彇澶у爢鍨涙満浠诲姟鍙峰拰浠诲姟瀹屾垚纭鐘舵�侊紙鍥犱负灏佽鐨勪簨浠剁粡甯镐笉瑙﹀彂锛屾墍浠ュ姞涓洿鎺ヨ鐨勯�昏緫锛屼互鍏嶅嚭鐜板爢鍨涙満涓�鐩存帴澶勪簬绛夊緟wcs纭锛�
+                    byte IsOver = commonStackerCrane.Communicator.Read<byte>("DB106.22");
+                    int tasknum = commonStackerCrane.Communicator.Read<int>("DB106.18");
+                    //WriteDebug(nameof(CommonStackerCraneJob), $"璇诲彇澶у爢鍨涙満SC01浠诲姟瀹屾垚淇″彿鍊�:{IsOver} 浠诲姟鍙凤細{tasknum}");
+                    if (IsOver == 6)
+                    {
+                        if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5)
+                        {
+                            _taskService.StackCraneTaskCompleted(tasknum);
+                            Console.Out.WriteLine("TaskCompleted" + tasknum);
+                            bool issuccess = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+                            if (issuccess)
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満SC01浠诲姟鍙峰啓鍏ヤ换鍔″畬鎴愮‘璁ゅ��5鎴愬姛{tasknum}");
+                            }
+                            else
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"澶у爢鍨涙満SC01浠诲姟鍙峰啓鍏ヤ换鍔″畬鎴愮‘璁ゅ��5澶辫触{tasknum}");
+                            }
+
+                        }
+                    }
+
+                    //鎻愬崌鏈轰氦浜�
+                    Dt_Task? task1001 = _taskService.QueryStackerCraneTaskByAGVRequest("SC01");
+                    if (task1001 != null)
+                    {
+                        //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鍙互杩涘叆
+                        int IsAllow = 0;
+                        if (task1001.SourceAddress == "SC01-002-000-001")//WMS 1001绔欑偣
+                        {
+                            IsAllow = commonStackerCrane.Communicator.Read<short>("DB2.0.0");
+                        }
+                        else if (task1001.SourceAddress == "SC01-002-000-002")//WMS 1002绔欑偣
+                        {
+                            IsAllow = commonStackerCrane.Communicator.Read<short>("DB2.8.0");
+                        }
+                        if (IsAllow == 1)//濡傛灉涓�1锛屽垯鍏佽AGV杩涘叆锛屽洖浼燱MS
+                        {
+                            MESSendCMD sendcmd = new MESSendCMD { cmd = 2001, task_id = task1001.TaskNum, status = 6 };
+                            MESResponse res = ApiInvoke.SendTaskCMD(sendcmd);
+                            if (res != null && res.code != 0)
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"鍏佽AGV杩涘叆鎻愬崌鏈猴紝鍥炰紶WMS澶辫触锛佷换鍔″彿{task1001.TaskNum}");
+                            }
+                            else
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"鍏佽AGV杩涘叆鎻愬崌鏈猴紝鍥炰紶WMS鎴愬姛锛佷换鍔″彿{task1001.TaskNum}");
+                            }
+                        }
+                        else
+                        {
+                            WriteDebug(nameof(CommonStackerCraneJob), $"鏈鍙栧埌鎻愬崌鏈哄厑璁¤繘鍏ヤ俊鍙凤紝鏆備笉鍏佽AGV杩涘叆鎻愬崌鏈猴紝浠诲姟鍙穥task1001.TaskNum}");
+                        }
+                    }
+                    Dt_Task? task3001 = _taskService.QueryStackerCraneTaskByAGVPutFinish("SC01");
+                    if (task3001 != null)
+                    {
+                        int IsFinish = 0;
+                        int IsWriteOne = 0;
+                        int IsWriteTwo = 0;
+                        if (task3001.SourceAddress == "SC01-002-000-001")//WMS 1001绔欑偣
+                        {
+                            //鎻愬崌鏈烘槸鍚﹀浜庡氨缁姸鎬�
+                          
+                            int IsReady = commonStackerCrane.Communicator.Read<short>("DB2.0.0");
+                            WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈虹姸鎬侊細{IsReady}浠诲姟鍙凤細{task3001.TaskNum}");
+                            //鍐欏叆鎻愬崌淇℃伅
+                            IsWriteOne = commonStackerCrane.Communicator.Read<short>("DB1.0.0");
+                            if (IsWriteOne == 0 && IsReady == 1)
+                            {
+                                commonStackerCrane.Communicator.Write<short>("DB1.0.0", 1);
+                            }
+                            else
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"鏈啓鍏ユ彁鍗囦俊鍙凤紝鍙兘鏄凡鍐欏叆鎴栬�呮彁鍗囨満鏈鐞嗗氨缁姸鎬�,浠诲姟鍙凤細{task3001.TaskNum}");
+                            }
+                            //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚
+
+                            IsFinish = commonStackerCrane.Communicator.Read<short>("DB2.2.0");
+                        }
+                        else if (task3001.SourceAddress == "SC01-002-000-002")//WMS 1002绔欑偣
+                        {
+                            //鎻愬崌鏈烘槸鍚﹀浜庡氨缁姸鎬�
+                         
+                            int IsReady = commonStackerCrane.Communicator.Read<short>("DB2.0.0");
+                            WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈虹姸鎬侊細{IsReady}浠诲姟鍙凤細{task3001.TaskNum}");
+                            //鍐欏叆鎻愬崌淇℃伅
+                            IsWriteTwo = commonStackerCrane.Communicator.Read<short>("DB1.6.0");
+                            if (IsWriteTwo == 0 && IsReady == 1)
+                            {
+                                commonStackerCrane.Communicator.Write<short>("DB1.6.0", 1);
+                            }
+                            else
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"鏈啓鍏ユ彁鍗囦俊鍙凤紝鍙兘鏄俊鍙峰凡鍐欏叆鎴栬�呮彁鍗囨満鏈鐞嗗氨缁姸鎬侊紝浠诲姟鍙凤細{task3001.TaskNum}");
+                            }
+                            //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚
+                            IsFinish = commonStackerCrane.Communicator.Read<short>("DB2.10.0");
+                        }
+                        if (IsFinish == 1)//濡傛灉涓�1锛屽垯琛ㄧず鎻愬崌瀹屾垚锛屽洖浼燱MS
+                        {
+                            MESSendCMD sendcmd = new MESSendCMD { cmd = 2002, task_id = task3001.TaskNum, status = 6 };
+                            MESResponse res = ApiInvoke.SendTaskCMD(sendcmd);
+                            string inparam = JsonConvert.SerializeObject(sendcmd);
+                            WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS,鍏ュ弬锛歿inparam}");
+
+                            if (res != null && res.code != 0)
+                            {
+                                WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS澶辫触锛佷换鍔″彿{task3001.TaskNum}");
+                            }
+                        }
+                        else
+                        {
+                            WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囦腑...锛屼换鍔″彿锛歿task3001.TaskNum}");
+                        }
+                    }
+
+                    //灏忓爢鍨涙満鍑哄簱瀹屾垚浠诲姟
+                    Dt_Task? taskSmall = _taskService.QueryStackerCraneFinishTask();
+                    if (taskSmall != null)
+                    {
+                        //鏍规嵁浠诲姟婧愬湴鍧�纭畾鍐欏叆PLC浣嶇疆 Depth
+                        Dt_LocationInfo location = _locationInfoRepository.QueryFirst(x => x.LocationCode == taskSmall.SourceAddress);
+                        if (location != null)
+                        {
+                            string[] Levels = taskSmall.Remark.Split("-");
+                            if (Levels.Length == 2)
+                            {
+                                if (!string.IsNullOrEmpty(Levels[0]) && !string.IsNullOrEmpty(Levels[1]))
+                                {
+                                    int level = Convert.ToInt16(Levels[0]) - Convert.ToInt16(Levels[1]);
+
+                                    //鍓╀綑灞傛暟鍐欏叆
+                                    bool issuccess = commonStackerCrane.Communicator.Write<short>("DB28." + location.Depth + ".0", Convert.ToInt16(level));
+                                    WriteDebug(nameof(CommonStackerCraneJob), $"鍓╀綑灞傛暟淇″彿鍐欏叆{level}-浠诲姟鍙穥taskSmall.TaskNum}");
+
+
+                                    //濡傛灉褰撳墠鎻愬彇灞傛暟绛変簬鎬诲眰鏁帮紝鍒欒〃绀烘枡杞︽墍鏈夌殑灞傛暟鍙栧畬
+                                    if (level == 0)
+                                    {
+                                        //婧愬湴鍧�锛堟殏瀛樹綅锛夊搴旂殑鐩爣鍦板潃锛堢粍绔嬫満锛塴ocation.Remark 
+                                        if (!string.IsNullOrEmpty(location.Remark))
+                                        {
+                                            //鏍规嵁鐩爣鍦板潃鏌ヨ缁勭珛鏈虹珯鐐逛俊鎭紝鑾峰彇鍐欏叆鏁磋溅瀹屾垚鐨凞B鍧� Depth
+                                            Dt_LocationInfo location2 = _locationInfoRepository.QueryFirst(x => x.LocationCode == location.Remark);
+                                            //鏁磋溅瀹屾垚鍐欏叆灞傛暟
+                                            int sn = 0;
+                                            if (taskSmall.SourceAddress == "SC01-001-006-001" || taskSmall.SourceAddress == "SC01-001-012-001" || taskSmall.SourceAddress == "SC01-001-018-001" || taskSmall.SourceAddress == "SC01-001-022-001" || taskSmall.SourceAddress == "SC01-001-026-001")
+                                            {
+                                                sn = 1;
+                                            }
+                                            else if (taskSmall.SourceAddress == "SC01-001-007-001" || taskSmall.SourceAddress == "SC01-001-013-001" || taskSmall.SourceAddress == "SC01-001-019-001" || taskSmall.SourceAddress == "SC01-001-023-001" || taskSmall.SourceAddress == "SC01-001-027-001")
+                                            {
+                                                sn = 2;
+                                            }
+                                            else
+                                            {
+                                                sn = 3;
+                                            }
+                                            bool issuccess2 = commonStackerCrane.Communicator.Write<short>("DB28." + location2.Depth + ".0", Convert.ToInt16(sn));
+                                            if (issuccess2 && issuccess)
+                                            {
+                                                _taskService.UpdateTaskStatus(taskSmall.TaskId, (int)TaskOutStatusEnum.OutFinish);
+                                                _taskExecuteDetailService.AddTaskExecuteDetail(taskSmall.TaskId, $"鍑哄簱浠诲姟瀹屾垚");
+                                            }
+                                            else
+                                            {
+                                                WriteDebug(nameof(CommonStackerCraneJob), $"鏁磋溅瀹屾垚淇″彿鍐欏叆澶辫触锛佷换鍔″彿{taskSmall.TaskNum}");
+                                            }
+                                        }
+
+                                    }
+                                    else
+                                    {
+
+                                        if (issuccess)
+                                        {
+                                            _taskService.UpdateTaskStatus(taskSmall.TaskId, (int)TaskOutStatusEnum.OutFinish);
+                                            _taskExecuteDetailService.AddTaskExecuteDetail(taskSmall.TaskId, $"鍑哄簱浠诲姟瀹屾垚");
+                                        }
+                                        else
+                                        {
+                                            WriteDebug(nameof(CommonStackerCraneJob), $"鍓╀綑灞傛暟淇″彿鍐欏叆澶辫触锛佷换鍔″彿{taskSmall.TaskNum}");
+                                        }
+                                    }
+
+                                }
+                            }
+                        }
+
+                    }
+
+
+
+                }
+            }
+            catch (Exception ex)
+            {
+                WriteError(nameof(CommonStackerCraneJob), "鏌ヨ鎴栧啓鍏LC鐘舵�佸け璐ワ紒", ex);
+            }
+           // WriteDebug("澶у爢鍨涙満杩愯鏃ュ織", "缁撴潫鏃堕棿" + DateTime.Now);
+            //});
             return Task.CompletedTask;
         }
 
@@ -93,7 +355,11 @@
                 {
                     Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                     _taskService.StackCraneTaskCompleted(e.TaskNum);
-                    commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+                    bool issuccess=commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
+                    if (issuccess)
+                    {
+                        WriteDebug(nameof(CommonStackerCraneJob), $"浠诲姟鍙峰啓鍏ヤ换鍔″畬鎴愮‘璁ゅ��5鎴愬姛{e.TaskNum}");
+                    }
                 }
             }
         }
@@ -106,47 +372,7 @@
         private Dt_Task? GetTask(CommonStackerCrane commonStackerCrane)
         {
             Dt_Task task;
-            if (commonStackerCrane.LastTaskType == null)
-            {
-                task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
-            }
-            else
-            {
-                if (commonStackerCrane.LastTaskType.GetValueOrDefault().GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-                {
-                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
-                    if (task == null)
-                    {
-                        task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
-                    }
-                }
-                else
-                {
-                    task = _taskService.QueryStackerCraneOutTask(commonStackerCrane.DeviceCode);
-                }
-            }
-
-            if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-            {
-                if (OutTaskStationIsOccupied(task) != null)
-                {
-                    return task;
-                }
-                else
-                {
-                    List<string> otherOutStaionCodes = _routerService.QueryNextRoutes(commonStackerCrane.DeviceCode, task.NextAddress).Select(x => x.ChildPosi).ToList();
-                    List<Dt_Task> tasks = _taskService.QueryStackerCraneOutTasks(commonStackerCrane.DeviceCode, otherOutStaionCodes);
-                    foreach (var item in tasks)
-                    {
-                        if (OutTaskStationIsOccupied(task) != null)
-                        {
-                            return task;
-                        }
-                    }
-                    task = _taskService.QueryStackerCraneInTask(commonStackerCrane.DeviceCode);
-                }
-            }
-
+            task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
             return task;
         }
 
@@ -195,94 +421,35 @@
             stackerCraneTaskCommand.TaskNum = task.TaskNum;
             stackerCraneTaskCommand.WorkType = 1;
             stackerCraneTaskCommand.TrayType = 0;
-            if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//鍒ゆ柇鏄惁鏄叆搴撲换鍔�
+            string[] SourceCodes = task.SourceAddress.Split("-");
+            if (SourceCodes.Length == 4)
             {
-                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.Roadway);
-                if (routers.Count > 0)
-                {
-                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
-                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
-                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
-
-                    string[] targetCodes = task.NextAddress.Split("-");
-                    if (targetCodes.Length == 3)
-                    {
-                        stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
-                        stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
-                        stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
-                    }
-                    else
-                    {
-                        //鏁版嵁閰嶇疆閿欒
-                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍏ュ簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�");
-                        return null;
-                    }
-                }
-                else
-                {
-                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鍙栬揣绔欏彴淇℃伅");
-                    return null;
-                }
+                stackerCraneTaskCommand.StartRow = Convert.ToInt16(SourceCodes[1]);
+                stackerCraneTaskCommand.StartColumn = Convert.ToInt16(SourceCodes[2]);
+                stackerCraneTaskCommand.StartLayer = Convert.ToInt16(SourceCodes[3]);
             }
-            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+            else
             {
-                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.Roadway, task.TargetAddress);
-                if (routers.Count > 0)
-                {
-                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(routers.FirstOrDefault().SrmRow);
-                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(routers.FirstOrDefault().SrmColumn);
-                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(routers.FirstOrDefault().SrmLayer);
-
-                    string[] sourceCodes = task.CurrentAddress.Split("-");
-                    if (sourceCodes.Length == 3)
-                    {
-                        stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
-                        stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
-                        stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
-                    }
-                    else
-                    {
-                        //鏁版嵁閰嶇疆閿欒
-                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鍑哄簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
-                        return null;
-                    }
-                }
-                else
-                {
-                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"鏈壘鍒扮珯鍙般�恵task.NextAddress}銆戜俊鎭紝鏃犳硶鑾峰彇瀵瑰簲鐨勫爢鍨涙満鏀捐揣绔欏彴淇℃伅");
-                    return null;
-                }
+                //鏁版嵁閰嶇疆閿欒
+                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"浠诲姟婧愬湴鍧�閰嶇疆閿欒锛�");
+                return null;
             }
-            else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
+            string[] targetCodes = task.TargetAddress.Split("-");
+            if (targetCodes.Length == 4)
             {
-                string[] targetCodes = task.NextAddress.Split("-");
-                if (targetCodes.Length == 3)
-                {
-                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[0]);
-                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[1]);
-                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[2]);
-                }
-                else
-                {
-                    //鏁版嵁閰嶇疆閿欒
-                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟缁堢偣閿欒锛岃捣鐐癸細銆恵task.NextAddress}銆�");
-                    return null;
-                }
-                string[] sourceCodes = task.CurrentAddress.Split("-");
-                if (sourceCodes.Length == 3)
-                {
-                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(sourceCodes[0]);
-                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
-                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
-                }
-                else
-                {
-                    //鏁版嵁閰嶇疆閿欒
-                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"绉诲簱浠诲姟璧风偣閿欒锛岃捣鐐癸細銆恵task.CurrentAddress}銆�");
-                    return null;
-                }
+                stackerCraneTaskCommand.EndRow = Convert.ToInt16(targetCodes[1]);
+                stackerCraneTaskCommand.EndColumn = Convert.ToInt16(targetCodes[2]);
+                stackerCraneTaskCommand.EndLayer = Convert.ToInt16(targetCodes[3]);
+            }
+            else
+            {
+                //鏁版嵁閰嶇疆閿欒
+                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"浠诲姟鐩爣鍦板潃閰嶇疆閿欒");
+                return null;
             }
             return stackerCraneTaskCommand;
         }
+
+
     }
 }

--
Gitblit v1.9.3