zjh
13 小时以前 c9abb56a208bf10e726b97122dcc19680c176c49
StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs
@@ -1,4 +1,5 @@
using MES.Service.DB;
using Masuit.Tools;
using MES.Service.DB;
using MES.Service.Dto.service;
using MES.Service.Modes;
@@ -18,7 +19,8 @@
        {
            // 根据AsnNo和MesNo对明细进行分组
            var groupedItems = itemOutLists
                .GroupBy(item => new {  item.MesNo, item.SqNo })
               // .GroupBy(item => new {  item.MesNo, item.SqNo })
                .GroupBy(item => new { item.MesNo })
                .ToList();
            int result = 1;
@@ -35,19 +37,20 @@
                    throw new NotImplementedException("入库单单号不能为空");
                }
                if (group.Key.SqNo == null)
                {
                    throw new NotImplementedException("退货申请单行号不能为空");
                }
                //if (group.Key.SqNo == null)
                //{
                //    throw new NotImplementedException("退货申请单行号不能为空");
                //}
                // 创建一个临时的itemOutFrom对象,使用分组的Key作为主要属性
                var tempItemOutFrom = new ItemOutFrom
                {
                    //AsnNo = group.Key.AsnNo,
                    MesNo = group.Key.MesNo,
                    SqNo = group.Key.SqNo,
                    //SqNo = group.Key.SqNo,
                    // 继承原始itemOutFrom的其他属性
                    RtnNo = itemOutFrom.RtnNo+ "-"+count.ToString(),
                    //RtnNo = itemOutFrom.RtnNo+ "-"+count.ToString(),
                    RtnNo = itemOutFrom.RtnNo,
                    Type = itemOutFrom.Type,
                    CreateBy = itemOutFrom.CreateBy,
                    FMRMODE = itemOutFrom.FMRMODE,
@@ -112,10 +115,10 @@
                        && s.Id == Convert.ToInt32(from.MesNo)
            ).First();
        if (mesInvItemIns == null)
        {
            throw new NotImplementedException("采购入库不存在");
        }
        //if (mesInvItemIns == null)
        //{
        //    throw new NotImplementedException("采购入库不存在");
        //}
        var mesDepots = Db.Queryable<MesDepots>()
            .Where(s => s.DepotId == Decimal.Parse(from.DepotId)).First();
@@ -187,15 +190,15 @@
        foreach (var itemOutList in items)
        {
            // 检查必要字段是否为空
            if (string.IsNullOrEmpty(itemOutList.SrcDocNo))
            {
                throw new NotImplementedException("采购订单号不能为空");
            }
            //if (string.IsNullOrEmpty(itemOutList.SrcDocNo))
            //{
            //    throw new NotImplementedException("采购订单号不能为空");
            //}
            if (string.IsNullOrEmpty(itemOutList.SrcDocLineNo))
            {
                throw new NotImplementedException("采购订单行号不能为空");
            }
            //if (string.IsNullOrEmpty(itemOutList.SrcDocLineNo))
            //{
            //    throw new NotImplementedException("采购订单行号不能为空");
            //}
            //if (string.IsNullOrEmpty(itemOutList.AsnLineNo))
            //{
@@ -212,10 +215,10 @@
                            && s.OrderLineId == itemOutList.SrcDocLineNo)
                .First();
            if (mesRohInData == null)
            {
                throw new NotImplementedException("采购订单不存在");
            }
            //if (mesRohInData == null)
            //{
            //    throw new NotImplementedException("采购订单不存在");
            //}
            //var deliveryDetail = Db.Queryable<DeliveryDetail>()
            //    .Where(a =>  Int32.Parse(a.ZzitemId) ==
