服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2025-03-18 406ac5eb58f06bde155443a34c76fbf187759808
Tiger.Business.WMS/Transaction/Yada/Count_BIZ_U9_ASN.cs
@@ -11,6 +11,8 @@
using Tiger.IBusiness;
using Tiger.Model.MES.Yada;
using Tiger.Model.Entitys.MES.U9C;
using System.Security.Policy;
using Tiger.Model.Entitys.MES.Position;
namespace Tiger.Business.WMS.Transaction
{
@@ -21,7 +23,7 @@
    {
        public ICount_BIZ_U9_ASN Init(string id, string userCode, string apiHost, string orgCode)
        {
            base.Init(id, apiHost, userCode, orgCode);
            base.Init(id, userCode, apiHost, orgCode);
            //加载已经清点数据
            LoadData();
            Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
@@ -41,8 +43,7 @@
      /// </summary>
      private void LoadData()
        {
            var orders = MainDB.Queryable<BIZ_U9_ASN>().Where(q => ("," + q.RECEIVER + ",").Contains("," + UserCode + ",")).ToList();
            OrderList = orders.Select(q => q.ORDER_NO).ToList();
            OrderList = MainDB.Queryable<BIZ_U9_ASN_SN>().Where(q => q.RECEIVER == UserCode && SqlFunc.Subqueryable<BIZ_U9_ASN>().Where(s => s.ORDER_NO == q.ORDER_NO && s.STATUS == BIZ_U9_ASN.STATUSs.Counting.GetValue()).Any()).Select(q => q.ORDER_NO).ToList();
        }
        /// <summary>
        /// 扫描入口
@@ -139,7 +140,7 @@
                    {
                        action.IsSuccessed = false;
                        //action.LocaleMsg = Biz.L("物料编码[{0}]不存在或者该物料未启用");
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", inv.ItemInfo.ITEM_CODE.IsNullOrEmpty(inv.Barcode.ItemCode));
                        action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", (inv.ItemInfo?.ITEM_CODE).IsNullOrEmpty(inv.Barcode.ItemCode));
                        return action;
                    }
@@ -155,8 +156,7 @@
                            AUTH_ORG = input.AuthOption.CurOrg,
                            STATUS = WMS_ITEM.STATUSs.WaitIn.GetValue(),
                            QTY = inv.Barcode.Qty.ToDouble(),
                            PROD_DATE = inv.Barcode.DateCode.ToDateTime(),
                            ERP_WH = CurScanShelf.WarehouseCode,
                            PROD_DATE = (inv.Barcode.DateCode?? DateTime.Now.ToString("yyyy-MM-dd")).ToDateTime(),
                            UNIT = inv.Barcode.Unit,
                        };
@@ -166,7 +166,6 @@
                            AUTH_ORG = input.AuthOption.CurOrg,
                            ITEM_CODE = inv.Barcode.ItemCode,
                            QTY = inv.Barcode.Qty.ToDouble(),
                            ERP_WH = CurScanShelf.WarehouseCode,
                            UNIT = inv.Barcode.Unit,
                        };
@@ -201,12 +200,12 @@
                    {
                        foreach (var item in inv.Items)
                        {
                            item.ERP_WH = CurScanShelf.WarehouseCode;
                            item.ERP_WH = "";
                            item.AUTH_ORG = input.AuthOption.CurOrg;
                        }
                        foreach (var item in inv.Packages)
                        {
                            item.ERP_WH = CurScanShelf.WarehouseCode;
                            item.ERP_WH = "";
                            item.AUTH_ORG = input.AuthOption.CurOrg;
                        }
                    }
@@ -261,7 +260,9 @@
                //执行清点数据处理
                CurSn.STATUS = WMS_ITEM.STATUSs.Counted.GetValue();
                CurSn.QTY = CurInvItem.Items.Sum(q => q.QTY);
            foreach (var item in CurInvItem.Items)
                CurSn.RECEIVER = UserCode;
                CurSn.RECEIVE_DATE = DateTime.Now;
                foreach (var item in CurInvItem.Items)
            {
               item.AUTH_ORG = CurSn.AUTH_ORG;
               item.STATUS = WMS_ITEM.STATUSs.Counted.GetValue();
@@ -350,6 +351,8 @@
            foreach (var sn in ScanList)
            {
               sn.STATUS = WMS_ITEM.STATUSs.Incoming.GetValue();
                    sn.RECEIVER = null;
                    sn.RECEIVE_DATE = DateTime.MinValue;
            }
            var historys = new List<WMS_ITEM_HIS>();
@@ -418,7 +421,9 @@
            var dbTran = db.UseTran(() =>
            {
               db.Updateable<BIZ_U9_ASN_SN>(UserCode).SetColumns(q => q.STATUS == WMS_ITEM.STATUSs.Incoming.GetValue())
                     .Where(q => q.SN == input.SN).ExecuteCommand();
                        .SetColumns(q => q.RECEIVER == null)
                        .SetColumns(q => q.RECEIVE_DATE == DateTime.MinValue)
                        .Where(q => q.SN == input.SN).ExecuteCommand();
               db.Updateable(item, UserCode).ExecuteCommand();
               db.Insertable(new WMS_ITEM_HIS(item, $"条码[{item.SN}]取消清点,操作单据[{order}]"), UserCode).ExecuteCommand();
            });
@@ -445,25 +450,29 @@
      ///  获取本次已清点的物料列表(带分页)
      /// </summary>
      /// <returns></returns>
      public async Task<PageAble<BIZ_U9_ASN_SN>> GetScannedList()
      public async Task<ApiAction<PageAble<BIZ_U9_ASN_SN>>> GetScannedList(BaseInputWithPage input)
      {
         return await Task.FromResult(new PageAble<BIZ_U9_ASN_SN>()
         {
            data = ScanList,
            totals = ScanList.Count(),
         });
      }
            var action = new ApiAction<PageAble<BIZ_U9_ASN_SN>>();
            action.Data = new PageAble<BIZ_U9_ASN_SN>();
            action.Data.pageSize = input.pageSize;
            action.Data.pageIndex = input.pageIndex;
            action.Data.totals = ScanList.Count;
            action.Data.data = ScanList.Skip((input.pageIndex - 1) * input.pageSize).Take(input.pageSize).ToList();
            //action.Data = query;
            return action;
        }
      /// <summary>
      ///  获取当前所有单据信息
      /// </summary>
      /// <returns></returns>
      public async Task<List<BIZ_U9_ASN>> GetOrderList()
        /// <summary>
        ///  获取当前所有单据信息
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction<List<BIZ_U9_ASN>>> GetOrderList()
        {
         var Orders = await Biz.Db.Queryable<BIZ_U9_ASN>().Where(q => OrderList.Contains(q.ORDER_NO)).IncludesAllFirstLayer().ToListAsync();
         if (!Orders.IsNullOrEmpty())
            var action = new ApiAction<List<BIZ_U9_ASN>>();
            action.Data = await Biz.Db.Queryable<BIZ_U9_ASN>().Where(q => OrderList.Contains(q.ORDER_NO)).IncludesAllFirstLayer().ToListAsync();
         if (!action.Data.IsNullOrEmpty())
         {
            foreach (var order in Orders)
            foreach (var order in action.Data)
            {
               foreach (var dtl in order.Details)
               {
@@ -472,14 +481,14 @@
               }
            }
         }
         return Orders;
         return action;
      }
      /// <summary>
      ///  设置收货单明细赠品数量
      /// </summary>
      /// <returns></returns>
      public async Task<ApiAction> SetGiftQty(BaseInput input)
        /// <summary>
        ///  生成收货单:调用U9新增收货单接口
        /// </summary>
        /// <returns></returns>
        public async Task<ApiAction> SetGiftQty(BaseInput input)
      {
         var action = new ApiAction();
         try
@@ -569,7 +578,8 @@
            if (list != null && list.Count > 0)
            {
               receipt.AUTH_ORG = order.AUTH_ORG;
                    receipt.ID = list.First().RcvId.ToString();
                    receipt.AUTH_ORG = order.AUTH_ORG;
               receipt.STATUS = BIZ_U9_RECEIPT.STATUSs.InQC.GetValue();
               receipt.ORDER_NO = list.First().DocNo;
               receipt.SUPP_CODE = list.First().SupplierCode;
@@ -587,6 +597,7 @@
                  var asnDtl = order.Details.First(q => q.ID == item.SrcASNDocLineId.ToString());
                  BIZ_U9_RECEIPT_DTL receiptDt = new()
                  {
                            ID = item.RcvLineId.ToString(),
                            AUTH_ORG = receipt.AUTH_ORG,
                            STATUS = BIZ_U9_RECEIPT.STATUSs.InQC.GetValue(),
                     ORDER_NO = item.DocNo,
@@ -598,38 +609,34 @@
                     ASN_NO =asnDtl.ORDER_NO,
                     ASN_LINE_ID = item.SrcASNDocLineId.ToString(),
                     ASN_LINE = asnDtl.LINE_NO,
                            ERP_CODE = item.ItemCode1,
                  };
                        receipt.Details.Add(receiptDt);
                    }
               foreach (var item in order.SnList)
               foreach (var sn in order.SnList)
               {
                        var dtl = receipt.Details.First(q => q.ASN_LINE == item.LINE_NO);
                        var dtl = receipt.Details.First(q => q.ASN_LINE == sn.LINE_NO);
                        BIZ_U9_RECEIPT_SN receiptSn = new()
                  {
                        {
                            AUTH_ORG = dtl.AUTH_ORG,
                            ORDER_NO = dtl.ORDER_NO,
                            LINE_NO = dtl.LINE_NO,
                            SN = receipt.Details.First().ORDER_NO,
                            //META_SN
                            ITEM_CODE = dtl.ITEM_CODE,
                            STATUS = BIZ_U9_RECEIPT.STATUSs.Imported.GetValue(),
                            //  QTY
                            //UNIT
                            //IS_OK
                            // IS_IN
                            //IS_SCRAP
                            //LOTNO
                            //CARTON_NO
                            //PALLET_NO
                     AUTH_ORG = dtl.AUTH_ORG,
                           // REMARK = result.Data[item].Code,
                            SN = sn.SN,
                            META_SN = sn.META_SN,
                            ITEM_CODE = sn.ITEM_CODE,
                            STATUS = WMS_ITEM.STATUSs.WaitIn.GetValue(),
                            QTY = sn.QTY,
                            UNIT = sn.UNIT,
                            IS_OK = sn.IS_OK,
                            IS_IN = sn.IS_IN,
                            LOTNO = sn.LOTNO,
                            CARTON_NO = sn.CARTON_NO,
                            PALLET_NO = sn.PALLET_NO,
                        };
                        receipt.SnList.Add(receiptSn);
                    }
            }
               // throw new NotImplementedException();
            //更新库存表信息
            var items = MainDB.Queryable<WMS_ITEM>().Where(q => SqlFunc.Subqueryable<BIZ_U9_ASN_SN>().Where(s => s.SN == q.SN && s.ORDER_NO == order.ORDER_NO).Any()).ToList();
@@ -645,14 +652,20 @@
               item.TRANS_LINE = receipt.SnList.First(q => q.SN == item.SN).LINE_NO;
               historys.Add(new WMS_ITEM_HIS(item, $"送货单[{order.ORDER_NO}]的条码[{item.SN}]生成收货单[{receipt.ORDER_NO}],待检验完成后可入库"));
            }
                order.STATUS = BIZ_U9_ASN.STATUSs.Finished.GetValue();
                order.RECEIVER_ID = receipt.ID;
                order.RECEIVER_NO = receipt.ORDER_NO;
                order.RECEIVER = UserCode;
                order.RECEIVE_DATE = DateTime.Now;
            //使用统一的事务DB对象
            var db = GetCommitDB();
                //使用统一的事务DB对象
                var db = GetCommitDB();
            var dbTran = db.UseTran(() =>
            {
               db.Updateable(items, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS, q.TRANS_CODE, q.TRANS_NO, q.TRANS_LINE, q.SOURCE_CODE, q.SOURCE_ORDER, q.SOURCE_LINE }).ExecuteCommandAsync();
               db.Updateable(items, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS, q.TRANS_CODE, q.TRANS_NO, q.TRANS_LINE, q.SOURCE_CODE, q.SOURCE_ORDER, q.SOURCE_LINE }).ExecuteCommand();
               db.Insertable(historys, UserCode).ExecuteCommand();
               db.Insertable(receipt, UserCode).ExecuteCommand();
                    db.Updateable(order, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS, q.RECEIVER, q.RECEIVE_DATE, q.RECEIVER_ID, q.RECEIVER_NO }).ExecuteCommand();
                    db.Insertable(receipt, UserCode).ExecuteCommand();
               db.Insertable(receipt.Details, UserCode).ExecuteCommand();
               db.Insertable(receipt.SnList, UserCode).ExecuteCommand();
            });