From a8fcfbb5e5ed9a07b1a30ef2d7ef9d407e9b04dd Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 02 四月 2025 21:44:54 +0800
Subject: [PATCH] 更新ASN实体

---
 Tiger.Business.WMS/Transaction/In_Default.cs |   87 +++++++++++++++++++++++--------------------
 1 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/Tiger.Business.WMS/Transaction/In_Default.cs b/Tiger.Business.WMS/Transaction/In_Default.cs
index cf4d374..cb890a6 100644
--- a/Tiger.Business.WMS/Transaction/In_Default.cs
+++ b/Tiger.Business.WMS/Transaction/In_Default.cs
@@ -13,6 +13,8 @@
 using Tiger.Business.WMS.Sharetronic.Shelf;
 //using Microsoft.IdentityModel.Tokens;
 using Tiger.Model.MES.Yada;
+using static IronPython.Modules.PythonThread;
+using Tiger.Model.Entitys.MES.Position;
 
 namespace Tiger.Business.WMS.Transaction
 {
@@ -23,7 +25,7 @@
     {
         public IIn_Default Init(string id, string userCode, string apiHost, string orgCode)
         {
-            base.Init(id, apiHost, userCode, orgCode);
+            base.Init(id, userCode, apiHost, orgCode);
             Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
             return this;
         }
@@ -63,7 +65,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -81,13 +83,13 @@
                 if (CurInvItem.IsNullOrEmpty())
                 {
                     //瑙f瀽鏉$爜
-                    Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
+                    Result<IInventory> result = GetInventory(input.SN, input.AuthOption, true);
 	                if (!result.IsSuccessed)
 	                {
 	                    action.IsSuccessed = false;
 	                    action.LocaleMsg = result.LocaleMsg;
-	                    return action;
-	                }
+                        return SetOutPutMqttMsg(action, input.Locale);
+                    }
 	                var inv = result.Data as Inventory;
 
                     //楠岃瘉鏉$爜鏄惁姝g‘
@@ -96,7 +98,7 @@
                         action.IsSuccessed = false;
                         //action.LocaleMsg = Biz.L("鐘舵�乕{0}]寮傚父锛岃閲嶆柊鎵弿");
                         action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', inv.StatusList.Select(q => q.GetDesc())));
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
                     //鐗╂枡楠岃瘉
                     if (inv.ItemInfo.IsNullOrEmpty() || inv.ItemInfo.IS_ACTIVE == "N")
@@ -104,16 +106,12 @@
                         action.IsSuccessed = false;
                         //action.LocaleMsg = Biz.L("鐗╂枡缂栫爜[{0}]涓嶅瓨鍦ㄦ垨鑰呰鐗╂枡鏈惎鐢�");
                         action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", inv.ItemInfo?.ITEM_CODE.IsNullOrEmpty(inv.Barcode.ItemCode));
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
 
                     if (inv.Items.Count == 0)
                     {
-                        List<WMS_ITEM_HIS> ItemHistorys = new List<WMS_ITEM_HIS>();
-                        WMS_ITEM Item;
-                        WMS_ITEM_PKG ItemPkgs;
-
-                        Item = new()
+                        var newItem = new WMS_ITEM()
                         {
                             SN = inv.Barcode.SN,
                             ITEM_CODE = inv.Barcode.ItemCode,
@@ -125,9 +123,8 @@
                             UNIT = inv.Barcode.Unit,
                         };
 
-                        WMS_ITEM_HIS his = new(Item, $"鏍囧噯涓婃灦鍏ュ簱");
-                        ItemHistorys.Add(his);
-                        ItemPkgs = new()
+                        WMS_ITEM_HIS his = new(newItem, $"鏍囧噯涓婃灦鍏ュ簱");
+                        var newPkg = new WMS_ITEM_PKG()
                         {
                             SN = inv.Barcode.SN,
                             AUTH_ORG = input.AuthOption.CurOrg,
@@ -139,19 +136,19 @@
 
                         var noExt = inv.Items.Where(q => !inv.ItemsExt.Any(s => s.SN == q.SN)).ToList();
                         //鎵╁睍琛ㄤ笉瀛樺湪鏃舵柊寤�
-                        foreach (var item in noExt)
+                        foreach (var ext in noExt)
                         {
                             inv.ItemsExt.Add(new()
                             {
-                                SN = item.SN,
+                                SN = ext.SN,
                                 META_SN = inv.Barcode.MetaSn,
                                 QR_CODE = inv.Barcode.MetaSn
                             });
                         }
 
-                        inv.Items.Add(Item);
+                        inv.Items.Add(newItem);
                         inv.History.Add(his);
-                        inv.Packages.Add(ItemPkgs);
+                        inv.Packages.Add(newPkg);
                     }
                     //闆呰揪涓嶄粠鏉$爜涓婃洿鏂版暟閲�
                     //else if (inv.Items.Count == 1)
@@ -181,20 +178,20 @@
                     CurInvItem = inv;
 
                     //妫�鏌ョ墿鏂欐暟閲忥紝濡傛灉娌℃湁鍒欐煡璇㈤泤杈炬潯鐮佷富妗o紝鎶婃暟閲忚繑鍥炲墠绔‘璁�
-                    if (CurInvItem.Items.Any(q => q.QTY <= 0))
+                    //if (CurInvItem.Items.Any(q => q.QTY <= 0))
                     {
                         var qtyList = Biz.DataSource["YadaU9C"].Client.Queryable<mes_MaterialBarCode>().Where(q => CurInvItem.Items.Select(q => q.SN).Contains(q.Code)).ToList();
                         foreach (var qty in qtyList)
                         {
                             var item = CurInvItem.Items.First(q => q.SN == qty.Code);
                             item.QTY = qty.WhQty;
-                            item.SUPP_LOTNO = qty.Segment7;
+                            item.SUPP_LOTNO = CurInvItem.Barcode.LotNo;
                         }
                         action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY });
                         action.Data.Command = Command = "ComfirmQty";
                         //action.LocaleMsg = Biz.L("璇风‘璁ゆ潯鐮乕{0}]鐨勬暟閲忔槸鍚︽纭�");
                         action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ComfirmQty", input.SN);
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
                 }
 
@@ -208,8 +205,8 @@
                         action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY });
                         action.Data.Command = Command = "ComfirmQty";
                         //action.LocaleMsg = Biz.L("鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紝璇烽噸鏂扮‘璁ゆ潯鐮乕{0}]鐨勬暟閲�");
