From 1b6bf29ff7daa1987de65940af52f452cabd6881 Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期二, 15 七月 2025 17:27:50 +0800 Subject: [PATCH] 优化AGV任务部分日志、货位绑定内部方法 --- core/WCSCore.cs | 127 ++++++++++++++++++------------------------ 1 files changed, 54 insertions(+), 73 deletions(-) diff --git a/core/WCSCore.cs b/core/WCSCore.cs index d72bf4b..a683ebd 100644 --- a/core/WCSCore.cs +++ b/core/WCSCore.cs @@ -22,29 +22,20 @@ namespace HH.WCS.Mobox3.DSZSH.core { public class WCSCore { public static ReturnResult OperateAgvTaskStatus(AgvTaskState model) { - var result = new ReturnResult(); + const string preLog = "AGV锛氫换鍔$姸鎬佸洖鎶ワ細"; try { if (model.state > 0) { // AGV 鎵ц浠诲姟鐨勯�杈戝鐞� if (!AgvTaskProcessOk(model)) { // 鎵ц涓峅K锛岃鏄庢病鏈夋壘鍒颁换鍔�- result.ResultCode = 1; - result.ResultMsg = $"鏍规嵁Model.No鏈壘鍒板搴旂殑浠诲姟锛寋model.task_no}"; - LogHelper.Info(result.ResultMsg, "API"); - return result; + return NewReturnResult(1, preLog + $"鏍规嵁浠诲姟鍙�{model.task_no}'鏈壘鍒板搴旂殑浠诲姟锛�); } } - result.ResultCode = 0; - result.ResultMsg = "success"; - LogHelper.Info(result.ResultMsg, "API"); - return result; + return NewReturnResult(0, "success"); // 涓嶈繑鍥炶缁嗘垚鍔熸棩蹇楋紝閬垮厤NDC浠sg=success浣滀负鎴愬姛鍒ゅ畾锛堝弬鑰冨浗鑷級 } catch (Exception ex) { - result.ResultCode = -1; - result.ResultMsg = $"鍙戠敓浜嗗紓甯革細{ex.Message}"; - LogHelper.Info(result.ResultMsg, "Error"); - return result; + return NewReturnResult(-1, $"鍙戠敓浜嗗紓甯革細{ex.Message}\n{ex.StackTrace}"); } } @@ -76,7 +67,7 @@ WCSHelper.UpdateStatus(TN_Task, "鍙栬揣瀹屾垚"); // 浠诲姟鐘舵�鏀规垚鍙栬揣瀹屾垚 TaskProcess.OperateStatus(TN_Task, 4); // 璧风偣瀹瑰櫒璐т綅瑙g粦,瑙i攣璧风偣 - if (TN_Task.S_TYPE == TaskName.C鎴愬搧鑳跺嚭搴� { + if (TN_Task.S_TYPE == ETask.C鎴愬搧鑳跺嚭搴�Name()) { var nextOutboundTask = Task.Run(() => { UpdateOutboundTaskState(3); }); @@ -128,8 +119,8 @@ var cgDetail = new TN_CG_Detail(); // 濡傛灉娌℃湁淇℃伅锛岄粯璁ゅ氨鏄┖鍊硷紝鍙互鐩存帴濉叆锛屼笉闇�鍒ゆ柇 //var emptyTask = false; // 绌烘墭/绌虹浠诲姟 - if (task.S_TYPE != TaskName.H濂借繍绠盻绌虹涓婄嚎 && task.S_TYPE != TaskName.H濂借繍绠盻绌虹鍏ュ簱 && - task.S_TYPE != TaskName.T鎵樼洏_绌烘墭涓婄嚎 && task.S_TYPE != TaskName.T鎵樼洏_绌烘墭鍏ュ簱) { + if (task.S_TYPE != ETask.K绌烘墭涓婄嚎鍑哄簱.Name() && task.S_TYPE != ETask.K绌烘墭鍏ュ簱.Name() && + task.S_TYPE != ETask.K绌虹涓婄嚎鍑哄簱.Name() && task.S_TYPE != ETask.K绌虹鍏ュ簱.Name()) { // 闈炵┖鎵�绌虹浠诲姟锛堢┖鎵�绌虹浠诲姟鏃犳硶鍦–GDetail鏌ュ埌鐗╂枡淇℃伅锛� //emptyTask= true; cgDetail = db.Queryable<TN_CG_Detail>() @@ -147,8 +138,8 @@ var isInbound = false; // 鍏ュ簱绫诲瀷鐨勪换鍔★紙鍖呮嫭绉诲簱绫讳换鍔★級 var inboundTasks = new List<string> { - TaskName.H濂借繍绠盻婊$涓嬬嚎鍏ュ簱, TaskName.H濂借繍绠盻绌虹鍏ュ簱, TaskName.T鎵樼洏_婊℃墭涓嬬嚎鍏ュ簱, TaskName.T鎵樼洏_绌烘墭鍏ュ簱, - TaskName.C鎶芥_鍚堟牸鍥炲簱, TaskName.C鎶芥_涓嶅悎鏍肩Щ搴� TaskName.Y绉诲簱 + ETask.M婊℃墭涓嬬嚎鍏ュ簱.Name(), ETask.M婊$涓嬬嚎鍏ュ簱.Name(), ETask.K绌烘墭鍏ュ簱.Name(), ETask.K绌虹鍏ュ簱.Name(), + ETask.C鎶芥鍚堟牸鍥炲簱.Name(), ETask.C鎶芥涓嶅悎鏍肩Щ搴�Name(), ETask.Y绉诲簱.Name() }; if (inboundTasks.Contains(task.S_TYPE)) { isInbound= true; @@ -204,28 +195,28 @@ /// <returns></returns> public static ReturnResult SafetyInteraction(SafetyInteractionInfo model) { var db = new SqlHelper<object>().GetInstance(); - var info = ""; + const string preLog = "AGV锛氫骇绾垮畨鍏ㄤ氦浜掞細"; try { ModbusHelper.Relink(); - //var loc = db.Queryable<TN_Location>() - // .Where(l => l.S_AGV_SITE == model.station_name && Settings.AreaMap[AreaName.鍖呰鍖篯.Contains(l.S_AREA_CODE)) - // .First(); + var BZQ = Settings.GetTaskInfo(ETask.M婊℃墭涓嬬嚎鍏ュ簱).StartAreas; + var loc = db.Queryable<TN_Location>() + .Where(l => BZQ.Contains(l.S_AREA_CODE) && l.S_AGV_SITE == model.station_name).First(); - if (!Settings.AgvSite_ProdLineCodeMap.TryGetValue(model.station_name, out int prodIndex)) { - info = $"AGV 绔欑偣{model.station_name}涓嶆槸鍚堟硶鐨勪骇绾挎帴椹充綅绔欑偣"; - LogHelper.Info(info); - return NewReturnResult(1, info); + if (loc == null) { + return NewReturnResult(1, preLog + $"AGV 绔欑偣{model.station_name}涓嶆槸鍚堟硶鐨勪骇绾挎帴椹充綅绔欑偣"); + } + + if (!Settings.LocProdIdMap.TryGetValue(loc.S_CODE, out var prodIndex)) { + return NewReturnResult(1, preLog + $"AGV 绔欑偣{model.station_name}涓嶆槸鍚堟硶鐨勪骇绾挎帴椹充綅绔欑偣"); } var prodLineInfo = Settings.ProductionLines[prodIndex]; var prodLineDevice = new ProductionLineDevice(prodLineInfo); if (!prodLineDevice.LoadDeviceStateOk()) { - info = "涓庝骇绾胯澶囬�璁け璐�; - LogHelper.Info(info); - return NewReturnResult(2, info); + return NewReturnResult(2, preLog + "涓庝骇绾胯澶囬�璁け璐�); } //var tn_task = db.Queryable<TN_Task>().First(a => a.S_CODE == model.task_no); @@ -242,61 +233,45 @@ //} if (prodLineDevice.SystemState != 1) { - info = $"褰撳墠浜х嚎鏃犳硶涓嶢GV鑱斿姩锛氱姸鎬亄prodLineDevice.SystemState}"; - LogHelper.Info(info); - return NewReturnResult(3, info); + return NewReturnResult(3, preLog + $"褰撳墠浜х嚎鏃犳硶涓嶢GV鑱斿姩锛氱姸鎬亄prodLineDevice.SystemState}"); } - if (model.apply_code == "5") { // 璇锋眰鍙栬揣 + // 璇锋眰鍙栬揣 + if (model.apply_code == "5") { if (prodLineDevice.FullOffline != 1) { - info = $"褰撳墠杈撻�绾挎弧鏂欎笅绾夸俊鍙蜂笉涓�锛屾棤娉曞彇璐�; - LogHelper.Info(info); - return NewReturnResult(4, info); + return NewReturnResult(4, preLog + $"褰撳墠杈撻�绾挎弧鏂欎笅绾夸俊鍙蜂笉涓�锛屾棤娉曞彇璐�); } if (!prodLineDevice.SetAgvPicking(1)) { - info = $"鍚戣緭閫佺嚎鍐欏叆鍏佽鍙栬揣淇″彿澶辫触"; - LogHelper.Info(info); - return NewReturnResult(5, info); + return NewReturnResult(5, preLog + $"鍚戣緭閫佺嚎鍐欏叆鍏佽鍙栬揣淇″彿澶辫触"); } - info = $"鍚戣緭閫佺嚎鍐欏叆鍏佽鍙栬揣淇″彿鎴愬姛"; - LogHelper.Info(info); - return NewReturnResult(0, info); + return NewReturnResult(0, preLog + $"鍚戣緭閫佺嚎鍐欏叆鍏佽鍙栬揣淇″彿鎴愬姛"); } - else if (model.apply_code == "1") { // 璇锋眰鍗歌揣 + // 璇锋眰鍗歌揣 + else if (model.apply_code == "1") { if (prodLineDevice.AllowAgvPlacePallet != 1) { - info = $"褰撳墠杈撻�绾垮厑璁告斁鎵樼洏淇″彿涓嶄负1锛屾棤娉曟斁璐�; - LogHelper.Info(info); - return NewReturnResult(6, info); + return NewReturnResult(6, preLog + $"褰撳墠杈撻�绾垮厑璁告斁鎵樼洏淇″彿涓嶄负1锛屾棤娉曟斁璐�); } if (!prodLineDevice.SetAgvPlacingPallet(1)) { - info = $"鍚戣緭閫佺嚎鍐欏叆鍏佽鏀捐揣淇″彿澶辫触"; - LogHelper.Info(info); - return NewReturnResult(7, info); + return NewReturnResult(7, preLog + $"鍚戣緭閫佺嚎鍐欏叆鍏佽鏀捐揣淇″彿澶辫触"); } - info = $"鍚戣緭閫佺嚎鍐欏叆鍏佽鏀捐揣淇″彿鎴愬姛"; - LogHelper.Info(info); - return NewReturnResult(0, info); + return NewReturnResult(0, preLog + $"鍚戣緭閫佺嚎鍐欏叆鍏佽鏀捐揣淇″彿鎴愬姛"); } else { - info = $"褰撳墠AGV璇锋眰鐮佷笉涓�5鍙栬揣 鎴�1鍗歌揣"; - LogHelper.Info(info); - return NewReturnResult(8, info); + return NewReturnResult(8, preLog + $"褰撳墠AGV璇锋眰鐮佷笉涓�5鍙栬揣 鎴�1鍗歌揣"); } } catch (Exception ex) { - info = $"鍙戠敓浜嗗紓甯革細{ex.Message}"; - LogHelper.InfoEx(ex); - return NewReturnResult(1, info); + return NewReturnResult(1, preLog + $"鍙戠敓浜嗗紓甯革細{ex.Message}\n{ex.StackTrace}"); } } public static void UpdateOutboundTaskState(int spotStateCode) { - var taskName = TaskName.C鎴愬搧鑳跺嚭搴� + var taskName = ETask.C鎴愬搧鑳跺嚭搴�Name(); var db = new SqlHelper<object>().GetInstance(); var detail = db.Queryable<TN_Outbound_Detail>() @@ -419,7 +394,7 @@ model.hwzt = "宸插嚭搴�; var jsonInfo = JsonConvert.SerializeObject(model); - var result = httpH.WebPost(Settings.ErpApiUrl + "PickUpReturn", jsonInfo); + var result = httpH.WebPost(Settings.ErpApiUrl + Settings.ErpRoute.PickUpReturn, jsonInfo); LogHelper.InfoApi($"鍙栬揣瀹屾垚鍙嶉ERP鎺ュ彛锛岀粨鏋�{result}锛岃皟鐢ㄥ弬鏁帮細", model); @@ -446,7 +421,8 @@ if (list.Count > 0) { list.ForEach(task => { //浣跨敤鑷畾涔変换鍔℃帹閫�- TaskProcess.SendTask(task);//璋冨害NDC鎴栨澀濂ユ垨鍥借嚜璁惧 + //TaskProcess.SendTask(task);//璋冨害NDC鎴栨澀濂ユ垨鍥借嚜璁惧 + TaskProcess.SendNDCTask(task); }); } else { @@ -457,7 +433,7 @@ // TCP 闈炶疆璇㈡柟寮�妯℃嫙浜х嚎涓嬬嚎鐨勫皾璇� public static void StartServer() { - var ListenPort = 6000; + var ListenPort = Settings.TcpServerPort; TcpListener listener = new TcpListener(IPAddress.Any, ListenPort); listener.Start(); Console.WriteLine($"鍚庡彴鏈嶅姟宸插惎鍔紝鐩戝惉绔彛 {ListenPort}..."); @@ -523,21 +499,22 @@ var db = new SqlHelper<object>().GetInstance(); var info = ""; - const string taskName = TaskName.T鎵樼洏_婊℃墭涓嬬嚎鍏ュ簱; - const string startAreaName = AreaName.B鍖呰鍖� - const string endAreaName = AreaName.M婊℃墭璐ф灦鍖� + var taskInfo = Settings.GetTaskInfo(ETask.M婊℃墭涓嬬嚎鍏ュ簱); + var taskName = taskInfo.TaskName; + var startAreas = taskInfo.StartAreas; + var endAreas = taskInfo.EndAreas; const string cntrType = "鎵樼洏"; try { var startLoc = db.Queryable<TN_Location>() .Where(l => l.S_CODE == startLocCode) - .Where(l => Settings.AreaMap[startAreaName].Contains(l.S_AREA_CODE)) + .Where(l => startAreas.Contains(l.S_AREA_CODE)) .Where(l => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "鏃� && l.C_ENABLE == "Y") //.Where(l => l.N_CURRENT_NUM == 0) // 缁戝畾鍓� .First(); if (startLoc == null) { - info = $"鍦�{startAreaName}'涓病鏈夋壘鍒拌捣鐐硅揣浣�{startLocCode}'锛屾垨涓嶆弧瓒宠姹傦細鏈笂閿併�褰撳墠瀹瑰櫒鏁伴噺=0"; + info = $"娌℃湁鎵惧埌璧风偣璐т綅'{startLocCode}'锛屾垨涓嶆弧瓒宠姹傦細鏈笂閿併�褰撳墠瀹瑰櫒鏁伴噺=0"; LogHelper.Info(info); return new Result<bool>(false, info); } @@ -555,14 +532,14 @@ startLoc.N_CURRENT_NUM = 1; // 缁戝畾鍚� var endLoc = db.Queryable<TN_Location>() - .Where(a => Settings.AreaMap[endAreaName].Contains(a.S_AREA_CODE)) + .Where(a => endAreas.Contains(a.S_AREA_CODE)) .Where(a => a.N_LOCK_STATE == 0 && a.S_LOCK_STATE == "鏃� && a.C_ENABLE == "Y") // 绛涢�锛氭湭涓婇攣 .Where(a => a.N_CURRENT_NUM == 0) // 绛涢�锛氱┖璐т綅 .OrderBy(l => l.N_LAYER) .First(); if (endLoc == null) { - info = $"鍦ㄧ粓鐐硅揣鍖�{endAreaName}'涓紝娌℃湁鎵惧埌鍚堥�鐨勩�缁堢偣璐т綅銆戯紝闇�婊¤冻瑕佹眰锛氭湭涓婇攣銆佸綋鍓嶅鍣ㄦ暟閲�0"; + info = $"娌℃湁鎵惧埌鍚堥�鐨勩�缁堢偣璐т綅銆戯紝闇�婊¤冻瑕佹眰锛氭湭涓婇攣銆佸綋鍓嶅鍣ㄦ暟閲�0"; LogHelper.Info(info); return new Result<bool>(false, info); } @@ -570,8 +547,8 @@ var cntId = locCntrRel.S_CNTR_CODE; var task = WCSHelper.BuildTask(startLoc, endLoc, cntId, taskName); - LocationHelper.LockStartLoc(ref startLoc); // 璧风偣鍑哄簱閿�- LocationHelper.LockEndLoc(ref endLoc); // 缁堢偣鍏ュ簱閿�+ WCSHelper.LockStartLoc(ref startLoc); // 璧风偣鍑哄簱閿�+ WCSHelper.LockEndLoc(ref endLoc); // 缁堢偣鍏ュ簱閿� using (var tran = db.Ado.UseTran()) { if (locCntrRelOld != null) { @@ -630,11 +607,15 @@ } } catch (Exception ex) { - LogHelper.InfoEx(ex); - return new Result<bool>(false, ex.Message); + return NewResult(false, ex.Message); } } + private static Result<bool> NewResult(bool res, string msg, bool log = true) { + if (log) { LogHelper.Info(msg); } + return new Result<bool>(res, msg); + } + } public class ProductCompletedMessage { -- Gitblit v1.9.1