From e79700d34620c495667b7b8e7b852f23ed7d7e4e Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期三, 16 七月 2025 17:30:42 +0800 Subject: [PATCH] 简化增删改表达式,避免类型匹配出错 --- core/WCSCore.cs | 91 +++++++++++++++------------------------------ 1 files changed, 30 insertions(+), 61 deletions(-) diff --git a/core/WCSCore.cs b/core/WCSCore.cs index b6b994e..dd776f4 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}"); } } @@ -147,7 +138,7 @@ var isInbound = false; // 鍏ュ簱绫诲瀷鐨勪换鍔★紙鍖呮嫭绉诲簱绫讳换鍔★級 var inboundTasks = new List<string> { - ETask.M婊℃墭涓嬬嚎鍏ュ簱.Name(), ETask.K绌虹鍏ュ簱.Name(), ETask.M婊℃墭涓嬬嚎鍏ュ簱.Name(), ETask.K绌烘墭鍏ュ簱.Name(), + 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)) { @@ -183,7 +174,7 @@ }; // 鏁版嵁搴撴搷浣�- if (db.Insertable<TN_Record_Table>(record).ExecuteCommand() <= 0) { + if (db.Insertable(record).ExecuteCommand() <= 0) { info = "鎻掑叆鍑哄叆搴撹褰曡〃澶辫触锛� + JsonConvert.SerializeObject(record); LogHelper.Info(info); return; @@ -204,7 +195,7 @@ /// <returns></returns> public static ReturnResult SafetyInteraction(SafetyInteractionInfo model) { var db = new SqlHelper<object>().GetInstance(); - var info = ""; + const string preLog = "AGV锛氫骇绾垮畨鍏ㄤ氦浜掞細"; try { ModbusHelper.Relink(); @@ -214,24 +205,18 @@ .Where(l => BZQ.Contains(l.S_AREA_CODE) && l.S_AGV_SITE == model.station_name).First(); if (loc == null) { - info = $"AGV 绔欑偣{model.station_name}涓嶆槸鍚堟硶鐨勪骇绾挎帴椹充綅绔欑偣"; - LogHelper.Info(info); - return NewReturnResult(1, info); + return NewReturnResult(1, preLog + $"AGV 绔欑偣{model.station_name}涓嶆槸鍚堟硶鐨勪骇绾挎帴椹充綅绔欑偣"); } if (!Settings.LocProdIdMap.TryGetValue(loc.S_CODE, out var prodIndex)) { - info = $"AGV 绔欑偣{model.station_name}涓嶆槸鍚堟硶鐨勪骇绾挎帴椹充綅绔欑偣"; - LogHelper.Info(info); - return NewReturnResult(1, info); + 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); @@ -248,56 +233,40 @@ //} 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}"); } } @@ -315,7 +284,7 @@ using (var tran = db.Ado.UseTran()) { detail.N_B_STATE = spotStateCode; - if (db.Updateable<TN_Outbound_Detail>(detail).UpdateColumns(it => it.N_B_STATE).ExecuteCommand() <= 0) { + if (db.Updateable(detail).UpdateColumns(it => it.N_B_STATE).ExecuteCommand() <= 0) { tran.RollbackTran(); LogHelper.Info($"{taskName}锛欰GV鍙栬揣锛氫慨鏀规槑缁嗗崟鐘舵�涓恒�3浠诲姟鎵ц瀹屾垚銆戝け璐ワ紒"); return; @@ -432,7 +401,7 @@ plan.SFJS = model.sfjs; plan.SFSL = model.sfsl; plan.HWZT = model.hwzt; - var success = db.Updateable<TN_Outbound_Plan>(plan).UpdateColumns(p => new { p.SFJS, p.SFSL, p.HWZT }).ExecuteCommand() > 0; + var success = db.Updateable(plan).UpdateColumns(p => new { p.SFJS, p.SFSL, p.HWZT }).ExecuteCommand() > 0; info = "鏇存柊鍑哄簱璁″垝鍗曡褰曡〃" + (success ? "鎴愬姛" : "澶辫触"); LogHelper.Info(info); } @@ -583,7 +552,7 @@ using (var tran = db.Ado.UseTran()) { if (locCntrRelOld != null) { - if (db.Deleteable<TN_Loc_Container>(locCntrRelOld).ExecuteCommand() <= 0 && + if (db.Deleteable(locCntrRelOld).ExecuteCommand() <= 0 && db.Updateable<TN_Location>().SetColumns(l => l.N_CURRENT_NUM == 0).Where(l => l.S_CODE == locCntrRelOld.S_LOC_CODE).ExecuteCommand() <= 0) { tran.RollbackTran(); info = $"鍒犻櫎鏃ц揣浣嶅鍣ㄥ叧绯昏〃澶辫触锛氳揣浣嶇紪鐮亄locCntrRelOld.S_LOC_CODE}锛屽鍣ㄧ紪鐮亄locCntrRelOld.S_CNTR_CODE}"; @@ -592,14 +561,14 @@ } } - if (db.Insertable<TN_Loc_Container>(locCntrRel).ExecuteCommand() <= 0) { + if (db.Insertable(locCntrRel).ExecuteCommand() <= 0) { tran.RollbackTran(); info = $"鎻掑叆璐т綅瀹瑰櫒鍏崇郴琛ㄥけ璐ワ細璐т綅缂栫爜{locCntrRel.S_LOC_CODE}锛屽鍣ㄧ紪鐮亄locCntrRel.S_CNTR_CODE}"; LogHelper.Info(info); return new Result<bool>(false, info); } - if (db.Updateable<TN_Location>(startLoc).UpdateColumns(it => new { + if (db.Updateable(startLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, @@ -612,7 +581,7 @@ return new Result<bool>(false, info); } - if (db.Updateable<TN_Location>(endLoc).UpdateColumns(it => new { + if (db.Updateable(endLoc).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE, it.S_LOCK_OP, @@ -624,7 +593,7 @@ return new Result<bool>(false, info); } - if (db.Insertable<TN_Task>(task).ExecuteCommand() <= 0) { + if (db.Insertable(task).ExecuteCommand() <= 0) { tran.RollbackTran(); info = $"鐢熸垚浠诲姟'{taskName}'澶辫触锛屼换鍔″彿={task.S_CODE}锛屽鍣ㄥ彿={cntId}锛岃捣鐐�{startLoc.S_CODE}锛岀粓鐐�{endLoc.S_CODE}"; LogHelper.Info(info); -- Gitblit v1.9.1