From c6342a8eb6d2c40e9a21deab63b5babb3def3025 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期日, 13 四月 2025 17:14:50 +0800
Subject: [PATCH] 物料扩展表增加字段 上架需要按物料的默认储位进行限制,不允许上架到其他储位 没有默认储位则不限制,需要记录并调用接口反写到U9

---
 Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs |  152 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 106 insertions(+), 46 deletions(-)

diff --git a/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs b/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs
index aacb9ab..a034d84 100644
--- a/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs
+++ b/Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs
@@ -12,6 +12,8 @@
 using Tiger.Model.Sharetronic.Shelf;
 using Tiger.Business.WMS.Sharetronic.Shelf;
 using Tiger.Model.Entitys.MES.U9C;
+using Tiger.Model.MES.Yada;
+using static IronPython.Modules._ast;
 
 namespace Tiger.Business.WMS.Transaction
 {
@@ -62,7 +64,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿[{input.SN}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
             }
@@ -80,14 +82,14 @@
                 if (CurInvItem.IsNullOrEmpty())
                 {
                     //瑙f瀽鏉$爜
-                    Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
-	                if (!result.IsSuccessed)
-	                {
-	                    action.IsSuccessed = false;
-	                    action.LocaleMsg = result.LocaleMsg;
-	                    return action;
-	                }
-	                var inv = result.Data as Inventory;
+                    Result<IInventory> result = GetInventory(input.SN, input.AuthOption, true);
+                    if (!result.IsSuccessed)
+                    {
+                        action.IsSuccessed = false;
+                        action.LocaleMsg = result.LocaleMsg;
+                        return SetOutPutMqttMsg(action, input.Locale);
+                    }
+                    var inv = result.Data as Inventory;
 
                     //楠岃瘉鏉$爜鏄惁姝g‘
                     if (!inv.isNormalStatus || inv.Status != WMS_ITEM.STATUSs.WaitIn)
@@ -95,7 +97,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")
@@ -103,18 +105,26 @@
                         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.ItemInfo.DEFAULT_LOCATION.IsNullOrEmpty() && inv.ItemInfo.DEFAULT_LOCATION != CurScanShelf.LocationCode)
+                    {
+	                    action.IsSuccessed = false;
+	                    //action.LocaleMsg = Biz.L("鐗╂枡[{0}]鍙厑璁镐笂鏋跺埌鍌ㄤ綅[{0}]锛岃閲嶆柊鎵弿鍌ㄤ綅");
+	                    action.LocaleMsg = Biz.L("WMS.Default.ScanItem.DefaultLocationError", inv.ItemInfo.ITEM_CODE, inv.ItemInfo.DEFAULT_LOCATION);
+	                    return SetOutPutMqttMsg(action, input.Locale);
                     }
                     CurInvItem = inv;
                 }
 
-                var receipt = await Biz.Db.Queryable<BIZ_U9_RECEIPT>().Where(q => q.ORDER_NO == CurInvItem.Items.First().TRANS_NO).IncludesAllFirstLayer().FirstAsync();
+                var receipt = await MainDB.Queryable<BIZ_U9_RECEIPT>().Where(q => q.ORDER_NO == CurInvItem.Items.First().TRANS_NO).IncludesAllFirstLayer().FirstAsync();
                 if (receipt.IsNullOrEmpty())
                 {
                     action.IsSuccessed = false;
                     //action.LocaleMsg = Biz.L("鏀惰揣鍗曚腑鎵句笉鍒版潯鐮佹墍灞炵殑鍗曟嵁[{0}]淇℃伅锛岃閲嶆柊鎵弿鏀惰揣鍗曠殑鏉$爜鎴栭�夋嫨姝g‘鐨勫姛鑳戒笂鏋�");
                     action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.ReceiptNotExists", CurInvItem.Items.First().TRANS_NO);
-                    return action;
+                    return SetOutPutMqttMsg(action, input.Locale);
                 }
                 var receiptDtl = receipt.Details.First(q => q.LINE_NO == CurInvItem.Items.First().TRANS_LINE);
                 if (receiptDtl.STATUS > BIZ_U9_RECEIPT.STATUSs.Storing.GetValue())
