From 5543c73e991dd0fb37c25365f688dc821394e09c Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期三, 27 十一月 2024 00:50:35 +0800 Subject: [PATCH] 一些优化 --- Tiger.Business.MES/Transaction/YadaPacking.cs | 87 ++++++++++++++++++++++++++++++++++--------- 1 files changed, 68 insertions(+), 19 deletions(-) diff --git a/Tiger.Business.MES/Transaction/YadaPacking.cs b/Tiger.Business.MES/Transaction/YadaPacking.cs index 28182e7..7ea9974 100644 --- a/Tiger.Business.MES/Transaction/YadaPacking.cs +++ b/Tiger.Business.MES/Transaction/YadaPacking.cs @@ -51,7 +51,7 @@ /// <returns></returns> public async Task<ApiAction<SubmitOutput>> Submit(SubmitInput input) { - ConsoleExt.WriteLine($"{curtime = prevtime = DateTime.Now:HH:mm:ss} ***** 1 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = prevtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 1 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; var action = new ApiAction<SubmitOutput>(new SubmitOutput()); try { @@ -94,13 +94,13 @@ var wosns = Biz.Db.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER && q.BATCH_NO == s.BATCH_NO)) .ByAuth(input.AuthOption)//.Where((q, s) => s.STATUS < BIZ_MES_WO_SN.STATUSs.Finished.GetValue()) .Where((q, s) => s.SN == input.SN || s.FLOW_SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList(); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 2 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 2 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; //鍏堝垽鏂綋鍓嶅伐鍗曚笉涓虹┖涓斿綋鍓嶅矖浣嶅湪褰撳墠宸ュ崟鏄笉鏄绔欙紝濡傛灉鏄垯涓嶅厑璁稿彉鏇村綋鍓嶅伐鍗曪紝灏濊瘯鎶婃潯鐮佺粦瀹氬埌褰撳墠宸ュ崟 if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode)) { //鏇存柊CurBatch CurBatch?.Update(); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 3 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 3 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; var wosn = wosns.FirstOrDefault(q => q.Batch.ORDER_NO == CurBatch.WO.ORDER_NO && (q.SN.STATUS == BIZ_MES_WO_SN.STATUSs.Finished.GetValue() || q.SN.STATUS == BIZ_MES_WO_SN.STATUSs.Scrap.GetValue())); if (!wosn.IsNullOrEmpty()) { @@ -114,7 +114,7 @@ { //鎻愪氦鏁版嵁 action = NodeSubmit(action, input); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 4 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 4 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; //鏇存柊宸ュ簭淇℃伅 if (!action.IsSuccessed) { @@ -235,23 +235,23 @@ { //鏇存柊CurBatch CurBatch?.Update(); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 5 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 5 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; var submitStep = Steps.Where(q => q.ID == input.CurStepID && !q.IsFinished).FirstOrDefault(); //濡傛灉瀹㈡埛绔繑鍥炵殑褰撳墠宸ユID鎵句笉鍒版湭瀹屾垚鐨勮涓哄伐姝ワ紝鍒欑洿鎺ュ紑濮嬩笅涓�涓涓哄伐姝� if (submitStep.IsNullOrEmpty()) { action = BeginNextActionStep(input); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 6 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 6 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; } else { action = submitStep.Submit(input); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 7 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 7 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; //濡傛灉褰撳墠宸ユ宸插畬鎴愶紝寮�濮嬫墽琛屼笅涓�宸ユ if (action.IsSuccessed && submitStep.IsFinished) { action = BeginNextActionStep(input); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 8 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 8 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; } //濡傛灉褰撳墠宸ユ鏈畬鎴� else @@ -296,7 +296,7 @@ //action.CatchExceptionWithLog(ex, $"鍖呰宸ュ簭锛氭彁浜ゆ搷浣滄暟鎹紓甯�"); action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.SubmitException")); } - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 9 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 9 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; return action; } @@ -308,7 +308,7 @@ /// <returns></returns> public ApiAction<SubmitOutput> NodeSubmit(ApiAction<SubmitOutput> action, SubmitInput input) { - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 10 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 10 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; var curNode = CurBatch.GetNode(PostCode); try { @@ -392,22 +392,52 @@ //璁剧疆褰撳墠鎸囦护涓烘甯镐骇鍝佽繃绔� NodeCmd = "NodeSubmit"; - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 11 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 11 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + //鑾峰彇鍑鸿揣鐘舵�� DbClient db = Biz.DataSource["YadaU9C"].Client; var ship = db.Queryable<mes_ShipList>().Where(q => q.MoDoc == CurBatch.WO.ORDER_NO && q.Status == 2 && SqlFunc.DateIsSame(q.BusinessDate, DateTime.Now)).First(); + int CurShipQty = 0; + int WaitShipmentCarton = 0; + int WaitShipment = 0; if (ship.IsNullOrEmpty()) { IsPrintCustomerLabel = false; } else { + CurShipQty = ship.ShipQty; + IsPrintCustomerLabel = true; SugarParameter[] pars = Biz.Db.Ado.GetParameters(new { BATCH = CurBatch.Batch.BATCH_NO, NodeIdOrName = curNode.NODE_NAME }); var list = Biz.Db.Ado.UseStoredProcedure().GetDataTable("SP_MES_GET_NODE_BATCH_COUNT", pars).AsEnumerable().ToList(); if (!list.IsNullOrEmpty()) { var batchCount = list.Where(q => q["ProdDate"].ToString() == "Whole").FirstOrDefault(); - IsPrintCustomerLabel = batchCount.IsNullOrEmpty() ? false : batchCount["WaitShipment"].ToInt32() >= ship.ShipQty ? false : true; + WaitShipmentCarton = batchCount["WaitShipmentCarton"].ToInt32(); + WaitShipment = batchCount["WaitShipment"].ToInt32(); + IsPrintCustomerLabel = batchCount.IsNullOrEmpty() ? IsPrintCustomerLabel : batchCount["WaitShipment"].ToInt32() >= ship.ShipQty ? false : true; } } ShippingOrder = IsPrintCustomerLabel ? ship?.ShipDoc ?? "" : ""; - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 12 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + //缂撳瓨鍑鸿揣鏁伴噺 + Context.SetOrAdd("CurShipQty", CurShipQty); + //if (Context.ContainsKey("CurShipQty")) + //{ + // Context["CurShipQty"] = CurShipQty; + //} + //else + //{ + // Context.Add("CurShipQty", CurShipQty); + //} + //缂撳瓨鍑鸿揣绠辨暟 + Context.SetOrAdd("CurWaitShipmentCarton", WaitShipmentCarton); + Context.SetOrAdd("CurWaitShipment", WaitShipment); + //if (Context.ContainsKey("CurWaitShipmentCarton")) + //{ + // Context["CurWaitShipmentCarton"] = WaitShipmentCarton; + //} + //else + //{ + // Context.Add("CurWaitShipmentCarton", WaitShipmentCarton); + //} + + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 12 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; //缁戝畾鏉$爜鍒板伐鍗� foreach (var wipSN in wipSNs) { @@ -551,7 +581,7 @@ var _curNodeSetting = curNodeSetting.Clone(); var _Batch = CurBatch.Batch.Clone(); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 13 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 13 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; //鍒濆鍖栧伐姝ュ垪琛� Steps.Clear(); var curStep = new WorkStep(IWorkStep.NodeTypes.Node, this) @@ -675,7 +705,7 @@ //action.CatchExceptionWithLog(ex, $"{curNode.NODE_NAME}锛氬伐搴忚妭鐐瑰伐姝ユ彁浜ゆ暟鎹紓甯革紝璇锋鏌ュ伐搴忚妭鐐硅缃�"); action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.NodeSubmitException", curNode.NODE_NAME)); } - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 13.1 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 13.1 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; return action; } @@ -689,7 +719,7 @@ var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null; var operInfo = SetOperNodeInfo(CurOperInfo(locale)); Action endAction = null; - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 14 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 14 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; //濡傛灉褰撳墠鏉$爜宸茬粡璧板埌娴佺▼缁堢偣鍒欒褰曟潯鐮佸畬宸� if (operInfo.IsReachedEndNode) @@ -757,8 +787,7 @@ //淇濆瓨鏁版嵁搴� SaveStepsCommitActionToDB(endAction); - ConsoleExt.WriteLine($"{curtime = DateTime.Now:HH:mm:ss} ***** 15 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; - + //淇濆瓨鎴愬姛锛岃繑鍥炶繃绔欐秷鎭� operInfo.InputQty += CurWipSNs.Count; action.Data.Data = new PackingActionOutput() { PkgInfo = curPkg }; @@ -775,7 +804,7 @@ //閲嶇疆宸ュ簭 ResetNode(); - + curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 15 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime; return action; } @@ -939,6 +968,26 @@ return action; } + /// <summary> + /// 鑾峰彇鏄惁鎵撳嵃瀹㈡埛鏍囩杩樻槸鍏ュ簱鏍囩 + /// </summary> + /// <returns></returns> + public async Task<ApiAction<ShipingInfo>> GetIsCustomerLabelAndShipQty() + { + var action = new ApiAction<ShipingInfo>(); + try + { + action.Data = new ShipingInfo() { + IsPrintCustomerLabel= IsPrintCustomerLabel, + ShipQty =Context.GetOrDefault("CurWaitShipment").ToInt32()>= Context.GetOrDefault("CurShipQty").ToInt32()? CurBatch.Batch.PLAN_QTY - Context.GetOrDefault("CurShipQty").ToInt32(): Context.GetOrDefault("CurShipQty").ToInt32() }; + } + catch (Exception ex) + { + action.CatchExceptionWithLog(ex, $"鍖呰宸ュ簭锛氳幏鍙栨槸鍚︽墦鍗板鎴锋爣绛捐繕鏄叆搴撴爣绛惧紓甯�"); + } + return action; + } + #endregion Functions /// <summary> -- Gitblit v1.9.3