From 40df5d91f800bb8b7be2638c13b4f9292d461221 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期一, 10 三月 2025 18:13:50 +0800
Subject: [PATCH] 增加送货单清点事务

---
 Tiger.Business.WMS/Transaction/In_Default.cs |  142 ++++++++++++++++++++++-------------------------
 1 files changed, 66 insertions(+), 76 deletions(-)

diff --git a/Tiger.Business.WMS/Transaction/In_Default.cs b/Tiger.Business.WMS/Transaction/In_Default.cs
index f8ab470..2e04e35 100644
--- a/Tiger.Business.WMS/Transaction/In_Default.cs
+++ b/Tiger.Business.WMS/Transaction/In_Default.cs
@@ -11,35 +11,25 @@
 using Tiger.IBusiness;
 using Tiger.Model.Sharetronic.Shelf;
 using Tiger.Business.WMS.Sharetronic.Shelf;
-using Microsoft.IdentityModel.Tokens;
-using Apache.NMS.ActiveMQ.Commands;
+//using Microsoft.IdentityModel.Tokens;
 using Tiger.Model.MES.Yada;
-using Tiger.Model.Entitys.MES.Position;
 
 namespace Tiger.Business.WMS.Transaction
 {
     /// <summary>
     /// 鏍囧噯涓婃灦浜嬪姟
     /// </summary>
-    public class In_Default : WMSTransactionBase, IIn_Default
+    public class In_Default : WmsTask, IIn_Default
     {
         public IIn_Default Init(string id, string userCode, string apiHost, string orgCode)
         {
-            TransID = id;
-            UserCode = userCode;
-            ApiHost = apiHost;
-            OrgCode = orgCode;
+            base.Init(id, apiHost, userCode, orgCode);
             Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
             return this;
         }
 
         #region Propertys & Variables
-        public string UserCode { get; set; }
-        public long UserId { get; set; }
-        public string OrgCode { get; set; }
-        public Inventory CurInvItem { get; set; }
-        public ScanShelfInfo CurScanShelf { get; set; }
-        public string Command { get; set; } = "Normal";
+        
         #endregion
 
         #region Functions
@@ -59,7 +49,7 @@
                     return SetOutPutMqttMsg(action, input.Locale);
                 }
                 //鍒ゆ柇鎵弿鐨勬槸鍚﹁揣鏋�
-                var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == input.SN || t.LOCATION_CODE.ToUpper() == input.SN) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
+                var whUnit = await MainDB.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == input.SN || t.LOCATION_CODE.ToUpper() == input.SN) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
                 //if (string.IsNullOrEmpty(CurScanShelf?.ShelfCode))
                 if (!whUnit.IsNullOrEmpty() || string.IsNullOrEmpty(CurScanShelf?.ShelfCode))
                 {
@@ -73,7 +63,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetInfo();
+                ResetScan();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -129,7 +119,7 @@
                             ITEM_CODE = inv.Barcode.ItemCode,
                             AUTH_ORG = input.AuthOption.CurOrg,
                             STATUS = WMS_ITEM.STATUSs.WaitIn.GetValue(),
-                            QTY = inv.Barcode.Qty.ToDecimal(),
+                            QTY = inv.Barcode.Qty.ToDouble(),
                             PROD_DATE = inv.Barcode.DateCode.ToDateTime(),
                             ERP_WH = CurScanShelf.WarehouseCode,
                             UNIT = inv.Barcode.Unit,
@@ -142,7 +132,7 @@
                             SN = inv.Barcode.SN,
                             AUTH_ORG = input.AuthOption.CurOrg,
                             ITEM_CODE = inv.Barcode.ItemCode,
-                            QTY = inv.Barcode.Qty.ToDecimal(),
+                            QTY = inv.Barcode.Qty.ToDouble(),
                             ERP_WH = CurScanShelf.WarehouseCode,
                             UNIT = inv.Barcode.Unit,
                         };
@@ -163,16 +153,17 @@
                         inv.History.Add(his);
                         inv.Packages.Add(ItemPkgs);
                     }
