服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2025-04-02 eb29ee75c7f2f4154b7a3d0c475f94e0b964e996
Tiger.Business.WMS/Transaction/In_Default.cs
@@ -13,6 +13,8 @@
using Tiger.Business.WMS.Sharetronic.Shelf;
//using Microsoft.IdentityModel.Tokens;
using Tiger.Model.MES.Yada;
using static IronPython.Modules.PythonThread;
using Tiger.Model.Entitys.MES.Position;
namespace Tiger.Business.WMS.Transaction
{
@@ -23,7 +25,7 @@
    {
        public IIn_Default Init(string id, string userCode, string apiHost, string orgCode)
        {
            base.Init(id, apiHost, userCode, orgCode);
            base.Init(id, userCode, apiHost, orgCode);
            Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
            return this;
        }
@@ -63,7 +65,7 @@
            catch (Exception ex)
            {
                //取消当前操作
                ResetScan();
                ResetTrans();
                //action.CatchExceptionWithLog(ex, $"扫描[{input.SN}]异常");
                action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN));
            }
@@ -81,13 +83,13 @@
                if (CurInvItem.IsNullOrEmpty())
                {
                    //解析条码
                    Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true);
                    Result<IInventory> result = GetInventory(input.SN, input.AuthOption, true);
                   if (!result.IsSuccessed)
                   {
                       action.IsSuccessed = false;
                       action.LocaleMsg = result.LocaleMsg;
                       return action;
                   }
                        return SetOutPutMqttMsg(action, input.Locale);
                    }
                   var inv = result.Data as Inventory;
                    //验证条码是否正确
@@ -96,7 +98,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")
@@ -104,16 +106,12 @@
                        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.Items.Count == 0)
                    {
                        List<WMS_ITEM_HIS> ItemHistorys = new List<WMS_ITEM_HIS>();
                        WMS_ITEM Item;
                        WMS_ITEM_PKG ItemPkgs;
                        Item = new()
                        var newItem = new WMS_ITEM()
                        {
                            SN = inv.Barcode.SN,
                            ITEM_CODE = inv.Barcode.ItemCode,
@@ -125,9 +123,8 @@
                            UNIT = inv.Barcode.Unit,
                        };
                        WMS_ITEM_HIS his = new(Item, $"标准上架入库");
                        ItemHistorys.Add(his);
                        ItemPkgs = new()
                        WMS_ITEM_HIS his = new(newItem, $"标准上架入库");
                        var newPkg = new WMS_ITEM_PKG()
                        {
                            SN = inv.Barcode.SN,
                            AUTH_ORG = input.AuthOption.CurOrg,
@@ -139,19 +136,19 @@
                        var noExt = inv.Items.Where(q => !inv.ItemsExt.Any(s => s.SN == q.SN)).ToList();
                        //扩展表不存在时新建
                        foreach (var item in noExt)
                        foreach (var ext in noExt)
                        {
                            inv.ItemsExt.Add(new()
                            {
                                SN = item.SN,
                                SN = ext.SN,
                                META_SN = inv.Barcode.MetaSn,
                                QR_CODE = inv.Barcode.MetaSn
                            });
                        }
                        inv.Items.Add(Item);
                        inv.Items.Add(newItem);
                        inv.History.Add(his);
                        inv.Packages.Add(ItemPkgs);
                        inv.Packages.Add(newPkg);
                    }
                    //雅达不从条码上更新数量
                    //else if (inv.Items.Count == 1)
@@ -181,20 +178,20 @@
                    CurInvItem = inv;
                    //检查物料数量,如果没有则查询雅达条码主档,把数量返回前端确认
                    if (CurInvItem.Items.Any(q => q.QTY <= 0))
                    //if (CurInvItem.Items.Any(q => q.QTY <= 0))
                    {
                        var qtyList = Biz.DataSource["YadaU9C"].Client.Queryable<mes_MaterialBarCode>().Where(q => CurInvItem.Items.Select(q => q.SN).Contains(q.Code)).ToList();
                        foreach (var qty in qtyList)
                        {
                            var item = CurInvItem.Items.First(q => q.SN == qty.Code);
                            item.QTY = qty.WhQty;
                            item.SUPP_LOTNO = qty.Segment7;
                            item.SUPP_LOTNO = CurInvItem.Barcode.LotNo;
                        }
                        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.ComfirmQty", input.SN);
                        return action;
                        return SetOutPutMqttMsg(action, input.Locale);
                    }
                }
@@ -208,8 +205,8 @@
                        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.ReComfirmQty", input.SN);
                        return action;
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmQty", input.SN);
                        return SetOutPutMqttMsg(action, input.Locale);
                    } 
                    else
                    {
@@ -235,7 +232,7 @@
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L(shelfApiResult.GetData<string>());
                        return action;
                        return SetOutPutMqttMsg(action, input.Locale);
                    }
                    var reaultShelf = shelfApiResult.GetData<ShelfChangeModel>();
@@ -245,7 +242,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())
@@ -253,7 +250,7 @@
                        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.LocationCode = nLocation.LOCATION_CODE;
                }
@@ -264,7 +261,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();
@@ -276,12 +273,17 @@
                    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);
                }
                //执行上架数据处理
                foreach (var item in CurInvItem.Items)
                {
                    item.TRANS_CODE = "In_Default";
                    item.TRANS_NO = $"In_Default_{DateTime.Now:yyyyMMdd}";
                }
                foreach (var item in CurInvItem.Packages)
                {
                    item.TRANS_CODE = "In_Default";
                    item.TRANS_NO = $"In_Default_{DateTime.Now:yyyyMMdd}";
@@ -291,8 +293,8 @@
                {
                    action.IsSuccessed = false;
                    action.LocaleMsg = putonResult.LocaleMsg;
                    ResetScan();
                    return action;
                    ResetTrans();
                    return SetOutPutMqttMsg(action, input.Locale);
                }
                //完成所有处理后使用事务保存数据
@@ -301,11 +303,11 @@
            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>
@@ -392,7 +394,7 @@
            catch (Exception ex)
            {
                //取消当前操作
                ResetScan();
                ResetTrans();
                //action.CatchExceptionWithLog(ex, $"扫描货架/储位[{0}]异常");
                action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code));
            }
@@ -403,11 +405,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
@@ -429,17 +436,17 @@
            //重置扫码信息
            ResetScanInfo();
            return action;
            return SetOutPutMqttMsg(action, locale);
        }
        #endregion
        /// <summary>
        /// 重置当前操作,有需要则重写此方法
        /// 重置事务数据,有需要则重写此方法
        /// </summary>
        public override void ResetScan()
        public override void ResetTrans()
        {
            base.ResetScan();
            base.ResetTrans();
            ResetScanInfo();
            CurScanShelf = null;
        }