From 1d61b45846ac2e5cb0a8366365613c44c1319289 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 26 三月 2025 18:06:17 +0800
Subject: [PATCH] 优化收货单上架行数量判断

---
 Tiger.Business.WMS/Transaction/In_SemiProd.cs |  214 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 198 insertions(+), 16 deletions(-)

diff --git a/Tiger.Business.WMS/Transaction/In_SemiProd.cs b/Tiger.Business.WMS/Transaction/In_SemiProd.cs
index 88742fa..8b103a4 100644
--- a/Tiger.Business.WMS/Transaction/In_SemiProd.cs
+++ b/Tiger.Business.WMS/Transaction/In_SemiProd.cs
@@ -18,6 +18,9 @@
 using System.Diagnostics;
 using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser;
 using Tiger.Model.Entitys.MES.U9C;
+using Tiger.Model.Entitys.MES.BizPrintInstoreDoc;
+using Tiger.Model.Entitys.MES.Position;
+using IronPython.Runtime.Operations;
 
 namespace Tiger.Business.WMS.Transaction
 {
@@ -27,12 +30,14 @@
     public class In_SemiProd : WMSTransactionBase, IIn_SemiProd
     {
         private readonly IMES_U9C _IMES_U9C = DI.Resolve<IMES_U9C>();
-        public IIn_SemiProd Init(string id, string userCode, string apiHost, string orgCode)
+        public IIn_SemiProd Init(string id, string apiHost, InstoreDocInput input)
         {
             TransID = id;
-            UserCode = userCode;
+            UserCode = input.UserCode;
             ApiHost = apiHost;
-            OrgCode = orgCode;
+            OrgCode = input.OrgCode;
+            pageSize = input.pageSize;
+            _GetScannedList();
             Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
             return this;
         }
@@ -60,7 +65,7 @@
         /// <summary>
         /// 鎵弿鍏ュ彛
         /// </summary>
-        public async Task<ApiAction<ScanOutput>> Scan(BaseInput input)
+        public async Task<ApiAction<ScanOutput>> Submit(BaseInput input)
         {
             var action = new ApiAction<ScanOutput>(new ScanOutput());
             try
@@ -76,9 +81,11 @@
                 {
                     action.IsSuccessed = false;
                     action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.WoEmptyFailure", input.SN); // $"宸ュ崟[{input.SN}]涓嶅瓨鍦�"
-                    return action;
+                    return SetOutPutMqttMsg(action, input.Locale);
                 }
-                
+
+                var semiTemplateQty = (input.Data ?? "").JsonToObject<SemiTemplateQty>() ?? new SemiTemplateQty();
+
                 InStoreInfo Info = new()
                 {
                     ErpProdInBth = new()
@@ -89,7 +96,8 @@
                         ITEM_CODE = wo.ITEM_CODE,
                         ITEM_NAME = wo.ItemInfo?.ITEM_DESC,
                         SapCode = wo.ItemInfo?.ExtInfo?.SapCode,
-                        SCAN_QTY = input.Data.ToInt32(),
+                        SCAN_QTY = semiTemplateQty.PackQty,
+                        CompleteQty = semiTemplateQty.CompleteQty,
                         IS_HANDLED = "N" //Y-宸茬敓鎴愶紝N-鏈敓鎴愶紝F-澶辫触
                     },
                     InStoreScanInfo = new()
@@ -98,7 +106,7 @@
                         SALES_ORDER = wo.SALES_ORDER,
                         WORK_ORDER = wo.ORDER_NO,
                         BATCH_NO = "",
-                        SCAN_QTY = input.Data.ToInt32()
+                        SCAN_QTY = semiTemplateQty.PackQty.ToDouble()
                     }
                 };
 
@@ -218,7 +226,8 @@
                 };
 
                 action.Data.Data = inStoreInfos;
-                action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.ScanSuccessed"); //$"宸ュ崟鏉$爜[{input.SN}]鎵弿鎴愬姛锛岃濉叆宸ュ崟鏁伴噺鍚庣偣鎻愪氦"
+                action.Data.Command = "";
+                action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.ScanSuccessed", input.SN); //$"宸ュ崟鏉$爜[{input.SN}]鎵弿鎴愬姛锛岃濉叆宸ュ崟鏁伴噺鍚庣偣鎻愪氦"
             }
             catch (Exception ex)
             {
@@ -228,20 +237,123 @@
             return SetOutPutMqttMsg(action, input.Locale);
         }
 
