服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-12-27 5695f1eb41693f799de0c76efd22909df34ff6d0
优化标准上下架逻辑
已修改6个文件
196 ■■■■ 文件已修改
Tiger.Api/Language.db 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.WMS/Common/Inventory.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.WMS/Transaction/In_Default.cs 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.WMS/Transaction/Out_Default.cs 105 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.WMS/WMS_ITEM_Biz.cs 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Model.Net/Entitys/WMS/WMS_ITEM_PKG.cs 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Api/Language.db
Binary files differ
Tiger.Business.WMS/Common/Inventory.cs
@@ -34,5 +34,10 @@
        public WMS_ITEM_PKG CurPkg => Packages.FirstOrDefault(q => q.SN == SN);
        public bool isExists => CurPkg != null;
        public bool isMinPackage => Items.Count == 1 && Items.Single().SN == SN;
        public void UpdatePkgQty()
        {
            this.Packages = WMS_ITEM_PKG.UpdateQty(this.Packages);
        }
    }
}
Tiger.Business.WMS/Transaction/In_Default.cs
@@ -90,7 +90,8 @@
            {
                if (CurInvItem.IsNullOrEmpty())
                {
                    Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
                    //解析条码
                    Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
                    if (!result.IsSuccessed)
                    {
                        action.IsSuccessed = false;
@@ -224,7 +225,11 @@
                        {
                            var item = CurInvItem.Items.First(q => q.SN == qty.SN);
                            item.QTY = qty.QTY;
                        }
                            var pkg = CurInvItem.Packages.First(q => q.SN == qty.SN);
                            pkg.QTY = qty.QTY;
                        }
                        CurInvItem.UpdatePkgQty();
                        Command = "Normal";
                    }
                }
Tiger.Business.WMS/Transaction/Out_Default.cs
@@ -10,6 +10,7 @@
using Tiger.Model;
using Tiger.IBusiness;
using Org.BouncyCastle.Ocsp;
using Tiger.Model.MES.Yada;
namespace Tiger.Business.WMS.Transaction
{
@@ -77,39 +78,83 @@
            var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command });
            try
            {
                //解析条码
                Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
                if (!result.IsSuccessed)
                if (CurInvItem.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = result.LocaleMsg;
                    return action;
                }
                CurInvItem = result.Data as Inventory;
                    //解析条码
                    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;
                //验证条码是否正确
                if (!CurInvItem.isNormalStatus || CurInvItem.Status != WMS_ITEM.STATUSs.InStore)
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L($"状态[{0}]异常,请重新扫描");
                    action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', CurInvItem.StatusList.Select(x => x.GetDesc())));
                    return action;
                    //验证条码是否正确
                    if (!inv.isNormalStatus || inv.Status != WMS_ITEM.STATUSs.InStore)
                    {
                        action.IsSuccessed = false;
                        //action.LocaleMsg = Biz.L($"状态[{0}]异常,请重新扫描");
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', inv.StatusList.Select(x => x.GetDesc())));
                        return action;
                    }
                    //储位验证
                    if (inv.Location.IsNullOrEmpty())
                    {
                        action.IsSuccessed = false;
                        //action.LocaleMsg = Biz.L($"条码[{0}]库存信息异常: 没有储位信息,请先上架后再扫描(储位Id: {1})");
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationIsNull", inv.CurPkg.SN, inv.CurPkg.LOCATION_ID);
                        return action;
                    }
                    //物料验证
                    if (inv.ItemInfo.IsNullOrEmpty() || inv.ItemInfo.IS_ACTIVE == "N")
                    {
                        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;
                    }
                    CurInvItem = inv;
                    //把物料数量返回前端确认要下架的数量
                    if (CurInvItem.Items.Any(q => q.QTY > 1))
                    {
                        action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY });
                        action.Data.Command = Command = "ComfirmQty";
                        //action.LocaleMsg = Biz.L("请确认条码[{0}]要下架的数量");
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ComfirmOutQty", input.SN);
                        return action;
                    }
                }
                //储位验证
                if (CurInvItem.Location.IsNullOrEmpty())
                Dictionary<string, decimal> downDic = null;
                //更新下架后的物料数量
                if (Command == "ComfirmQty")
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L($"条码[{0}]库存信息异常: 没有储位信息,请先上架后再扫描(储位Id: {1})");
                    action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationIsNull", CurInvItem.CurPkg.SN, CurInvItem.CurPkg.LOCATION_ID);
                    return action;
                }
                //物料验证
                if (CurInvItem.ItemInfo.IsNullOrEmpty() || CurInvItem.ItemInfo.IS_ACTIVE == "N")
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L($"物料编码[{0}]不存在或者该物料未启用");
                    action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", CurInvItem.ItemInfo.ITEM_CODE.IsNullOrEmpty(CurInvItem.Barcode.ItemCode));
                    return action;
                    var qtyList = (input.Data ?? "").JsonToObject<List<WMS_ITEM>>() ?? new List<WMS_ITEM>();
                    if (!qtyList.Any() || qtyList.Sum(q => q.QTY) <= 0)
                    {
                        action.IsSuccessed = false;
                        action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY });
                        action.Data.Command = Command = "ComfirmQty";
                        //action.LocaleMsg = Biz.L("下架数量不能小于等于零,请重新确认条码[{0}]的下架数量");
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmOutQty", input.SN);
                        return action;
                    }
                    else if (qtyList.Any(q => q.QTY > CurInvItem.Items.First(i => i.SN == q.SN).QTY))
                    {
                        action.IsSuccessed = false;
                        action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY });
                        action.Data.Command = Command = "ComfirmQty";
                        //action.LocaleMsg = Biz.L("下架数量不能超过原条码数量,请重新确认条码[{0}]的下架数量");
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmExceedOutQty", input.SN);
                        return action;
                    }
                    else
                    {
                        downDic = qtyList.ToDictionary(k => k.SN, v => v.QTY);
                        Command = "Normal";
                    }
                }
                //出库下架
