服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2025-04-02 29e5727404f1c34af7b0f9b80c0876e6eeb4b91c
Tiger.Business.WMS/Transaction/Yada/In_BIZ_U9_RECEIPT.cs
@@ -11,7 +11,8 @@
using Tiger.IBusiness;
using Tiger.Model.Sharetronic.Shelf;
using Tiger.Business.WMS.Sharetronic.Shelf;
using static IronPython.Modules._ast;
using Tiger.Model.Entitys.MES.U9C;
using Tiger.Model.MES.Yada;
namespace Tiger.Business.WMS.Transaction
{
@@ -22,7 +23,7 @@
    {
        public IIn_BIZ_U9_RECEIPT 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;
        }
@@ -80,14 +81,14 @@
                if (CurInvItem.IsNullOrEmpty())
                {
                    //解析条码
                    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;
                    Result<IInventory> result = GetInventory(input.SN, input.AuthOption, true);
                    if (!result.IsSuccessed)
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = result.LocaleMsg;
                        return SetOutPutMqttMsg(action, input.Locale);
                    }
                    var inv = result.Data as Inventory;
                    //验证条码是否正确
                    if (!inv.isNormalStatus || inv.Status != WMS_ITEM.STATUSs.WaitIn)
@@ -95,7 +96,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")
@@ -103,18 +104,18 @@
                        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);
                    }
                    CurInvItem = inv;
                }
                var receipt = await Biz.Db.Queryable<BIZ_U9_RECEIPT>().Where(q => q.ORDER_NO == CurInvItem.Items.First().TRANS_NO).IncludesAllFirstLayer().FirstAsync();
                var receipt = await MainDB.Queryable<BIZ_U9_RECEIPT>().Where(q => q.ORDER_NO == CurInvItem.Items.First().TRANS_NO).IncludesAllFirstLayer().FirstAsync();
                if (receipt.IsNullOrEmpty())
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("收货单中找不到条码所属的单据[{0}]信息,请重新扫描收货单的条码或选择正确的功能上架");
                    action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.ReceiptNotExists", CurInvItem.Items.First().TRANS_NO);
                    return action;
                    return SetOutPutMqttMsg(action, input.Locale);
                }
                var receiptDtl = receipt.Details.First(q => q.LINE_NO == CurInvItem.Items.First().TRANS_LINE);
                if (receiptDtl.STATUS > BIZ_U9_RECEIPT.STATUSs.Storing.GetValue())
@@ -122,15 +123,23 @@
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("收货单中行[{0}]状态[{1}]异常,请扫描正确的条码");
                    action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.ReceiptDtlStatusException", receiptDtl.LINE_NO, receiptDtl.STATUS.GetEnumDesc<BIZ_U9_RECEIPT.STATUSs>());
                    return action;
                    return SetOutPutMqttMsg(action, input.Locale);
                }
                var receiptSn = receipt.SnList.First(q => q.SN == CurInvItem.SN);
                if (receiptSn.STATUS != WMS_ITEM.STATUSs.WaitIn.GetValue())
                var receiptSn = receipt.SnList.Where(q => CurInvItem.Items.Any(i => i.SN == q.SN)).ToList();
                if (receiptSn.Any(q => q.STATUS != WMS_ITEM.STATUSs.WaitIn.GetValue()))
                {
                    action.IsSuccessed = false;
                    //action.LocaleMsg = Biz.L("收货单中条码[{0}]状态[{1}]异常,请扫描正确的条码");
                    action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.ReceiptSnStatusException", receiptSn.SN, receiptSn.STATUS.GetEnumDesc<WMS_ITEM.STATUSs>());
                    return action;
                    action.LocaleMsg = Biz.L("WMS.In_BIZ_U9_RECEIPT.ScanItem.ReceiptSnStatusException", CurInvItem.SN, receiptSn.First(q => q.STATUS != WMS_ITEM.STATUSs.WaitIn.GetValue()).STATUS.GetEnumDesc<WMS_ITEM.STATUSs>());
                    return SetOutPutMqttMsg(action, input.Locale);
                }
                //从U9获取收货单行信息
                var u9Dtl = Biz.DataSource["YadaU9C"].Client.Queryable<mes_ReturnedDocInfo>().Where(x => x.RcvId == receipt.ID.ToDouble() && x.DocLineNo == receiptDtl.LINE_NO.ToDouble() && x.SplitFlag != 1).First();
                if (!u9Dtl.IsNullOrEmpty() && u9Dtl.RcvQtyTU != receiptDtl.QTY_OK)
                {
                    receiptDtl.ID = u9Dtl.RcvLineId.ToString();
                    receiptDtl.QTY_OK = u9Dtl.RcvQtyTU;
                    receiptDtl.QTY_NG = receiptDtl.QTY - receiptDtl.QTY_OK;
                }
                var nLocation = new WMS_LOCATION();
@@ -142,7 +151,7 @@
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = Biz.L(shelfApiResult.GetData<string>());
                        return action;
                        return SetOutPutMqttMsg(action, input.Locale);
                    }
                    var reaultShelf = shelfApiResult.GetData<ShelfChangeModel>();
@@ -152,7 +161,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())
@@ -160,7 +169,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;
                }