-                    else if (inv.Items.Count == 1)
-                    {
-                        inv.Items.First().QTY = inv.Barcode.Qty.ToDecimal();
-                        inv.Items.First().ERP_WH = CurScanShelf.WarehouseCode;
-                        inv.Items.First().AUTH_ORG = input.AuthOption.CurOrg;
+                    //闆呰揪涓嶄粠鏉$爜涓婃洿鏂版暟閲�
+                    //else if (inv.Items.Count == 1)
+                    //{
+                    //    inv.Items.First().QTY = inv.Barcode.Qty.ToDouble();
+                    //    inv.Items.First().ERP_WH = CurScanShelf.WarehouseCode;
+                    //    inv.Items.First().AUTH_ORG = input.AuthOption.CurOrg;
 
-                        inv.Packages.First().QTY = inv.Barcode.Qty.ToDecimal();
-                        inv.Packages.First().ERP_WH = CurScanShelf.WarehouseCode;
-                        inv.Packages.First().AUTH_ORG = input.AuthOption.CurOrg;
-                    }
+                    //    inv.Packages.First().QTY = inv.Barcode.Qty.ToDouble();
+                    //    inv.Packages.First().ERP_WH = CurScanShelf.WarehouseCode;
+                    //    inv.Packages.First().AUTH_ORG = input.AuthOption.CurOrg;
+                    //}
                     //濡傛灉鎵弿澶栫鐨勪笉鑳芥洿鏂版暟閲�
                     else
                     {
@@ -255,7 +246,7 @@
                         action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationNotExistsInShelf", CurScanShelf.Shelf.SHELF_CODE, reaultShelf.ledAddr);
                         return action;
                     }
-                    var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.ID).First();
+                    var locationData = MainDB.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.ID).First();
                     if (!locationData.IsNullOrEmpty())
                     {
                         action.IsSuccessed = false;
@@ -275,7 +266,7 @@
                         return action;
                     }
 
-                    nLocation = await Biz.Db.Queryable<WMS_LOCATION>().Where(t => t.LOCATION_CODE == CurScanShelf.LocationCode && t.AUTH_ORG == OrgCode).FirstAsync();
+                    nLocation = await MainDB.Queryable<WMS_LOCATION>().Where(t => t.LOCATION_CODE == CurScanShelf.LocationCode && t.AUTH_ORG == OrgCode).FirstAsync();
                 }
 
                 //鍒ゆ柇鍌ㄤ綅鏄惁鍗曟斁
@@ -284,66 +275,32 @@
                     action.IsSuccessed = false;
                     //action.LocaleMsg = Biz.L("鍌ㄤ綅[{0}]鍙兘瀛樻斁涓�涓墿鏂�");
                     action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE);
-                    CurInvItem = null;
+                    ResetScan();
                     return action;
                 }
 
-                //鎵ц涓婃灦
+                //鎵ц涓婃灦鏁版嵁澶勭悊
                 foreach (var item in CurInvItem.Items)
                 {
                     item.TRANS_CODE = "In_Default";
                     item.TRANS_NO = $"In_Default_{DateTime.Now:yyyyMMdd}";
                 }
-                Result<PutOnInfo> putonResult = WMS_ITEM_Biz.WmsItem.PutOn(CurInvItem, input.AuthOption, nLocation.LOCATION_CODE);
+                Result putonResult = PutOn(input.AuthOption, nLocation.LOCATION_CODE);
                 if (!putonResult.IsSuccessed)
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = putonResult.LocaleMsg;
-                    CurInvItem = null;
+                    ResetScan();
                     return action;
                 }
-                PutOnInfo putOnInfo = putonResult.Data;
 
-                //淇濆瓨鍒版暟鎹簱
-                var db = Business.Biz.Db;
-                var dbTran = db.UseTran(() =>
-                {
-                    //鍏ュ簱
-                    db.Storageable(putOnInfo.Items, UserCode).ExecuteCommand();
-                    db.Storageable(putOnInfo.Packages, UserCode).ExecuteCommand();
-                    db.Insertable(putOnInfo.History, UserCode).ExecuteCommand();
-                    var x = db.Storageable(putOnInfo.ItemsExt, UserCode).ToStorage();
-                    x.AsInsertable.ExecuteCommand();//涓嶅瓨鍦ㄦ彃鍏�
-                    x.AsUpdateable.ExecuteCommand();//瀛樺湪鏇存柊
-                });
-                if (!dbTran.IsSuccess)
-                {
-                    Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
-                    throw dbTran.ErrorException;
-                }
-                // 杩斿洖鍏朵粬鍏ュ簱瀵硅薄
-                action.Data.Data = new DefaultInStoreOutput
-                {
-                    Barcode = CurInvItem.SN,
-                    MaterialCode = CurInvItem.ItemInfo.ITEM_CODE,
-                    MaterialName = CurInvItem.ItemInfo.ITEM_NAME,
-                    CurrentQty = CurInvItem.Items[0].QTY,
-                    Unit = CurInvItem.Items[0].UNIT,
-                    DateCode = CurInvItem.Items[0].PROD_DATE,
-                    WarehouseCode = putOnInfo.Warehouse.WH_CODE,
-                    RegionCode = putOnInfo.Region.REGION_CODE,
-                    ShelfCode = putOnInfo.Shelf.SHELF_CODE,
-                    LocationCode = putOnInfo.Location.LOCATION_CODE,
-                };
-
-                //action.LocaleMsg = Biz.L($"鎵弿鏉$爜[{0}]涓婃灦鍒板偍浣峓{1}]鎴愬姛");
-                action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, putOnInfo.Location.LOCATION_CODE);
-                CurInvItem = null;
+                //瀹屾垚鎵�鏈夊鐞嗗悗浣跨敤浜嬪姟淇濆瓨鏁版嵁
+                action = DoIfFinish(action, input.Locale);
             }
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetInfo();
+                ResetScan();
                 //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{input.SN}]澶嶆牳寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
             }
