From 6cc35000a6e138cfad96e7b02f8aeddcdb4ba6bf Mon Sep 17 00:00:00 2001 From: wankeda <Administrator@DESKTOP-HAU3ST3> Date: 星期二, 24 六月 2025 09:57:25 +0800 Subject: [PATCH] 代码提交 --- 代码管理/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs | 157 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 134 insertions(+), 23 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" index cc58f54..afd92de 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" @@ -1,10 +1,12 @@ -锘縰sing WIDESEAWCS_Common.AGVEnum; +锘縰sing System.Threading.Tasks; +using WIDESEAWCS_Common.AGVEnum; using WIDESEAWCS_Common.TaskEnum; +using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; -namespace WIDESEAWCS_Tasks.AGVJob +namespace WIDESEAWCS_Tasks { public class UpdateTaskAGV { @@ -176,6 +178,31 @@ plcClient.Communicator.Write(taskFbInteractive2, 1); //throw new Exception("浠诲姟鐘舵�佹洿鏀逛负4缁堢偣宸插畬鎴愬け璐�,浠诲姟ID:" + agvTask.agv_tasknum + DateTime.Now + ",浠诲姟鐘舵�佷笉鏄粓鐐规墽琛屼腑!"); } + if (agvTask.TargetAddress.Contains("HXWLX")) + { + if (agvTask.SourceAddress.Contains("KPHLX")) + { + // 绌虹洏绾胯繘鐑樼 + // TODO: 璋冪敤鍒涙櫤鎺ュ彛鑾峰彇瀹屾暣鏉$爜 + var materials = new List<BakingClass> + { + new BakingClass { BarCode = "1", MaterialType = "1" }, + }; + MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); + if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } + } + else + { + // 鎻愬崌鏈鸿繘鐑樼 + // TODO: 璋冪敤鍒涙櫤鎺ュ彛鑾峰彇瀹屾暣鏉$爜 + var materials = new List<BakingClass> + { + new BakingClass { BarCode = "1", MaterialType = "1" }, + }; + MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); + if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } + } + } //agvtask_HtyRepository.AddTaskHistory(agvTask, OperateType.Finished.ToString()); _taskRepository.DeleteData(agvTask); @@ -231,7 +258,7 @@ } } - public static void UpdateTask(AGV plcClient, ITaskRepository taskRepository) + public static void UpdateTask(AGV plcClient, ITaskRepository taskRepository, ITaskCZRepository _taskCZRepository, ITaskCZDetailsRepository _detailsRepository) { // 浣跨敤Interlocked.Exchange淇濊瘉鍚屼竴鏃堕棿鍙湁涓�涓嚎绋嬪彲浠ユ墽琛屼换鍔℃洿鏂� if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 1) == 0) @@ -257,22 +284,22 @@ } // 璇诲彇浠诲姟鐘舵�� - int taskFbInteractive = plcClient.Communicator.Read<int>(taskFbInteractiveR); - int taskFbInteractiveW = plcClient.Communicator.Read<int>(taskFbInteractive2); - int resetTaskFbInteractiveRValue = plcClient.Communicator.Read<int>(resetTaskFbInteractiveR); + int taskFbInteractive = plcClient.Communicator.Read<ushort>(taskFbInteractiveR); + int taskFbInteractiveW = plcClient.Communicator.Read<ushort>(taskFbInteractive2); + int resetTaskFbInteractiveRValue = plcClient.Communicator.Read<ushort>(resetTaskFbInteractiveR); // 濡傛灉resetTaskFbInteractiveR涓�1锛屽垯閲嶇疆taskFbInteractiveW涓�0锛屽苟绛夊緟鍏跺彉涓�0 if (resetTaskFbInteractiveRValue == 1) { - plcClient.Communicator.Write(taskFbInteractive2, 0); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0); // 閬垮厤浣跨敤Thread.Sleep鏉ョ瓑寰呯姸鎬佸彉鍖栵紝浣跨敤鏇撮珮鏁堢殑绛夊緟鏈哄埗 for (int i = 0; i < 5; i++) { Task.Delay(300).Wait(); // 浣跨敤Task.Delay鏇夸唬Thread.Sleep锛岄伩鍏嶉樆濉炵嚎绋嬫睜涓殑绾跨▼ - int agvNumber = plcClient.Communicator.Read<int>(taskFbInteractive2); + int agvNumber = plcClient.Communicator.Read<ushort>(taskFbInteractive2); if (agvNumber != 0) { - plcClient.Communicator.Write(taskFbInteractive2, 0); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0); } else { @@ -284,8 +311,8 @@ // 鍙湁褰搕askFbInteractive涓�1涓攖askFbInteractiveW涓�0鏃舵墠澶勭悊浠诲姟鐘舵�� if (taskFbInteractive == 1 && taskFbInteractiveW == 0) { - string taskId = plcClient.Communicator.Read<int>(taskIDFb).ToString(); // 浠诲姟ID - int taskState = plcClient.Communicator.Read<int>(taskStatusFb); // 浠诲姟鐘舵�� + string taskId = plcClient.Communicator.Read<string>(taskIDFb).ToString(); // 浠诲姟ID + int taskState = plcClient.Communicator.Read<ushort>(taskStatusFb); // 浠诲姟鐘舵�� // 濡傛灉浠诲姟鐘舵�佹棤鏁堬紝鍒欑洿鎺ヨ繑鍥� if (taskState == 0) @@ -294,10 +321,11 @@ } // 鏍规嵁浠诲姟ID鏌ヨ鏁版嵁搴撲腑鐨勪换鍔� - var agvTask = taskRepository.QueryFirst(r => r.TaskNum.ToString() == taskId); + int tasknum = int.Parse(taskId.Split('-')[1]); + var agvTask = taskRepository.QueryFirst(r => r.TaskNum.ToString() == tasknum.ToString()); if (agvTask == null) { - plcClient.Communicator.Write(taskFbInteractive2, 1); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); return; // 濡傛灉浠诲姟涓嶅瓨鍦紝鐩存帴杩斿洖锛屼笉闇�瑕佸啀娆″啓鍏� } @@ -316,27 +344,84 @@ } else if (taskState == 4) // 浠诲姟缁堢偣瀹屾垚 { - if (agvTask.TaskState != (int)TaskInStatusEnum.SC_InExecuting) + if (agvTask.TaskState != (int)TaskInStatusEnum.SC_InFinish) { // 濡傛灉浠诲姟鐘舵�佷笉鏄粓鐐规墽琛屼腑锛屾姏鍑哄紓甯� throw new Exception($"浠诲姟鐘舵�佹洿鏀逛负4缁堢偣宸插畬鎴愬け璐�,浠诲姟ID:{taskId},褰撳墠鐘舵��:{agvTask.TaskState}"); } + if (agvTask.TargetAddress.Contains("HXWLX")) + { + if (agvTask.SourceAddress.Contains("KPHLX")) + { + // 绌虹洏绾胯繘鐑樼 + // TODO: 浠诲姟鎴彇瀹屾暣鏉$爜 + var details = agvTask.ExceptionMessage; + string[] splitDetails = details.Split(','); + + var materials = splitDetails + .Select(part => new BakingClass + { + MaterialType = "", + BarCode = part + }) + .ToList(); + + MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); + if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } + } + else + { + // 鎻愬崌鏈鸿繘鐑樼 + // TODO: 璋冪敤鍒涙櫤鎺ュ彛鑾峰彇瀹屾暣鏉$爜 + //var czTask = _taskCZRepository.QueryFirst(x => x.Id == agvTask.WMSId); + //CZTaskBarCodeDto barCodeDto = JsonConvert.DeserializeObject<CZTaskBarCodeDto>(czTask.DtCZTaskDetails); + //var materials = Enumerable.Range(0, 2) + // .Select(i => new BakingClass + // { + // MaterialType = czTask.TaskProductCode, + // BarCode = GetBarCodeByIndex(barCodeDto, i, hasDesc: !string.IsNullOrEmpty(czTask.TaskDesc)) + // }) + // .ToList(); + + var details = _detailsRepository.QueryData(x => x.TaskEndAddress == agvTask.TargetAddress).ToList(); + + if (details.Count >= 2) + { + details = details.Take(2).ToList(); + } + + var materials = details.Select(x => new BakingClass + { + MaterialType = x.MaterialType, + BarCode = x.MaterialBarCode, + }).ToList(); + + MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); + if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } + else + { + // 鍒犻櫎details鏁版嵁 + _detailsRepository.DeleteData(details); + } + } + } + // 鍒犻櫎宸插畬鎴愮殑浠诲姟 taskRepository.DeleteData(agvTask); - plcClient.Communicator.Write(taskFbInteractive2, 1); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); EnsureTaskFeedback(taskFbInteractive2, plcClient); } else if (taskState == 5) { - plcClient.Communicator.Write(taskFbInteractive2, 1); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); } } // 濡傛灉taskFbInteractive涓�0涓攖askFbInteractiveW涓�1锛屽垯閲嶇疆taskFbInteractiveW涓�0 if (taskFbInteractive == 0 && taskFbInteractiveW == 1) { - plcClient.Communicator.Write(taskFbInteractive2, 0); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 0); EnsureTaskFeedback(taskFbInteractive2, plcClient); } } @@ -355,15 +440,15 @@ // 鏇存柊浠诲姟鐘舵�佸苟鍐欏叆AGV鍙嶉鍦板潃 private static void UpdateTaskStatus(AGV plcClient, Dt_Task agvTask, TaskInStatusEnum targetStatus, ITaskRepository taskRepository, string taskFbInteractive2) { - if (agvTask.TaskState != (int)targetStatus) - { - plcClient.Communicator.Write(taskFbInteractive2, 1); // 鐘舵�佷笉鍖归厤锛屽啓鍏ュ弽棣� - } + //if (agvTask.TaskState != (int)targetStatus) + //{ + // plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); // 鐘舵�佷笉鍖归厤锛屽啓鍏ュ弽棣� + //} // 鏇存柊浠诲姟鐘舵�佷负涓嬩竴涓湭瀹屾垚鐘舵�� agvTask.TaskState = agvTask.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); taskRepository.UpdateData(agvTask); - plcClient.Communicator.Write(taskFbInteractive2, 1); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); EnsureTaskFeedback(taskFbInteractive2, plcClient); } @@ -376,7 +461,7 @@ int agvNumber = plcClient.Communicator.Read<int>(taskFbInteractive2); if (agvNumber != 1) { - plcClient.Communicator.Write(taskFbInteractive2, 1); + plcClient.Communicator.Write<ushort>(taskFbInteractive2, 1); } else { @@ -384,5 +469,31 @@ } } } + + // 杈呭姪鏂规硶 + private static string GetBarCodeByIndex(CZTaskBarCodeDto dto, int index, bool hasDesc) + { + return (index, hasDesc) switch + { + (0, false) => dto.BarCode1, + (1, false) => dto.BarCode2, + (0, true) => dto.BarCode3, + (1, true) => dto.BarCode4, + _ => throw new IndexOutOfRangeException() + }; + } + } + + public class BakingFeedingClass + { + public string Devid { get; set; } + + public List<BakingClass> Materials { get; set; } + } + + public class BakingClass + { + public string MaterialType { get; set; } + public string BarCode { get; set; } } } \ No newline at end of file -- Gitblit v1.9.3