From eb29ee75c7f2f4154b7a3d0c475f94e0b964e996 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 02 四月 2025 18:17:48 +0800
Subject: [PATCH] 优化事务基础写法

---
 Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs |   43 +++++++++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs b/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs
index 33359cd..8fbcc2c 100644
--- a/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs
+++ b/Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs
@@ -67,7 +67,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -153,12 +153,19 @@
                 });
 
                 //瀹屾垚鎵�鏈夊鐞嗗悗浣跨敤浜嬪姟淇濆瓨鏁版嵁
-                action = DoIfFinish(action, input.Locale);
+                action = DoIfFinish(action, input.Locale, () =>
+                {
+                    if (!OrderList.Contains(CurSn.First().ORDER_NO))
+                    {
+                        OrderList.Add(CurSn.First().ORDER_NO);
+                    }
+                    ScanList.AddRange(CurSn);
+                });
             }
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{0}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
@@ -169,17 +176,16 @@
         /// 瀹屾垚鎵�鏈夊鐞嗗悗浣跨敤浜嬪姟淇濆瓨鏁版嵁
         /// </summary>
         /// <param name="action"></param>
+        /// <param name="locale"></param>
+        /// <param name="doAfterSave"></param>
         /// <returns></returns>
-        public ApiAction<ScanOutput> DoIfFinish(ApiAction<ScanOutput> action, string locale)
+        public ApiAction<ScanOutput> DoIfFinish(ApiAction<ScanOutput> action, string locale, Action doAfterSave = null)
         {
             //淇濆瓨鏁版嵁搴�
             SaveCommitListToDB();
 
-            if (!OrderList.Contains(CurSn.First().ORDER_NO))
-            {
-                OrderList.Add(CurSn.First().ORDER_NO);
-            }
-            ScanList.AddRange(CurSn);
+            //淇濆瓨鏁版嵁鎴愬姛鍚庢墽琛�
+            doAfterSave?.Invoke();
 
             // 杩斿洖鏁版嵁
             action.Data.Data = ScanList;
@@ -188,7 +194,7 @@
             action.LocaleMsg = Biz.L("WMS.Count_BIZ_U9_ASN.CountSuccess", CurSn.First().SN);
 
             //閲嶇疆宸ュ簭
-            ResetScan();
+            ResetTrans();
             return SetOutPutMqttMsg(action, locale); ;
         }
 
@@ -564,15 +570,24 @@
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// </summary>
+        public override void ResetTrans()
+        {
+            ResetScan();
+            CurScanShelf = null;
+            base.ResetTrans();
+        }
+
+        /// <summary>
+        /// 閲嶇疆鏈鎵爜淇℃伅
         /// </summary>
         public override void ResetScan()
         {
-            base.ResetScan();
-            Command = null;
+            Command = "Normal";
             CurInvItem = null;
-            CurScanShelf = null;
             CurSn = null;
+            base.ResetScan();
         }
 
         public override bool Close(bool needSaveHistoryLog = false)

--
Gitblit v1.9.3