-        public async Task<ApiAction<ScanOutput>> ScanItem(BaseInput input)
+        public ApiAction<InStoreInfos> GetInStoreInfos()
         {
-            var action = new ApiAction<ScanOutput>(new ScanOutput());
+            return new() { Data = inStoreInfos };
+        }
+
+
+        /// <summary>
+        /// 鏌ヨ宸叉壂鎻忓垪琛�
+        /// </summary>
+        /// <returns></returns>
+        public async Task<ApiAction<InStoreInfos>> GetScannedList()
+        {
+            var action = new ApiAction<InStoreInfos>();
             try
             {
-                
+                _GetScannedList();
+                action.Data = inStoreInfos;
             }
             catch (Exception ex)
             {
-                action.CatchExceptionWithLog(ex, Biz.L("鍗婃垚鍝佸叆搴撳け璐�"));
+                action.CatchExceptionWithLog(ex, $"鏌ヨ宸叉壂鎻忓垪琛ㄥ紓甯�");
             }
             return action;
         }
 
+        /// <summary>
+        /// 浠庢暟鎹簱璇诲洖鎿嶄綔鑰呭師鏈搷浣滅殑璁板綍
+        /// </summary>
+        /// <returns></returns>
+        private RcvRptDocCreateInput _GetScannedList()
+        {
+            RcvRptInput.RcvRptDocBases = new();
+            RcvRptInput.ErpProdInBths = new();
+            RcvRptInput.PrintJsons = new();
+            RcvRptInput.labels = new();
+            RcvRptInput.userId = UserCode;
+            ErpProdInSns.Clear();
+            ErpProdIns.Clear();
+            ErpProdInBths.Clear();
+            InStoreScanInfos.Clear();
+            RcvRptInput.ErpProdInBths = Biz.Db.Queryable<BIZ_ERP_PROD_IN_BTH>()
+                .Where(q => q.BATCH_NO == SqlFunc.Subqueryable<BIZ_ERP_PROD_IN_BTH>().Where(s => s.ORDER_NO == UserCode && s.GHOST_ROW == false).Select(s => s.BATCH_NO) && q.IS_HANDLED == "N")
+                .IncludesAllFirstLayer().ToList();
+            foreach (var item in RcvRptInput.ErpProdInBths)
+            {
+                var values = item.ProdInSns.GroupBy(x => x.CARTONNO)
+                    .Select(g => new InStoreScanInfo() { SN = g.Key, SALES_ORDER = item.SALES_ORDER, BATCH_NO = item.BATCH_NO, WORK_ORDER = item.WORK_ORDER, SCAN_QTY = g.Sum(x => x.Qty).ToDouble() });
+                foreach (var t in values)
+                {
+                    InStoreScanInfos.Add(t);
+                }
+                item.CartonQty = values.Count();
+
+                ErpProdIns.Add(new()
+                {
+                    AUTH_ORG = OrgCode,
+                    BILLCODE = UserCode,
+                    BILLDATE = DateTime.Now,
+                    STATUS = 0,
+                    HANDLED = -1,
+                    WAREHOUSECODE = "",
+                    SOURCECODE = item.WORK_ORDER,
+                    HANDLED_DATE = DateTime.Now,
+                });
+                ErpProdInSns.AddRange(item.ProdInSns);
+
+                //鐢熸垚鎵撳嵃瀹炰綋
+                if (RcvRptInput.PrintJsons.Count == 0)
+                {
+                    RcvRptInput.PrintJsons.Add(new()
+                    {
+                        ID = Guid.NewGuid().ToString("N"),
+                        Items = new() {
+                            item
+                        }
+                    });
+                }
+                else
+                {
+                    //鎷煎垎椤�
+                    bool isAdded = false;
+                    foreach (var p in RcvRptInput.PrintJsons)
+                    {
+                        if (!p.Items.Any(q => q.WORK_ORDER == item.WORK_ORDER))
+                        {
+                            if (p.Items.Count < pageSize)
+                            {
+                                p.Items.Add(item);
+                                isAdded = true;
+                            }
+                        }
+                        else
+                        {
+                            isAdded = true;
+                        }
+                    }
+                    if (!isAdded)
+                    {
+                        RcvRptInput.PrintJsons.Add(new()
+                        {
+                            ID = Guid.NewGuid().ToString("N"),
+                            Items = new() {
+                            item
+                        }
+                        });
+                    }
+                }
+            }
+            ErpProdInBths = RcvRptInput.ErpProdInBths;
+
+            inStoreInfos = new()
+            {
+                ErpProdInBths = ErpProdInBths,
+                InStoreScanInfos = InStoreScanInfos,
+            };
+            return RcvRptInput;
+        }
 
         /// <summary>
         /// 璋冪敤U9C鎺ュ彛鐢熸垚鍏ュ簱鍗�
