From 05d580b4357829263c9c44449621ca6017576dcb Mon Sep 17 00:00:00 2001
From: duyongjia <adu_555@163.com>
Date: 星期二, 19 十一月 2024 16:26:46 +0800
Subject: [PATCH] 现场修改提交

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs |  332 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 201 insertions(+), 131 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..3e63582 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,5 @@
-锘縰sing Microsoft.AspNetCore.Components.Routing;
+锘縰sing HslCommunication;
+using Microsoft.AspNetCore.Components.Routing;
 using Quartz;
 using System;
 using System.Collections.Generic;
@@ -7,40 +8,48 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_Communicator;
 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)
         {
+            CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
             try
-            {
-                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
+            {  
                 if (commonStackerCrane != null)
                 {
                     if (!commonStackerCrane.IsEventSubscribed)
@@ -51,7 +60,7 @@
                     if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                     {
                         commonStackerCrane.CheckStackerCraneTaskCompleted();//闃叉浠诲姟瀹屾垚浜嬩欢鐩戞祴瓒呮椂锛屽啀鎵嬪姩瑙﹀彂涓�娆�
-
+                        
                         if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                         {
                             Dt_Task? task = GetTask(commonStackerCrane);
@@ -63,8 +72,22 @@
                                     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, $"鍫嗗灈鏈哄嚭搴撴墽琛屼腑");
+                                        }
+                                    }
+                                    else
+                                    {
+                                        _taskService.UpdateTaskExceptionMessage(task.TaskNum, "鍫嗗灈鏈烘墽琛屼换鍔″懡浠ゅけ璐ワ紒");
+                                        WriteDebug(nameof(CommonStackerCraneJob), "鍫嗗灈鏈烘墽琛屼换鍔″懡浠ゅけ璐ワ紒");
                                     }
                                 }
                             }
@@ -74,8 +97,154 @@
             }
             catch (Exception ex)
             {
-                Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
+                WriteError(nameof(CommonStackerCraneJob), "澶у爢鍨涙満鎵ц浠诲姟寮傚父锛�",ex);
             }
+
+
+            //鏌ヨ鎻愬崌鏈�/缁勭珛鏈轰俊鍙�
+            //Task.Run(delegate
+            //{
+                try
+                {
+                   
+                    if (commonStackerCrane != null)
+                    {
+                        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), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS澶辫触锛佷换鍔″彿{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绔欑偣
+                            {
+                                //鍐欏叆鎻愬崌淇℃伅
+                                IsWriteOne = commonStackerCrane.Communicator.Read<short>("DB1.0.0");
+                                if(IsWriteOne == 0) 
+                                {
+                                  
+                                    commonStackerCrane.Communicator.Write<short>("DB1.0.0", 1);
+                                }
+                                //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚
+                               
+                                commonStackerCrane.Communicator.Read<short>("DB2.2.0");
+                            }
+                            else if (task3001.SourceAddress == "SC01-002-000-002")//WMS 1002绔欑偣
+                            {
+                                //鍐欏叆鎻愬崌淇℃伅
+                                IsWriteTwo = commonStackerCrane.Communicator.Read<short>("DB1.6.0");
+                                if (IsWriteTwo == 0)
+                                {
+                                    commonStackerCrane.Communicator.Write<short>("DB1.6.0", 1);
+                                }    
+                                //璇诲彇鎻愬崌鏈轰俊鍙凤紝纭畾鏄惁鎻愬崌瀹屾垚
+                                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);
+                                if (res != null && res.code != 0)
+                                {
+                                    WriteDebug(nameof(CommonStackerCraneJob), $"鎻愬崌鏈烘彁鍗囧畬鎴愶紝鍥炰紶WMS澶辫触锛佷换鍔″彿{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));
+                                        //濡傛灉褰撳墠鎻愬彇灞傛暟绛変簬鎬诲眰鏁帮紝鍒欒〃绀烘枡杞︽墍鏈夌殑灞傛暟鍙栧畬
+                                        if (level == 0)
+                                        {
+                                            //婧愬湴鍧�锛堟殏瀛樹綅锛夊搴旂殑鐩爣鍦板潃锛堢粍绔嬫満锛塴ocation.Remark 
+                                            if (!string.IsNullOrEmpty(location.Remark))
+                                            {
+                                                //鏍规嵁鐩爣鍦板潃鏌ヨ缁勭珛鏈虹珯鐐逛俊鎭紝鑾峰彇鍐欏叆鏁磋溅瀹屾垚鐨凞B鍧� Depth
+                                                Dt_LocationInfo location2 = _locationInfoRepository.QueryFirst(x => x.LocationCode == location.Remark);
+                                                //鏁磋溅瀹屾垚鍐欏叆
+                                                bool issuccess2 = commonStackerCrane.Communicator.Write<short>("DB28." + location.Depth+".0", 1);
+                                                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);
+                }
+             
+
+            //});
+
+
+
             return Task.CompletedTask;
         }
 
@@ -106,47 +275,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 +324,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