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/WMS_ITEM_Biz.cs | 196 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 135 insertions(+), 61 deletions(-) diff --git a/Tiger.Business.WMS/WMS_ITEM_Biz.cs b/Tiger.Business.WMS/WMS_ITEM_Biz.cs index d0e5965..ea6dae1 100644 --- a/Tiger.Business.WMS/WMS_ITEM_Biz.cs +++ b/Tiger.Business.WMS/WMS_ITEM_Biz.cs @@ -31,16 +31,21 @@ /// <param name="option">鎺堟潈鏌ヨ閫夐」</param> /// <param name="doUnPack">鏄惁鍚屾椂鎵ц鎷嗗寘鎿嶄綔锛岃В闄や笌鐖舵潯鐮佷箣闂寸殑鍖呰鍏崇郴</param> /// <returns></returns> - public Result<Inventory> Get(string sn, AuthOption option, bool doUnPack) + public Result<IInventory> Get(string sn, AuthOption option, bool doUnPack) { - var result = new Result<Inventory>(Result.Flags.Success, new Inventory()); + var result = new Result<IInventory>(Result.Flags.Success); try { + var inv = new Inventory(); Barcode barcode = new Barcode(sn); if (sn.IsNullOrEmpty()) { result.Flag = Result.Flags.Failed; result.LocaleMsg = new("WMS.WmsItem.Barcode.EmptyFailure"); + } + else if (barcode.IsException) + { + throw barcode.AnalyseException; } //闈炴硶鏉$爜 else if (!barcode.IsRegular) @@ -48,40 +53,39 @@ result.Flag = Result.Flags.Failed; result.LocaleMsg = new("WMS.WmsItem.Barcode.IllegalFailure"); } - else if (barcode.Qty <= 0) - { - result.Flag = Result.Flags.Failed; - result.LocaleMsg = new("鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紝璇锋鏌ヤ簩缁寸爜锛�"); - } + //else if (barcode.Qty <= 0) + //{ + // result.Flag = Result.Flags.Failed; + // result.LocaleMsg = new("鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紝璇锋鏌ヤ簩缁寸爜锛�"); + //} else { var query = Biz.Db.Queryable<WMS_ITEM_PKG>().ByAuth(option).Where(q => q.SN == barcode.SN).IncludesAllFirstLayer().First(); //var query = Biz.Db.Queryable<WMS_ITEM_PKG>().Where(q => q.SN == barcode.SN).IncludesAllFirstLayer().First();//.ByAuth(option) //鍖呰琛ㄤ腑鎵惧埌鏉$爜 - if (!query.IsNullOrEmpty() && query.QTY > 0) + if (!query.IsNullOrEmpty())// && query.QTY > 0) { - result.Data.SN = barcode.SN; - result.Data.Barcode = barcode; - result.Data.ExtInfo = query.ExtInfo; - result.Data.ItemInfo = query.ItemInfo; - result.Data.Warehouse = query.Warehouse; - result.Data.Region = query.Region; - result.Data.Shelf = query.Shelf; - result.Data.Location = query.Location; - result.Data.Packages = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM_PKG>("pkg_wms_get_item_pkg", new SugarParameter("root", barcode.SN)); - result.Data.Items = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM>("pkg_wms_get_items", new SugarParameter("root", barcode.SN)); - result.Data.ItemsExt = Biz.Db.Queryable<WMS_ITEM_EXT>().Where(q => result.Data.Items.Any(s => s.SN == q.SN)).ToList(); - //var data = result.Data.Items.Select(i => i.SN).ToList().Except(result.Data.ItemsExt.Select(i => i.SN).ToList()); - var data = result.Data.Items.Where(q => !result.Data.ItemsExt.Any(s => s.SN == q.SN)).ToList(); + inv.SN = barcode.SN; + inv.Barcode = barcode; + inv.ExtInfo = query.ExtInfo; + inv.ItemInfo = query.ItemInfo; + inv.Warehouse = query.Warehouse; + inv.Region = query.Region; + inv.Shelf = query.Shelf; + inv.Location = query.Location; + inv.Packages = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM_PKG>("sp_wms_get_item_pkg", new SugarParameter("root", barcode.SN)); + inv.Items = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM>("sp_wms_get_items", new SugarParameter("root", barcode.SN)); + inv.ItemsExt = Biz.Db.Queryable<WMS_ITEM_EXT>().Where(q => inv.Items.Any(s => s.SN == q.SN)).ToList(); + //var data = inv.Items.Select(i => i.SN).ToList().Except(inv.ItemsExt.Select(i => i.SN).ToList()); + var data = inv.Items.Where(q => !inv.ItemsExt.Any(s => s.SN == q.SN)).ToList(); if (data.Count > 0) { foreach (var item in data) { - result.Data.ItemsExt.Add(new() + inv.ItemsExt.Add(new() { SN = item.SN, - SUPP_ITEM_CODE = barcode.OEMItemCode, META_SN = barcode.MetaSn, QR_CODE = barcode.MetaSn }); @@ -90,12 +94,12 @@ result.LocaleMsg = new($"WMS.WmsItem.Barcode.Get{(doUnPack ? "UnPack" : "")}Success", barcode.SN, query.Parent?.SN); if (!query.Parent.IsNullOrEmpty() && doUnPack && query.Parent.SN != query.SN) { - result.Data.ParentPkg = null; + inv.ParentPkg = null; //淇濆瓨鏁版嵁鍒版暟鎹簱 var db = Biz.Db; var dbTran = db.UseTran(() => { - var unPackQty = result.Data.Items.Sum(q => q.QTY); + var unPackQty = inv.Items.Sum(q => q.QTY); db.Updateable<WMS_ITEM_PKG>().SetColumns(q => q.PARENT_SN == null).Where(q => q.ID == query.ID).ExecuteCommand(); db.Updateable<WMS_ITEM_PKG>().SetColumns(q => q.QTY == q.QTY - unPackQty).Where(q => q.ID == query.Parent.ID).ExecuteCommand(); if (!Biz.Db.Queryable<WMS_ITEM_PKG>().Any(q => q.PARENT_SN == query.PARENT_SN && q.SN != query.SN)) @@ -110,17 +114,18 @@ } else { - result.Data.ParentPkg = query.Parent; + inv.ParentPkg = query.Parent; } } else { - result.Data.SN = barcode.SN; - result.Data.Barcode = barcode; - result.Data.ItemInfo = Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == barcode.ItemCode).First(); + inv.SN = barcode.SN; + inv.Barcode = barcode; + inv.ItemInfo = Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == barcode.ItemCode).First(); result.LocaleMsg = new($"WMS.WmsItem.Barcode.NotFound", barcode.SN); } } + result.Data = inv; } catch (Exception ex) { @@ -137,17 +142,22 @@ /// <param name="option">鎺堟潈鏌ヨ閫夐」</param> /// <param name="doUnPack">鏄惁鍚屾椂鎵ц鎷嗗寘鎿嶄綔锛岃В闄や笌鐖舵潯鐮佷箣闂寸殑鍖呰鍏崇郴</param> /// <returns></returns> - public Result<Inventory> GetK(string sn, AuthOption option, bool doUnPack) + public Result<IInventory> GetK(string sn, AuthOption option, bool doUnPack) { - var result = new Result<Inventory>(Result.Flags.Success, new Inventory()); + var result = new Result<IInventory>(Result.Flags.Success, new Inventory()); try { + var inv = new Inventory(); Barcode barcode = new Barcode(sn); barcode.ItemCode = (barcode.ItemCode.IsNullOrEmpty("K").StartsWith("K") ? "" : "K") + barcode.ItemCode; if (sn.IsNullOrEmpty()) { result.Flag = Result.Flags.Failed; result.LocaleMsg = new("WMS.WmsItem.Barcode.EmptyFailure"); + } + else if (barcode.IsException) + { + throw barcode.AnalyseException; } //闈炴硶鏉$爜 else if (!barcode.IsRegular) @@ -167,28 +177,27 @@ //鍖呰琛ㄤ腑鎵惧埌鏉$爜 if (!query.IsNullOrEmpty() && query.QTY > 0) { - result.Data.SN = barcode.SN; - result.Data.Barcode = barcode; - result.Data.ExtInfo = query.ExtInfo; - result.Data.ItemInfo = query.ItemInfo; - result.Data.Warehouse = query.Warehouse; - result.Data.Region = query.Region; - result.Data.Shelf = query.Shelf; - result.Data.Location = query.Location; - result.Data.Packages = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM_PKG>("pkg_wms_get_item_pkg", new SugarParameter("root", barcode.SN)); - result.Data.Items = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM>("pkg_wms_get_items", new SugarParameter("root", barcode.SN)); - result.Data.ItemsExt = Biz.Db.Queryable<WMS_ITEM_EXT>().Where(q => result.Data.Items.Any(s => s.SN == q.SN)).ToList();//鎵╁睍琛� - //var data = result.Data.Items.Select(i => i.SN).ToList().Except(result.Data.ItemsExt.Select(i => i.SN).ToList()); - var data = result.Data.Items.Where(q => !result.Data.ItemsExt.Any(s => s.SN == q.SN)).ToList(); + inv.SN = barcode.SN; + inv.Barcode = barcode; + inv.ExtInfo = query.ExtInfo; + inv.ItemInfo = query.ItemInfo; + inv.Warehouse = query.Warehouse; + inv.Region = query.Region; + inv.Shelf = query.Shelf; + inv.Location = query.Location; + inv.Packages = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM_PKG>("pkg_wms_get_item_pkg", new SugarParameter("root", barcode.SN)); + inv.Items = Biz.Db.Ado.UseStoredProcedure().SqlQuery<WMS_ITEM>("pkg_wms_get_items", new SugarParameter("root", barcode.SN)); + inv.ItemsExt = Biz.Db.Queryable<WMS_ITEM_EXT>().Where(q => inv.Items.Any(s => s.SN == q.SN)).ToList();//鎵╁睍琛� + //var data = inv.Items.Select(i => i.SN).ToList().Except(inv.ItemsExt.Select(i => i.SN).ToList()); + var data = inv.Items.Where(q => !inv.ItemsExt.Any(s => s.SN == q.SN)).ToList(); //鎵╁睍琛ㄤ笉瀛樺湪鏃舵柊寤� if (data.Count > 0) { foreach (var item in data) { - result.Data.ItemsExt.Add(new() + inv.ItemsExt.Add(new() { SN = item.SN, - SUPP_ITEM_CODE = barcode.OEMItemCode, META_SN = barcode.MetaSn, QR_CODE = barcode.MetaSn }); @@ -198,12 +207,12 @@ if (!query.Parent.IsNullOrEmpty() && doUnPack && query.Parent.SN != query.SN) { - result.Data.ParentPkg = null; + inv.ParentPkg = null; //淇濆瓨鏁版嵁鍒版暟鎹簱 var db = Biz.Db; var dbTran = db.UseTran(() => { - var unPackQty = result.Data.Items.Sum(q => q.QTY); + var unPackQty = inv.Items.Sum(q => q.QTY); db.Updateable<WMS_ITEM_PKG>().SetColumns(q => q.PARENT_SN == null).Where(q => q.ID == query.ID).ExecuteCommand(); db.Updateable<WMS_ITEM_PKG>().SetColumns(q => q.QTY == q.QTY - unPackQty).Where(q => q.ID == query.Parent.ID).ExecuteCommand(); if (!Biz.Db.Queryable<WMS_ITEM_PKG>().Any(q => q.PARENT_SN == query.PARENT_SN && q.SN != query.SN)) @@ -218,17 +227,18 @@ } else { - result.Data.ParentPkg = query.Parent; + inv.ParentPkg = query.Parent; } } else { - result.Data.SN = barcode.SN; - result.Data.Barcode = barcode; - result.Data.ItemInfo = Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == barcode.ItemCode).First(); + inv.SN = barcode.SN; + inv.Barcode = barcode; + inv.ItemInfo = Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == barcode.ItemCode).First(); result.LocaleMsg = new($"WMS.WmsItem.Barcode.NotFound", barcode.SN); } } + result.Data = inv; } catch (Exception ex) { @@ -245,11 +255,12 @@ /// <param name="targetLocation">瑕佷笂鏋剁殑鍌ㄤ綅浠g爜</param> /// <param name="isTransfer">鏄惁绉诲簱鎿嶄綔</param> /// <returns></returns> - public Result<PutOnInfo> PutOn(Inventory inventory, AuthOption option, string targetLocation, bool isTransfer = false) + public Result<PutOnInfo> PutOn(IInventory inventory, AuthOption option, string targetLocation, bool isTransfer = false) { var result = new Result<PutOnInfo>(Result.Flags.Success, new PutOnInfo()); try { + var inv = inventory as Inventory; var location = Biz.Db.Queryable<V_WH_UNIT>().Where(q => q.LOCATION_CODE == targetLocation && q.AUTH_ORG == option.CurOrg).IncludesAllFirstLayer().First(); if (!location.IsNullOrEmpty()) { @@ -260,7 +271,7 @@ foreach (var item in inventory.Items) { item.STATUS = WMS_ITEM.STATUSs.InStore.GetValue(); - item.SUPP_LOTNO = inventory.Barcode.LotNo; + item.SUPP_LOTNO = inv.Barcode.LotNo; item.FIRST_IN_DATE = item.FIRST_IN_DATE <= DateTime.MinValue ? DateTime.Now : item.FIRST_IN_DATE; item.PROD_DATE = item.PROD_DATE <= DateTime.MinValue ? item.FIRST_IN_DATE : item.PROD_DATE; item.WH_ID = location.WH_ID; @@ -279,8 +290,7 @@ foreach (var item in inventory.ItemsExt) { item.AUTH_ORG = option.OrgCode; - item.SN = inventory.Barcode.SN; - item.SUPP_ITEM_CODE = inventory.Barcode.OEMItemCode; + item.SN = inv.Barcode.SN; } result.Data.Items = inventory.Items; @@ -307,9 +317,11 @@ /// <param name="inventory">瑕佷笅鏋剁殑搴撳瓨瀵硅薄</param> /// <param name="option">鎺堟潈鏌ヨ閫夐」</param> /// <param name="status">涓嬫灦鍚庣姸鎬�</param> + /// <param name="clearLocation">鏄惁娓呯悊鍌ㄥ尯璐ф灦鍌ㄤ綅淇℃伅</param> /// <returns></returns> - public Result<TakeDownInfo> TakeDown(Inventory inventory, AuthOption option, WMS_ITEM.STATUSs status, bool clearLocation = true) + public Result<TakeDownInfo> TakeDown(IInventory inventory, AuthOption option, WMS_ITEM.STATUSs status, bool clearLocation = true) { + return TakeDown(inventory, inventory.Items.ToDictionary(k => k.SN, v => v.QTY), option, status, clearLocation); var result = new Result<TakeDownInfo>(Result.Flags.Success, new TakeDownInfo()); try { @@ -335,6 +347,68 @@ item.LOCATION_ID = null; } } + result.Data.Items = inventory.Items; + result.Data.History = inventory.History; + result.Data.Packages = inventory.Packages; + } + catch (Exception ex) + { + result.CatchExceptionWithLog(ex, Biz.L("WMS.WmsItem.TakeDown.Exception", inventory.SN, inventory?.Location?.LOCATION_CODE)); + } + return result; + } + + /// <summary> + /// 涓嬫灦 + /// </summary> + /// <param name="inventory">瑕佷笅鏋剁殑搴撳瓨瀵硅薄</param> + /// <param name="qtyList">瑕佷笅鏋剁殑鏈�灏忓寘瑁呮暟閲忓瓧鍏革紝key锛歴n锛寁alue锛歲ty</param> + /// <param name="option">鎺堟潈鏌ヨ閫夐」</param> + /// <param name="status">涓嬫灦鍚庣姸鎬�</param> + /// <param name="clearLocation">鏄惁娓呯悊鍌ㄥ尯璐ф灦鍌ㄤ綅淇℃伅</param> + /// <returns></returns> + public Result<TakeDownInfo> TakeDown(IInventory inventory, Dictionary<string, double> qtyList, AuthOption option, WMS_ITEM.STATUSs status, bool clearLocation = true) + { + var result = new Result<TakeDownInfo>(Result.Flags.Success, new TakeDownInfo()); + try + { + //濡傛灉瑕佷笅鏋剁殑鏁伴噺瀛楀吀涓虹┖鍒欒涓烘槸鍏ㄩ儴涓嬫灦 + qtyList = qtyList.IsNullOrEmpty(inventory.Items.ToDictionary(k => k.SN, v => v.QTY)); + + foreach (var item in inventory.Items) + { + if (qtyList.ContainsKey(item.SN) && qtyList[item.SN] > 0) + { + var downQty = qtyList[item.SN]; + if (item.QTY > downQty) + { + item.QTY -= downQty; + var pkg = inventory.Packages.First(q => q.SN == item.SN); + pkg.QTY = item.QTY; + } + else + { + item.STATUS = status.GetValue(); + var pkg = inventory.Packages.First(q => q.SN == item.SN); + pkg.PARENT_SN = null; + pkg.Parent = null; + if (clearLocation) + { + //item.WH_ID = null; + item.REGION_ID = null; + item.SHELF_ID = null; + item.LOCATION_ID = null; + //pkg.WH_ID = null; + pkg.REGION_ID = null; + pkg.SHELF_ID = null; + pkg.LOCATION_ID = null; + } + } + inventory.History.Add(new WMS_ITEM_HIS(item, $"鏉$爜[{inventory.SN}]浠庡偍浣峓{inventory?.Location?.LOCATION_CODE}]涓嬫灦鏁伴噺[{downQty}]鎴愬姛锛岀姸鎬乕{item.STATUS.GetEnumDesc<WMS_ITEM.STATUSs>()}]锛屾搷浣滃崟鎹甗{item.TRANS_NO}]")); + } + } + inventory.Packages = WMS_ITEM_PKG.UpdateQty(inventory.Packages); + result.Data.Items = inventory.Items; result.Data.History = inventory.History; result.Data.Packages = inventory.Packages; @@ -445,13 +519,13 @@ /// <param name="option">鎺堟潈鏌ヨ閫夐」</param> /// <param name="reqQty">闇�姹傛暟閲忥紝浼氳繑鍥炴弧瓒抽渶姹傜殑鐗╂枡涓暟</param> /// <returns></returns> - public Result<List<SuggestItem>> Suggest(string order, string itemCode, string erpWH, string whID, string regionID, string shelfID, AuthOption option, decimal reqQty) + public Result<List<SuggestItem>> Suggest(string order, string itemCode, string erpWH, string whID, string regionID, string shelfID, AuthOption option, double reqQty) { var result = new Result<List<SuggestItem>>(Result.Flags.Success, new List<SuggestItem>()) { LocaleMsg = new("WMS.WmsItem.Suggest.Success") }; try { var takeCount = 0; - var checkSum = (decimal)0; + var checkSum = 0.0; var checkCount = 0; do { @@ -552,7 +626,7 @@ Location = l, }) .Take(takeCount).ToList(); - var curQty = (decimal)0; + var curQty = 0.0; foreach (var item in items) { result.Data.Add(item); @@ -663,7 +737,7 @@ /// <param name="transLine"></param> /// <param name="actQty"></param> /// <param name="isFirst"></param> - public static WMS_ITEM_POOL GetPoolItem(this WMS_ITEM item, string orgCode, string transCode, string transNo, string transLine, decimal actQty, bool isFirst) + public static WMS_ITEM_POOL GetPoolItem(this WMS_ITEM item, string orgCode, string transCode, string transNo, string transLine, double actQty, bool isFirst) { var poolItem = new WMS_ITEM_POOL() { -- Gitblit v1.9.3