@@ -257,7 +369,7 @@
                 if (!RcvRptInput.ErpProdInBths.Any(q => q.IS_HANDLED == "N"))
                 {
                     action.IsSuccessed = false;
-                    action.LocaleMsg = Biz.L($"娌℃湁瑕佸叆搴撶殑浜у搧鏁版嵁锛岃鎵弿鍖呰瀹屾垚鐨勭浜岀淮鐮侀噸鏂扮敓鎴愬叆搴撳崟鎹紒");
+                    action.LocaleMsg = Biz.L($"娌℃湁瑕佸叆搴撶殑浜у搧鏁版嵁锛岃鎵弿宸ュ崟閲嶆柊鐢熸垚鍏ュ簱鍗曟嵁锛�");
                     return action;
                 }
                 if (RcvRptInput.RcvRptDocBases.IsNullOrEmpty() || RcvRptInput.RcvRptDocBases.Count == 0)
@@ -269,8 +381,8 @@
                             WorkOrder = item.WORK_ORDER,
                             ItemCode = item.ITEM_CODE,
                             WhCode = "10105",
-                            PkgQty = item.SCAN_QTY.ToInt32(),
-                            CompleteQty = item.SCAN_QTY.ToInt32(),
+                            PkgQty = item.SCAN_QTY,
+                            CompleteQty = item.CompleteQty,
                             OutputType = 0,
                             StorageType = 4,
                             DocState = 1,
@@ -340,6 +452,76 @@
             return action;
         }
 
+        /// <summary>
+        /// 娓呴櫎
+        /// </summary>
+        /// <returns></returns>
+        public async Task<ApiAction> Clear()
+        {
+            var action = new ApiAction();
+            try
+            {
+                RcvRptInput = new();
+                ProdInBatchs = new() { };
+                ErpProdInBths = new() { };
+                ErpProdIns = new();
+                /// <summary>
+                /// 鎵弿鍒楄〃 
+                /// </summary>
+                InStoreScanInfos = new() { };
+                ErpProdInSns = new();
+                inStoreInfos = new() { };
+
+                //涓存椂浠g爜锛屾祴璇曠敤
+                //DbClient _db = Biz.DataSource["YadaU9C"].Client;
+                //var items = Biz.Db.Queryable<WMS_ITEM>().Where(q => SqlFunc.IsNullOrEmpty(q.SUPP_LOTNO)).ToList();
+                //var snlist = items.Select(q => q.SN).ToList();
+                ////var list = _db.Ado.SqlQuery<mes_MaterialBarCodeByBin>($"select *,cast('{DateTime.Now.ToString("yyyy-MM-dd")}' as DATETIME) as PROD_DATE,'' as Unit,'' as LotNo from mes_MaterialBarCodeByBin where Code in ({string.Join(',', snlist.Select(x=> $"'{x}'"))})");
+                //var list = _db.Queryable<mes_MaterialBarCode>().Where(q => snlist.Contains(q.Code)).ToList();
+                //foreach (var item in list)
+                //{
+                //    var wmsitem = items.Where(q => q.SN == item.Code).FirstOrDefault();
+                //    if (!wmsitem.IsNullOrEmpty())
+                //    {
+                //        wmsitem.SUPP_LOTNO = item.Segment7;
+                //    }
+                //}
+
+
+                ////淇濆瓨鏁版嵁搴�
+                //var db = Business.Biz.Db;
+                //var dbTran = db.UseTran(() =>
+                //{
+                //    db.Updateable(items).UpdateColumns(q => new { q.SUPP_LOTNO }).ExecuteCommand();
+                //});
+                //if (!dbTran.IsSuccess)
+                //{
+                //    Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
+                //    this.Close(!dbTran.IsSuccess);
+                //    throw dbTran.ErrorException;
+                //}
+
+                //淇濆瓨鏁版嵁搴�
+                var db = Business.Biz.Db;
+                var dbTran = db.UseTran(() =>
+                {
+                    db.Deleteable<BIZ_ERP_PROD_IN_BTH>().Where(x => x.ORDER_NO == UserCode && x.IS_HANDLED == "N").ExecuteCommand();
+                    db.Deleteable<BIZ_ERP_PROD_IN_SN>().Where(x => x.BUSINESSCODE == UserCode).ExecuteCommand();
+                });
+                if (!dbTran.IsSuccess)
+                {
+                    Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception");
+                    this.Close(!dbTran.IsSuccess);
+                    throw dbTran.ErrorException;
+                }
+            }
+            catch (Exception ex)
+            {
+                action.CatchExceptionWithLog(ex, $"鏌ヨ宸叉壂鎻忓垪琛ㄥ紓甯�");
+            }
+            return action;
+        }
+
         #endregion
 
         public override bool Close(bool needSaveHistoryLog = false)

--
Gitblit v1.9.3