@@ -122,7 +132,7 @@
                     action.IsSuccessed = false;
                     //action.LocaleMsg = Biz.L("鏀惰揣鍗曚腑琛孾{0}]鐘舵�乕{1}]寮傚父锛岃鎵弿姝g‘鐨勬潯鐮�");
                     action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.ReceiptDtlStatusException", receiptDtl.LINE_NO, receiptDtl.STATUS.GetEnumDesc<BIZ_U9_RECEIPT.STATUSs>());
-                    return action;
+                    return SetOutPutMqttMsg(action, input.Locale);
                 }
                 var receiptSn = receipt.SnList.Where(q => CurInvItem.Items.Any(i => i.SN == q.SN)).ToList();
                 if (receiptSn.Any(q => q.STATUS != WMS_ITEM.STATUSs.WaitIn.GetValue()))
@@ -130,7 +140,25 @@
                     action.IsSuccessed = false;
                     //action.LocaleMsg = Biz.L("鏀惰揣鍗曚腑鏉$爜[{0}]鐘舵�乕{1}]寮傚父锛岃鎵弿姝g‘鐨勬潯鐮�");
                     action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.ReceiptSnStatusException", CurInvItem.SN, receiptSn.First(q => q.STATUS != WMS_ITEM.STATUSs.WaitIn.GetValue()).STATUS.GetEnumDesc<WMS_ITEM.STATUSs>());
-                    return action;
+                    return SetOutPutMqttMsg(action, input.Locale);
+                }
+                //浠嶶9鑾峰彇鏀惰揣鍗曡淇℃伅
+                var u9Dtl = Biz.DataSource["YadaU9C"].Client.Queryable<mes_ReturnedDocInfo>().Where(x => x.RcvId == receipt.ID.ToDouble() && x.DocLineNo == receiptDtl.LINE_NO.ToDouble() && x.SplitFlag != 1).First();
+                //鏀惰揣鍗曠殑鐘舵�佸垽鏂槸鍚﹀凡鎻愪氦IQC瀹℃牳锛屾湭閫氳繃IQC涓嶈兘涓婃灦
+                if (!u9Dtl.IsNullOrEmpty() && u9Dtl.Status != 3)
+                {
+                    action.IsSuccessed = false;
+                    //action.LocaleMsg = Biz.L("鏀惰揣鍗曡鐘舵�乕{0}]寮傚父锛岃鍏堟彁浜QC妫�楠岀粨鏋�");
+                    action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.U9StatusException", u9Dtl.StatusName);
+                    return SetOutPutMqttMsg(action, input.Locale);
+                }
+                if (!u9Dtl.IsNullOrEmpty() && u9Dtl.RcvQtyTU != receiptDtl.QTY_OK)
+                {
+                    receiptDtl.ID = u9Dtl.RcvLineId.ToString();
+                    receiptDtl.QTY_OK = u9Dtl.RcvQtyTU;
+                    receiptDtl.QTY_NG = receiptDtl.QTY - receiptDtl.QTY_OK;
+                    receiptDtl.ERP_STATUS_CODE = u9Dtl.Status.ToString();
+                    receiptDtl.ERP_STATUS_NAME = u9Dtl.StatusName;
                 }
 
                 var nLocation = new WMS_LOCATION();
@@ -142,7 +170,7 @@
                     {
                         action.IsSuccessed = false;
                         action.LocaleMsg = Biz.L(shelfApiResult.GetData<string>());
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
                     }
                     var reaultShelf = shelfApiResult.GetData<ShelfChangeModel>();
 
@@ -152,7 +180,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())
@@ -160,8 +188,9 @@
                         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.Location = nLocation;
                     CurScanShelf.LocationCode = nLocation.LOCATION_CODE;
                 }
                 else