@@ -118,7 +163,7 @@
                    item.TRANS_CODE = "Out_Default";
                    item.TRANS_NO = $"Out_Default_{DateTime.Now:yyyyMMdd}";
                }
                Result<TakeDownInfo> downResult = WMS_ITEM_Biz.WmsItem.TakeDown(CurInvItem, input.AuthOption, WMS_ITEM.STATUSs.Sended);
                Result<TakeDownInfo> downResult = WMS_ITEM_Biz.WmsItem.TakeDown(CurInvItem, downDic, input.AuthOption, WMS_ITEM.STATUSs.OffShelf);
                if (!downResult.IsSuccessed)
                {
                    action.IsSuccessed = false;
Tiger.Business.WMS/WMS_ITEM_Biz.cs
@@ -321,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
                {
@@ -358,6 +359,68 @@
            }
            /// <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, decimal> 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;
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, Biz.L("WMS.WmsItem.TakeDown.Exception", inventory.SN, inventory?.Location?.LOCATION_CODE));
                }
                return result;
            }
            /// <summary>
            /// 下架物料推荐,返回固定个数的最小包装物料库存列表
            /// </summary>
            /// <param name="order">领料单号</param>
Tiger.Model.Net/Entitys/WMS/WMS_ITEM_PKG.cs
@@ -205,7 +205,21 @@
        #endregion
        #region 公共方法
        public static List<WMS_ITEM_PKG> UpdateQty(List<WMS_ITEM_PKG> list)
        {
            var minPkgs = list.Where(q => !list.Any(p => p.PARENT_SN == q.SN));
            var parent = list.Where(q => minPkgs.Any(p => p.PARENT_SN == q.SN));
            while (parent.Any())
            {
                foreach (var item in parent)
                {
                    item.QTY = list.Where(q => q.PARENT_SN == item.SN).Sum(q => q.QTY);
                }
                parent = list.Where(q => parent.Any(p => p.PARENT_SN == q.SN));
            }
            return list;
        }
        #endregion
    }//endClass