@@ -171,7 +180,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();
@@ -184,11 +193,23 @@
                    //action.LocaleMsg = Biz.L("储位[{0}]只能存放一个物料");
                    action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE);
                    ResetScan();
                    return action;
                    return SetOutPutMqttMsg(action, input.Locale);
                }
                //执行上架数据处理
                foreach (var item in CurInvItem.Items)
                {
                    item.IS_LOCKED = "Y";
                    item.SOURCE_CODE = item.TRANS_CODE;
                    item.SOURCE_ORDER = item.TRANS_NO;
                    item.SOURCE_LINE = item.TRANS_LINE;
                    item.TRANS_CODE = nameof(BIZ_U9_RECEIPT);
                    item.TRANS_NO = receipt.ORDER_NO;
                    item.TRANS_LINE = receiptDtl.LINE_NO;
                    item.PROD_DATE = item.PROD_DATE < new DateTime(2000, 1, 1) ? DateTime.Now : item.PROD_DATE;
                    item.FIRST_IN_DATE = item.FIRST_IN_DATE < new DateTime(2000, 1, 1) ? DateTime.Now : item.FIRST_IN_DATE;
                }
                foreach (var item in CurInvItem.Packages)
                {
                    item.SOURCE_CODE = item.TRANS_CODE;
                    item.SOURCE_ORDER = item.TRANS_NO;
@@ -203,31 +224,61 @@
                    action.IsSuccessed = false;
                    action.LocaleMsg = putonResult.LocaleMsg;
                    ResetScan();
                    return action;
                    return SetOutPutMqttMsg(action, input.Locale);
                }
                //更新单据信息
                receiptSn.STATUS = WMS_ITEM.STATUSs.InStore.GetValue();
                receiptSn.IS_IN = "Y";
                foreach (var sn in receiptSn)
                {
                    sn.STATUS = WMS_ITEM.STATUSs.InStore.GetValue();
                    sn.IS_IN = "Y";
                }
                //如果当前行上架完成标记为待审核
                receiptDtl.QTY_IN = receipt.SnList.Where(q => q.LINE_NO == receiptDtl.LINE_NO).Sum(q => q.QTY);
                if (receiptDtl.QTY_IN == receiptDtl.QTY)
                receiptDtl.QTY_IN = receipt.SnList.Where(q => q.LINE_NO == receiptDtl.LINE_NO && q.STATUS == WMS_ITEM.STATUSs.InStore.GetValue()).Sum(q => q.QTY);
                if (receiptDtl.QTY_IN == receiptDtl.QTY_OK)
                {
                    receiptDtl.STATUS = BIZ_U9_RECEIPT.STATUSs.Review.GetValue();
                    //当前单据明细已经全部上架完成,可以调用U9行审接口
                    //当前单据明细行已经全部上架完成,可以调用U9行审接口,如果行审失败则报错,最后一个上架失败
                    var iInput = new SubmitLineInput
                    {
                        userId = UserCode,
                        IsLogin = true,
                        param = new()
                        {
                            RcvLineID = receiptDtl.ID,
                            RcvDocNo = receiptDtl.ORDER_NO,
                            DocLineNo = receiptDtl.LINE_NO,
                            OrgCode = receiptDtl.AUTH_ORG,
                        }
                    };
                    var result = await DI.Resolve<IWMS_U9C>().ReceivementApproveLine(iInput);
                    if (!result.IsSuccessed)
                    {
                        action.IsSuccessed = false;
                        action.LocaleMsg = result.LocaleMsg;
                        return SetOutPutMqttMsg(action, input.Locale);
                    }
                    else
                    {
                        receiptDtl.STATUS = BIZ_U9_RECEIPT.STATUSs.Finished.GetValue();
                    }
                }
                else
                {
                    receiptDtl.STATUS = BIZ_U9_RECEIPT.STATUSs.Storing.GetValue();
                }
                var dtlStatus = receipt.Details.Select(q => q.STATUS).Distinct();
                if (dtlStatus.Count() == 1 && dtlStatus.First() == BIZ_U9_RECEIPT.STATUSs.Review.GetValue())
                //更新单据状态
                if (receipt.Details.Any(q => q.STATUS < BIZ_U9_RECEIPT.STATUSs.Review.GetValue()))
                {
                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Storing.GetValue();
                }
                else if (receipt.Details.Any(q => q.STATUS < BIZ_U9_RECEIPT.STATUSs.Finished.GetValue()))
                {
                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Review.GetValue();
                }
                else
                {
                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Storing.GetValue();
                    receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.Finished.GetValue();
                }
                //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
@@ -238,7 +289,7 @@
                    var db = GetCommitDB();
                    //数据保存逻辑
                    db.Updateable(receipt, UserCode).UpdateColumns(q => new { q.STATUS, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
                    db.Updateable(receiptDtl, UserCode).UpdateColumns(q => new { q.STATUS, q.QTY_IN, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
                    db.Updateable(receiptDtl, UserCode).UpdateColumns(q => new { q.ID, q.STATUS, q.QTY_IN, q.QTY_OK, q.QTY_NG, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
                    db.Updateable(receiptSn, UserCode).UpdateColumns(q => new { q.STATUS, q.IS_IN, q.UPDATE_TIME, q.UPDATE_USER }).ExecuteCommand();
                });
@@ -252,7 +303,7 @@
                //action.CatchExceptionWithLog(ex, $"扫描条码[{input.SN}]复核异常");
                action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN));
            }
            return action;
            return SetOutPutMqttMsg(action, input.Locale);
        }
        /// <summary>
@@ -350,11 +401,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
@@ -375,8 +431,8 @@
            action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, CurInvItem.Location.LOCATION_CODE);
            //重置工序
            ResetScan();
            return action;
            ResetScanInfo();
            return SetOutPutMqttMsg(action, locale);
        }
        #endregion
@@ -387,9 +443,17 @@
        public override void ResetScan()
        {
            base.ResetScan();
            ResetScanInfo();
            CurScanShelf = null;
        }
        /// <summary>
        /// 重置扫码信息
        /// </summary>
        public void ResetScanInfo()
        {
            Command = null;
            CurInvItem = null;
            CurScanShelf = null;
        }
        public override bool Close(bool needSaveHistoryLog = false)