@@ -171,7 +200,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();
@@ -183,8 +212,8 @@
                     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);
                 }
 
                 //鎵ц涓婃灦鏁版嵁澶勭悊
@@ -197,28 +226,39 @@
                     item.TRANS_CODE = nameof(BIZ_U9_RECEIPT);
                     item.TRANS_NO = receipt.ORDER_NO;
                     item.TRANS_LINE = receiptDtl.LINE_NO;
+                    item.PROD_DATE = item.PROD_DATE < new DateTime(2000, 1, 1) ? DateTime.Now : item.PROD_DATE;
+                    item.FIRST_IN_DATE = item.FIRST_IN_DATE < new DateTime(2000, 1, 1) ? DateTime.Now : item.FIRST_IN_DATE;
+                }
+                foreach (var item in CurInvItem.Packages)
+                {
+                    item.SOURCE_CODE = item.TRANS_CODE;
+                    item.SOURCE_ORDER = item.TRANS_NO;
+                    item.SOURCE_LINE = item.TRANS_LINE;
+                    item.TRANS_CODE = nameof(BIZ_U9_RECEIPT);
+                    item.TRANS_NO = receipt.ORDER_NO;
+                    item.TRANS_LINE = receiptDtl.LINE_NO;
                 }
                 Result putonResult = PutOn(input.AuthOption, nLocation.LOCATION_CODE);
                 if (!putonResult.IsSuccessed)
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = putonResult.LocaleMsg;
-                    ResetScan();
-                    return action;
+                    ResetTrans();
+                    return SetOutPutMqttMsg(action, input.Locale);
                 }
 
                 //鏇存柊鍗曟嵁淇℃伅
-                foreach(var sn in receiptSn)
+                foreach (var sn in receiptSn)
                 {
                     sn.STATUS = WMS_ITEM.STATUSs.InStore.GetValue();
                     sn.IS_IN = "Y";
                 }
                 //濡傛灉褰撳墠琛屼笂鏋跺畬鎴愭爣璁颁负寰呭鏍�
-                receiptDtl.QTY_IN = receipt.SnList.Where(q => q.LINE_NO == receiptDtl.LINE_NO).Sum(q => q.QTY);
-                if (receiptDtl.QTY_IN == receiptDtl.QTY)
+                receiptDtl.QTY_IN = receipt.SnList.Where(q => q.LINE_NO == receiptDtl.LINE_NO && q.STATUS == WMS_ITEM.STATUSs.InStore.GetValue()).Sum(q => q.QTY);
+                if (receiptDtl.QTY_IN == receiptDtl.QTY_OK)
                 {
                     receiptDtl.STATUS = BIZ_U9_RECEIPT.STATUSs.Review.GetValue();
-                    //褰撳墠鍗曟嵁鏄庣粏宸茬粡鍏ㄩ儴涓婃灦瀹屾垚锛屽彲浠ヨ皟鐢║9琛屽鎺ュ彛
+                    //褰撳墠鍗曟嵁鏄庣粏琛屽凡缁忓叏閮ㄤ笂鏋跺畬鎴愶紝鍙互璋冪敤U9琛屽鎺ュ彛锛屽鏋滆瀹″け璐ュ垯鎶ラ敊锛屾渶鍚庝竴涓笂鏋跺け璐�
                     var iInput = new SubmitLineInput
                     {
                         userId = UserCode,
@@ -236,21 +276,29 @@
                     {
                         action.IsSuccessed = false;
                         action.LocaleMsg = result.LocaleMsg;
-                        return action;
+                        return SetOutPutMqttMsg(action, input.Locale);
+                    }
+                    else
+                    {
+                        receiptDtl.STATUS = BIZ_U9_RECEIPT.STATUSs.Finished.GetValue();
                     }
                 }
                 else
                 {
                     receiptDtl.STATUS = BIZ_U9_RECEIPT.STATUSs.Storing.GetValue();
                 }
-                var dtlStatus = receipt.Details.Select(q => q.STATUS).Distinct();
-                if (dtlStatus.Count() == 1 && dtlStatus.First() == BIZ_U9_RECEIPT.STATUSs.Review.GetValue())
+                //鏇存柊鍗曟嵁鐘舵��
+                if (receipt.Details.Any(q => q.STATUS < BIZ_U9_RECEIPT.STATUSs.Review.GetValue()))
+                {
+                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Storing.GetValue();
+                }
+                else if (receipt.Details.Any(q => q.STATUS < BIZ_U9_RECEIPT.STATUSs.Finished.GetValue()))
                 {
                     receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Review.GetValue();
                 }
                 else
                 {
-                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Storing.GetValue();
+                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Finished.GetValue();
                 }
 
                 //鍒涘缓鍙橀噺鍏嬮殕瀵硅薄鐢ㄤ簬浼犲叆DBSubmitAction涓繚瀛樺綋鍓嶉渶瑕佹殏瀛樼殑鏁版嵁鍊�
@@ -261,21 +309,27 @@
                     var db = GetCommitDB();
                     //鏁版嵁淇濆瓨閫昏緫
                     db.Updateable(receipt, UserCode).UpdateColumns(q => new { q.STATUS, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
-                    db.Updateable(receiptDtl, UserCode).UpdateColumns(q => new { q.STATUS, q.QTY_IN, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
+                    db.Updateable(receiptDtl, UserCode).UpdateColumns(q => new { q.ID, q.STATUS, q.QTY_IN, q.QTY_OK, q.QTY_NG, q.ERP_STATUS_CODE, q.ERP_STATUS_NAME, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
                     db.Updateable(receiptSn, UserCode).UpdateColumns(q => new { q.STATUS, q.IS_IN, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
                 });
 
                 //瀹屾垚鎵�鏈夊鐞嗗悗浣跨敤浜嬪姟淇濆瓨鏁版嵁
-                action = DoIfFinish(action, input.Locale);
+                action = DoIfFinish(action, input.Locale, () => {
+                    //璁剧疆褰撳墠鐗╂枡鐨勯粯璁ゅ偍浣�
+                    if (CurInvItem.ItemInfo.DEFAULT_LOCATION.IsNullOrEmpty())
+                    {
+                        SetDefaultLocation(MainDB, CurInvItem.ItemInfo, nLocation);
+                    }
+                });
             }
             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>
@@ -362,7 +416,7 @@
             catch (Exception ex)
             {
                 //鍙栨秷褰撳墠鎿嶄綔
-                ResetScan();
+                ResetTrans();
                 //action.CatchExceptionWithLog(ex, $"鎵弿璐ф灦/鍌ㄤ綅[{0}]寮傚父");
                 action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
             }
@@ -373,11 +427,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
@@ -398,29 +457,30 @@
             action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, CurInvItem.Location.LOCATION_CODE);
 
             //閲嶇疆宸ュ簭
-            ResetScanInfo();
-            return action;
+            ResetScan();
+            return SetOutPutMqttMsg(action, locale);
         }
 
         #endregion
 
         /// <summary>
-        /// 閲嶇疆褰撳墠鎿嶄綔锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
+        /// 閲嶇疆浜嬪姟鏁版嵁锛屾湁闇�瑕佸垯閲嶅啓姝ゆ柟娉�
         /// </summary>
-        public override void ResetScan()
+        public override void ResetTrans()
         {
-            base.ResetScan();
-            ResetScanInfo();
+            ResetScan();
             CurScanShelf = null;
+            base.ResetTrans();
         }
 
         /// <summary>
-        /// 閲嶇疆鎵爜淇℃伅
+        /// 閲嶇疆鏈鎵爜淇℃伅
         /// </summary>
-        public void ResetScanInfo()
+        public override void ResetScan()
         {
-            Command = null;
+            Command = "Normal";
             CurInvItem = null;
+            base.ResetScan();
         }
 
         public override bool Close(bool needSaveHistoryLog = false)

--
Gitblit v1.9.3