服务端的TigerApi 框架,基于.NET6 2024 版本
YangYuGang
2025-03-25 024b9947f75a2a73745fc4eded6f7c6bfd1e7f6f
Tiger.Business.WMS/WMS_ITEM_Biz.cs
@@ -43,24 +43,28 @@
                        result.Flag = Result.Flags.Failed;
                        result.LocaleMsg = new("WMS.WmsItem.Barcode.EmptyFailure");
                    }
                    else if (barcode.IsException)
                    {
                        throw barcode.AnalyseException;
                    }
                    //非法条码
                    else if (!barcode.IsRegular)
                    {
                        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)
                        {
                            inv.SN = barcode.SN;
                            inv.Barcode = barcode;
@@ -70,8 +74,8 @@
                            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.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();
@@ -82,7 +86,6 @@
                                    inv.ItemsExt.Add(new()
                                    {
                                        SN = item.SN,
                                        SUPP_ITEM_CODE = barcode.OEMItemCode,
                                        META_SN = barcode.MetaSn,
                                        QR_CODE = barcode.MetaSn
                                    });
@@ -152,6 +155,10 @@
                        result.Flag = Result.Flags.Failed;
                        result.LocaleMsg = new("WMS.WmsItem.Barcode.EmptyFailure");
                    }
                    else if (barcode.IsException)
                    {
                        throw barcode.AnalyseException;
                    }
                    //非法条码
                    else if (!barcode.IsRegular)
                    {
@@ -178,8 +185,8 @@
                            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.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();
@@ -191,7 +198,6 @@
                                    inv.ItemsExt.Add(new()
                                    {
                                        SN = item.SN,
                                        SUPP_ITEM_CODE = barcode.OEMItemCode,
                                        META_SN = barcode.MetaSn,
                                        QR_CODE = barcode.MetaSn
                                    });
@@ -285,7 +291,6 @@
                        {
                            item.AUTH_ORG = option.OrgCode;
                            item.SN = inv.Barcode.SN;
                            item.SUPP_ITEM_CODE = inv.Barcode.OEMItemCode;
                        }
                        result.Data.Items = inventory.Items;
@@ -316,6 +321,7 @@
            /// <returns></returns>
            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
                {
@@ -341,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:sn,value:qty</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;
@@ -451,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
                    {
@@ -558,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);
@@ -669,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()
            {