-                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmQty", input.SN); 
-                        return action;
+                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmQty", input.SN);
+                        return SetOutPutMqttMsg(action, input.Locale);
                     } 
                     else
                     {
@@ -235,7 +232,7 @@
                     {
                         action.IsSuccessed = false;
                         action.LocaleMsg = Biz.L(shelfApiResult.GetData<string>());
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
                     var reaultShelf = shelfApiResult.GetData<ShelfChangeModel>();
 
@@ -245,7 +242,7 @@
                         action.IsSuccessed = false;
                         //action.LocaleMsg = Biz.L($"璐ф灦[{0}]涓笉瀛樺湪id涓篬{1}]鐨勫偍浣嶏紝璇峰厛缁存姢璐ф灦淇℃伅");
                         action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationNotExistsInShelf", CurScanShelf.Shelf.SHELF_CODE, reaultShelf.ledAddr);
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
                     var locationData = MainDB.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.ID).First();
                     if (!locationData.IsNullOrEmpty())
@@ -253,7 +250,7 @@
                         action.IsSuccessed = false;
                         //action.LocaleMsg = Biz.L("鍌ㄤ綅[{0}]宸插瓨鏈夌墿鏂橻{1}]锛岃妫�鏌ョ郴缁熷簱瀛樹俊鎭�");
                         action.LocaleMsg = Biz.L($"WMS.Default.ScanShelf.ItemAlreadyExistsInLocation", nLocation.LOCATION_CODE, locationData.SN);
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
                     CurScanShelf.LocationCode = nLocation.LOCATION_CODE;
                 }
@@ -264,7 +261,7 @@
                         action.IsSuccessed = false;
                         //action.LocaleMsg = Biz.L("璇疯緭鍏ユ垨鎵弿鏈夋晥鐨勮揣鏋�/鍌ㄤ綅鐮�");
                         action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfCanNotEmpty");
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
 
                     nLocation = await MainDB.Queryable<WMS_LOCATION>().Where(t => t.LOCATION_CODE == CurScanShelf.LocationCode && t.AUTH_ORG == OrgCode).FirstAsync();
@@ -276,12 +273,17 @@
                     action.IsSuccessed = false;
                     //action.LocaleMsg = Biz.L("鍌ㄤ綅[{0}]鍙兘瀛樻斁涓�涓墿鏂�");
                     action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE);
-                    ResetScan();
-                    return action;
+                    ResetTrans();
+                    return SetOutPutMqttMsg(action, input.Locale);
                 }
 
                 //鎵ц涓婃灦鏁版嵁澶勭悊
                 foreach (var item in CurInvItem.Items)
+                {
+                    item.TRANS_CODE = "In_Default";
+                    item.TRANS_NO = $"In_Default_{DateTime.Now:yyyyMMdd}";
+                }
+                foreach (var item in CurInvItem.Packages)
                 {
                     item.TRANS_CODE = "In_Default";
                     item.TRANS_NO = $"In_Default_{DateTime.Now:yyyyMMdd}";
@@ -291,8 +293,8 @@
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = putonResult.LocaleMsg;
-                    ResetScan();
-                    return action;
+                    ResetTrans();
+                    return SetOutPutMqttMsg(action, input.Locale);
                 }
 
                 //瀹屾垚鎵�鏈夊鐞嗗悗浣跨敤浜嬪姟淇濆瓨鏁版嵁
@@ -301,11 +303,11 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{input.SN}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
-            return action;
+            return SetOutPutMqttMsg(action, input.Locale);
         }
 
         /// <summary>
@@ -392,7 +394,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿璐ф灦/鍌ㄤ綅[{0}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
             }
@@ -403,11 +405,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();
+
+            //淇濆瓨鏁版嵁鎴愬姛鍚庢墽琛�
+            doAfterSave?.Invoke();
 
             // 杩斿洖鏁版嵁
             action.Data.Data = new DefaultInStoreOutput
@@ -429,17 +436,17 @@
 
             //閲嶇疆鎵爜淇℃伅
             ResetScanInfo();
-            return action;
+            return SetOutPutMqttMsg(action, locale);
         }
 
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetScan()
+        public override void ResetTrans()
         {
-            base.ResetScan();
+            base.ResetTrans();
             ResetScanInfo();
             CurScanShelf = null;
         }

--
Gitblit v1.9.3