From 8f392cc88b0768b74efca3b68785cf5aa1c38e70 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 06 十一月 2024 14:28:20 +0800
Subject: [PATCH] 代码更新

---
 wcs-server-hbf/WIDESEA_WCS/JobsPart/AGV/UpdateAgvTask.cs |   68 +++++++++++++++++----------------
 1 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/wcs-server-hbf/WIDESEA_WCS/JobsPart/AGV/UpdateAgvTask.cs b/wcs-server-hbf/WIDESEA_WCS/JobsPart/AGV/UpdateAgvTask.cs
index 915907c..78ce94d 100644
--- a/wcs-server-hbf/WIDESEA_WCS/JobsPart/AGV/UpdateAgvTask.cs
+++ b/wcs-server-hbf/WIDESEA_WCS/JobsPart/AGV/UpdateAgvTask.cs
@@ -14,17 +14,21 @@
 using WIDESEA_Services.Services;
 using WIDESEA_WCS.WCSClient;
 
-namespace WIDESEA_WCS.SchedulerExecute.AGV
+namespace WIDESEA_WCS.JobsPart.AGV
 {
-    public partial class AGVSchedulerExecute
+    public partial class AGVServer
     {
-        private static int _readUpdateAGVTaskSignalsotask = 0;
-        public static void UpdateAgvTask(PLCClient plcClient)
+        private static int _readUpdateAGVTaskSignalso = 0;
+        public void UpdateAgvTask(PLCClient plcClient)
         {
-            if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotask, 1) == 0)
+            if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 1) == 0)
             {
                 try
                 {
+                    if (plcClient == null)
+                    {
+                        return;
+                    }
                     VOLContext context = new VOLContext();
                     Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(context);
                     Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
@@ -43,10 +47,8 @@
                     if (1 == taskFbInteractive && taskFbInteractiveW == 0)
                     {
                         string taskId = plcClient.ReadValue(TaskDBName.taskIDFb.ToString()).ToString();//浠诲姟ID
-                        
                         if (taskId.Contains("\b")) { taskId = taskId.Remove(0, 1); }
                         int taskState = int.Parse(plcClient.ReadValue(TaskDBName.taskStatusFb.ToString()).ToString());//1璧风偣鎵ц涓�,2璧风偣宸插畬鎴�,3缁堢偣鎵ц涓�,4缁堢偣宸插畬鎴�
-                        WriteLog.GetLog().Write($"{plcClient.PLCName}寮�濮�:" + taskId + "浠诲姟鐘舵�侊細"+ taskState + "{DateTime.Now}", "AGV鏇存柊浠诲姟鐘舵�佹祴璇�");
                         if (0 == taskState)//鏃犲惈涔�
                             return;
                         WriteLog.GetLog().Write($"{plcClient.PLCName}浠诲姟鍙�" + taskId + "浠诲姟鐘舵��" + taskState + $"   {DateTime.Now}", "AGV鏇存柊浠诲姟鐘舵��");
@@ -64,7 +66,6 @@
                                 }
 
                                 #region 缂栧啓瀵瑰簲椤圭洰鐨勪笟鍔¢�昏緫
-
                                 Task task = Task.Run(() =>
                                 {
                                     if (null == agvTask)
@@ -75,6 +76,7 @@
                                         //throw new Exception("璧风偣鎵ц澶辫触鏈壘鍒颁换鍔�,ID:" + taskId);
                                     }
                                     agvTask.agv_taskstate = AGVTaskStateEnum.Executing.ToString();
+                                    agvTask.agv_realesstime = DateTime.Now;
                                     int isOk = agvtaskRepository.Update(agvTask, true);
                                     if (isOk == 0)
                                     {
@@ -128,17 +130,16 @@
                         {
                             if (agvTask != null)
                             {
-                                
+                                WriteLog.GetLog().Write($"浠诲姟鍙�:{agvTask.agv_tasknum},璧风偣鍦板潃:{agvTask.agv_fromaddress},缁堢偣鍦板潃锛歿agvTask.agv_toaddress} 鏃堕棿: {DateTime.Now}", "AGV浠诲姟鍙嶉2");
+                                if (agvTask.agv_taskstate == AGVTaskStateEnum.Complete.ToString())
+                                {
+                                    plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
+                                    WriteLog.GetLog().Write("WCS鍐嶆鍐欏叆AGV浠诲姟鍙�" + taskId + "," + DateTime.Now + "浠诲姟璧风偣瀹屾垚鐘舵�佺‘璁�1", "AGV鏇存柊浠诲姟鐘舵��");
+                                }
+
+                                #region 缂栧啓瀵瑰簲椤圭洰鐨勪笟鍔¢�昏緫
                                 Task.Run(() =>
                                 {
-                                    WriteLog.GetLog().Write($"浠诲姟鍙�:{agvTask.agv_tasknum},璧风偣鍦板潃:{agvTask.agv_fromaddress},缁堢偣鍦板潃锛歿agvTask.agv_toaddress} 鏃堕棿: {DateTime.Now}", "AGV浠诲姟鍙嶉2");
-                                    if (agvTask.agv_taskstate == AGVTaskStateEnum.Complete.ToString())
-                                    {
-                                        plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
-                                        WriteLog.GetLog().Write("WCS鍐嶆鍐欏叆AGV浠诲姟鍙�" + taskId + "," + DateTime.Now + "浠诲姟璧风偣瀹屾垚鐘舵�佺‘璁�1", "AGV鏇存柊浠诲姟鐘舵��");
-                                    }
-
-                                    #region 缂栧啓瀵瑰簲椤圭洰鐨勪笟鍔¢�昏緫
                                     if (null == agvTask)
                                     {
                                         plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
@@ -152,7 +153,7 @@
                                         agvTask.agv_taskstate = AGVTaskStateEnum.Abnormal.ToString();
                                         isOk = agvtaskRepository.Update(agvTask, true);
                                     }
-                                    if (agvTask.agv_remark.Contains("PDA搴撴埧鍙枡浠诲姟") || agvTask.agv_remark.Contains("PDA浜х嚎鍙枡浠诲姟"))
+                                    if (agvTask.agv_remark.Contains("PDA搴撴埧鍙枡浠诲姟") ||       agvTask.agv_remark.Contains("PDA浜х嚎鍙枡浠诲姟"))
                                     {
                                         base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_fromaddress);
                                         if (pda_Location == null)
@@ -161,14 +162,14 @@
                                             return;
                                         }
                                         dt_container container = containerRepository.FindFirst(d => d.container_sn == agvTask.agv_barcode && d.container_barcode == pda_Location.L_Code);
-                                        if (container != null)
+                                        if (container!=null)
                                         {
                                             containerRepository.Delete(container, true);
                                             pda_Location.L_Task = 2;
                                             pda_Location.L_state = LoctionStateEnum.LocationState_Empty.ToString();
                                             pdaloctionRepository.Update(pda_Location, true);
                                         }
-
+                               
 
                                     }
                                     else if (agvTask.agv_remark.Contains("PDA鍥炴祦浠诲姟"))
@@ -240,13 +241,13 @@
                         }
                         else if (3 == taskState)//浠诲姟缁堢偣鎵ц涓�
                         {
+
                             if (agvTask != null)
                             {
+                                WriteLog.GetLog().Write($"浠诲姟鍙�:{agvTask.agv_tasknum},璧风偣鍦板潃:{agvTask.agv_fromaddress},缁堢偣鍦板潃锛歿agvTask.agv_toaddress} 鏃堕棿: {DateTime.Now}", "AGV浠诲姟鍙嶉3");
                                 #region 缂栧啓瀵瑰簲椤圭洰鐨勪笟鍔¢�昏緫
                                 Task.Run(() =>
                                 {
-                                    WriteLog.GetLog().Write($"浠诲姟鍙�:{agvTask.agv_tasknum},璧风偣鍦板潃:{agvTask.agv_fromaddress},缁堢偣鍦板潃锛歿agvTask.agv_toaddress} 鏃堕棿: {DateTime.Now}", "AGV浠诲姟鍙嶉3");
-                                    
                                     if (agvTask.agv_taskstate == AGVTaskStateEnum.Executing1.ToString())
                                     {
                                         plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
@@ -288,7 +289,7 @@
                                             location.task = 2;
                                             location.logic_row = "0";
 
-                                            int a = locationRepository.Update(location, x => new { x.logic_col, x.task, x.logic_row, x.update_time, x.geartype }, true);
+                                            int a = locationRepository.Update(location, x => new { x.logic_col, x.task, x.logic_row, x.update_time,x.geartype }, true);
                                             if (a == 0)
                                             {
                                                 WriteLog.GetLog().Write($"浠诲姟鍙凤細{agvTask.agv_tasknum},鍐呭锛氱粓鐐瑰湴鍧�锛歿location.upper_code},璐т綅淇敼澶辫触", $"璐т綅淇敼澶辫触");
@@ -296,6 +297,8 @@
                                         }
                                     }
                                 });
+
+
                                 #endregion
 
                                 plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
@@ -340,9 +343,9 @@
                             {
                                 WriteLog.GetLog().Write($"浠诲姟鍙�:{agvTask.agv_tasknum},璧风偣鍦板潃:{agvTask.agv_fromaddress},缁堢偣鍦板潃锛歿agvTask.agv_toaddress} 鏃堕棿: {DateTime.Now}", "AGV浠诲姟鍙嶉4");
                                 #region 缂栧啓瀵瑰簲椤圭洰鐨勪笟鍔¢�昏緫
-
                                 Task.Run(() =>
                                 {
+
                                     agvTask.agv_taskstate = AGVTaskStateEnum.Complete1.ToString();
                                     int isOk = agvtaskRepository.Update(agvTask, true);
                                     if (isOk == 0)
@@ -489,17 +492,17 @@
                                         }
                                         else if (agvTask.agv_toaddress.Contains("HCJ"))
                                         {
-                                            if (location.upper_code.Contains("FJ-BCHCJ37") || location.upper_code.Contains("FJ-BCHCJ36") || location.upper_code.Contains("ZJ-BCHCJ35") || location.upper_code.Contains("ZJ-BCHCJ34"))
+                                            if (location.upper_code.Contains("FJ-BCHCJ37") || location.upper_code.Contains("FJ-BCHCJ36") ||       location.upper_code.Contains("ZJ-BCHCJ35") || location.upper_code.Contains("ZJ-BCHCJ34"))
                                             {
                                                 location.logic_row = "TSJXL-BCK";
                                                 location.logic_col = 1;
                                             }
-                                            else if (location.upper_code.Contains("FJ-BCHCJ35") || location.upper_code.Contains("FJ-BCHCJ34") || location.upper_code.Contains("ZJ-BCHCJ33") || location.upper_code.Contains("ZJ-BCHCJ32"))
+                                            else if (location.upper_code.Contains("FJ-BCHCJ35") || location.upper_code.Contains("FJ-BCHCJ34")|| location.upper_code.Contains("ZJ-BCHCJ33")|| location.upper_code.Contains("ZJ-BCHCJ32"))
                                             {
                                                 location.logic_row = "TBXL-BCK";
                                                 location.logic_col = 1;
                                             }
-                                            else if (agvTask.agv_fromaddress.Contains("FJ-BCHCJ37") || agvTask.agv_fromaddress.Contains("ZJ-BCHCJ35"))
+                                            else if (agvTask.agv_fromaddress.Contains("FJ-BCHCJ37")|| agvTask.agv_fromaddress.Contains("ZJ-BCHCJ35"))
                                             {
                                                 location.logic_row = "TSJXL-BCK";
                                                 location.logic_col = 0;
@@ -568,7 +571,7 @@
                                     else if (agvTask.agv_remark.Contains("PDA鍥炴祦浠诲姟"))
                                     {
                                         base_pda_location pda_Location = pdaloctionRepository.FindFirst(d => d.L_Code == agvTask.agv_toaddress);
-                                        if (pda_Location == null)
+                                        if (pda_Location==null)
                                         {
                                             Console.WriteLine($"寮傚父锛歅DA鍥炴祦浠诲姟缁堢偣鍦板潃涓嶄笉鍦細{agvTask.agv_toaddress}");
                                             return;
@@ -586,14 +589,14 @@
                                         containerRepository.Add(dt_Container, true);
                                         pda_Location.L_Task = 2;
                                         pda_Location.L_state = LoctionStateEnum.LocationState_Stored.ToString();
-                                        pdaloctionRepository.Update(pda_Location, d => new { d.L_state, d.L_Task }, true);
+                                        pdaloctionRepository.Update(pda_Location,d=>new {d.L_state,d.L_Task }, true);
 
 
                                     }
                                     else if (agvTask.agv_remark.Contains("閾濆3缂撳瓨鏋朵换鍔�"))
                                     {
                                         dt_stationinfo dt_Stationinfo = stationinfoRepository.FindFirst(d => d.stationCode == agvTask.agv_toaddress);
-                                        if (dt_Stationinfo == null)
+                                        if (dt_Stationinfo==null)
                                         {
                                             Console.WriteLine($"寮傚父锛氶摑澹崇紦瀛樻灦浠诲姟缁堢偣鍦板潃涓嶄笉鍦細{agvTask.agv_toaddress}");
                                             return;
@@ -820,7 +823,6 @@
                             WriteLog.GetLog().Write("WCS鍐欏叆AGV浠诲姟鍙�" + taskId + DateTime.Now + "浠诲姟寮傚父鐘舵�佺‘璁�1", "AGV鏇存柊浠诲姟鐘舵��");
                             agvtaskRepository.Delete(agvTask, true);
                         }
-                        WriteLog.GetLog().Write($"{plcClient.PLCName}缁撴潫:" + taskId + "{DateTime.Now}", "AGV鏇存柊浠诲姟鐘舵�佹祴璇�");
                     }
                     if (taskFbInteractive == 0 && taskFbInteractiveW == 1)
                     {
@@ -839,6 +841,7 @@
                             }
                         }
                     }
+
                 }
                 catch (Exception ex)
                 {
@@ -846,10 +849,9 @@
                 }
                 finally
                 {
-                    Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotask, 0);
+                    Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 0);
                 }
             }
-
         }
     }
 }

--
Gitblit v1.9.3