@@ -369,7 +326,7 @@
                 CurScanShelf = new ScanShelfInfo();
 
                 // 鏌ヨ璐ф灦淇℃伅
-                whUnit = whUnit.IsNullOrEmpty(await Biz.Db.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == Code || t.LOCATION_CODE.ToUpper() == Code) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync());
+                whUnit = whUnit.IsNullOrEmpty(await MainDB.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == Code || t.LOCATION_CODE.ToUpper() == Code) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync());
 
                 // 鎵弿璐ф灦浠g爜锛屼笖涓烘櫤鑳借揣鏋�
                 if (!whUnit.IsNullOrEmpty() && whUnit.SHELF_CODE  == Code)
@@ -384,7 +341,7 @@
                 // 鎵弿搴撲綅浠g爜
                 else if (!whUnit.IsNullOrEmpty() && whUnit.LOCATION_CODE == Code)
                 {
-                    //var nLocation = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
+                    //var nLocation = await MainDB.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
                     //if (nLocation == null)
                     //{
                     //    action.IsSuccessed = false;
@@ -401,7 +358,7 @@
                     }
                     if (whUnit.Shelf.IsLightShelf || whUnit.Location.IS_SINGLE == "Y")
                     {
-                        var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == whUnit.LOCATION_ID && q.AUTH_ORG == OrgCode).First();
+                        var locationData = MainDB.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == whUnit.LOCATION_ID && q.AUTH_ORG == OrgCode).First();
                         if (!locationData.IsNullOrEmpty())
                         {
                             action.IsSuccessed = false;
@@ -434,10 +391,43 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetInfo();
+                ResetScan();
                 //action.CatchExceptionWithLog(ex, $"鎵弿璐ф灦/鍌ㄤ綅[{0}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
             }
+            return action;
+        }
+
+        /// <summary>
+        /// 瀹屾垚鎵�鏈夊鐞嗗悗浣跨敤浜嬪姟淇濆瓨鏁版嵁
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        public ApiAction<ScanOutput> DoIfFinish(ApiAction<ScanOutput> action, string locale)
+        {
+            //淇濆瓨鏁版嵁搴�
+            SaveCommitListToDB();
+
+            // 杩斿洖鏁版嵁
+            action.Data.Data = new DefaultInStoreOutput
+            {
+                Barcode = CurInvItem.SN,
+                MaterialCode = CurInvItem.ItemInfo.ITEM_CODE,
+                MaterialName = CurInvItem.ItemInfo.ITEM_NAME,
+                CurrentQty = CurInvItem.Items[0].QTY,
+                Unit = CurInvItem.Items[0].UNIT,
+                DateCode = CurInvItem.Items[0].PROD_DATE,
+                WarehouseCode = CurInvItem.Warehouse.WH_CODE,
+                RegionCode = CurInvItem.Region.REGION_CODE,
+                ShelfCode = CurInvItem.Shelf.SHELF_CODE,
+                LocationCode = CurInvItem.Location.LOCATION_CODE,
+            };
+
+            //action.LocaleMsg = Biz.L($"鎵弿鏉$爜[{0}]涓婃灦鍒板偍浣峓{1}]鎴愬姛");
+            action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, CurInvItem.Location.LOCATION_CODE);
+
+            //閲嶇疆宸ュ簭
+            ResetScan();
             return action;
         }
 
@@ -446,9 +436,9 @@
         /// <summary>
         /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetInfo()
+        public override void ResetScan()
         {
-            base.ResetInfo();
+            base.ResetScan();
             Command = null;
             CurInvItem = null;
             CurScanShelf = null;

--
Gitblit v1.9.3