@@ -231,7 +234,7 @@
            var itemIdLinkU9 = Db.Queryable<MesLinkU9>()
                .Where(s => s.TableType == "MES_ITEMS"
                            && s.U9Id == itemOutList.itemId).First();
                            && s.U9Id == itemOutList.itemId &&s.OrgId== "1002011210000095").First();
            if (mesLinkU9 == null)
            {
@@ -247,55 +250,117 @@
                throw new NotImplementedException("[" + itemOutList.itemId +
                                                  "]物料不存在,请同步给MES");
            }
            var mesUnit = Db.Queryable<MesUnit>()
               .Where(s => s.Id == int.Parse(mesItems.ItemUnit)).First();
            var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>()
                .Where(s => s.ItemInId == mesInvItemIns.Id
                            && s.ItemNo == mesItems.ItemNo
                            && s.Ebeln == itemOutList.SrcDocNo
                            && s.EbelnLineNo ==
                            Decimal.Parse(itemOutList.SrcDocLineNo)
                            && s.SuppNo == mesSupplier.SuppNo
                            ).First();
            if (mesInvItemInCItems == null)
            if (itemOutList.SrcDocNo!=null&& itemOutList.SrcDocNo!="")
            {
                throw new NotImplementedException("没有对应的入库明细");
                var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>()
              .Where(s => s.ItemInId == mesInvItemIns.Id
                          && s.ItemNo == mesItems.ItemNo
                          && s.Ebeln == itemOutList.SrcDocNo
                          && s.EbelnLineNo ==
                          Decimal.Parse(itemOutList.SrcDocLineNo)
                          && s.SuppNo == mesSupplier.SuppNo
                          ).First();
                if (mesInvItemInCItems == null)
                {
                    throw new NotImplementedException("没有对应的入库明细");
                }
                // 确保CbillNo不为空
                if (string.IsNullOrEmpty(mesInvItemIns.CbillNo))
                {
                    throw new NotImplementedException("入库单关联的采购单号不能为空");
                }
                mesInvItemOutItems.Add(new MesInvItemOutItems
                {
                    ItemOutId = nextSequenceValue,
                    ItemNo = mesItems.ItemNo,
                    Quantity = Decimal.Parse(itemOutList.qty),
                    CreateBy = "PL017",
                    CreateDate = DateTime.Now,
                    Factory = "1000",
                    Company = "1000",
                    DepotCode = mesDepots.DepotCode,
                    WorkNo = itemOutList.SrcDocNo, // 确保WorkNo有值
                    WorkLine =
                        Decimal.Parse(itemOutList.SrcDocLineNo), // 确保WorkLine有值
                    EbelnK3id = Decimal.Parse(mesRohInData.ErpId),
                    LineK3id = Decimal.Parse(mesRohInData.EbelnK3id),
                    FType = 0,
                    Status = 0,
                    PbillNo = mesInvItemIns.CbillNo, // 确保PbillNo有值
                    RkNo = from.MesNo, // 确保RkNo有值
                    RkLine = mesInvItemInCItems.Id, // 确保RkLine有值
                    RkQty = mesInvItemInCItems.Quantity,
                    TlQty = 0,
                    ItemId = Decimal.Parse(itemIdLinkU9.MesId), // 确保ItemId有值
                    SqNo = itemOutList.SqNo, // 确保ItemId有值
                                             //ZzitemId = itemOutList.AsnLineNo, // 确保ItemId有值
                                              Unit = mesUnit.Fnumber,
                });
            }
            // 确保CbillNo不为空
            if (string.IsNullOrEmpty(mesInvItemIns.CbillNo))
            else
            {
                throw new NotImplementedException("入库单关联的采购单号不能为空");
              //  var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>()
              //.Where(s => s.ItemInId == mesInvItemIns.Id
              //            && s.ItemNo == mesItems.ItemNo
              //            && s.Ebeln == itemOutList.SrcDocNo
              //            && s.EbelnLineNo ==
              //            Decimal.Parse(itemOutList.SrcDocLineNo)
              //            && s.SuppNo == mesSupplier.SuppNo
              //            ).First();
              //  if (mesInvItemInCItems == null)
              //  {
              //      throw new NotImplementedException("没有对应的入库明细");
              //  }
                //// 确保CbillNo不为空
                //if (string.IsNullOrEmpty(mesInvItemIns.CbillNo))
                //{
                //    throw new NotImplementedException("入库单关联的采购单号不能为空");
                //}
                mesInvItemOutItems.Add(new MesInvItemOutItems
                {
                    ItemOutId = nextSequenceValue,
                    ItemNo = mesItems.ItemNo,
                    Quantity = Decimal.Parse(itemOutList.qty),
                    CreateBy = "PL017",
                    CreateDate = DateTime.Now,
                    Factory = "1000",
                    Company = "1000",
                    DepotCode = mesDepots.DepotCode,
                    WorkNo = itemOutList.SrcDocNo, // 确保WorkNo有值
                    WorkLine =
                        Decimal.Parse(itemOutList.SrcDocLineNo), // 确保WorkLine有值
                    //EbelnK3id = Decimal.Parse(mesRohInData.ErpId),
                    //LineK3id = Decimal.Parse(mesRohInData.EbelnK3id),
                    FType = 0,
                    Status = 0,
                    //PbillNo = mesInvItemIns.CbillNo, // 确保PbillNo有值
                    RkNo = from.MesNo, // 确保RkNo有值
                    RkLine = null, // 确保RkLine有值
                    RkQty = null,
                    TlQty = 0,
                    ItemId = Decimal.Parse(itemIdLinkU9.MesId), // 确保ItemId有值
                    SqNo = itemOutList.SqNo, // 确保ItemId有值
                                             //ZzitemId = itemOutList.AsnLineNo, // 确保ItemId有值
                    Unit = mesUnit.Fnumber,
                });
            }
            mesInvItemOutItems.Add(new MesInvItemOutItems
            {
                ItemOutId = nextSequenceValue,
                ItemNo = mesItems.ItemNo,
                Quantity = Decimal.Parse(itemOutList.qty),
                CreateBy = "PL017",
                CreateDate = DateTime.Now,
                Factory = "1000",
                Company = "1000",
                DepotCode = mesDepots.DepotCode,
                WorkNo = itemOutList.SrcDocNo, // 确保WorkNo有值
                WorkLine =
                    Decimal.Parse(itemOutList.SrcDocLineNo), // 确保WorkLine有值
                EbelnK3id = Decimal.Parse(mesRohInData.ErpId),
                LineK3id = Decimal.Parse(mesRohInData.EbelnK3id),
                FType = 0,
                Status = 0,
                PbillNo = mesInvItemIns.CbillNo, // 确保PbillNo有值
                RkNo = from.MesNo, // 确保RkNo有值
                RkLine = mesInvItemInCItems.Id, // 确保RkLine有值
                RkQty = mesInvItemInCItems.Quantity,
                TlQty = 0,
                ItemId = Decimal.Parse(itemIdLinkU9.MesId), // 确保ItemId有值
                SqNo = itemOutList.SqNo, // 确保ItemId有值
                //ZzitemId = itemOutList.AsnLineNo, // 确保ItemId有值
                // Unit = item.Unit,
            });
        }
        var outItemCommand = Db.Insertable(mesInvItemOutItems)