From d5d0d54d8ba486a5b2b669fb16df824a129faaeb Mon Sep 17 00:00:00 2001
From: zjh <2207896513@qq.com>
Date: 星期五, 12 九月 2025 18:01:31 +0800
Subject: [PATCH] 新增iqc异常处置单接口

---
 StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs |  356 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 214 insertions(+), 142 deletions(-)

diff --git a/StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs b/StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs
index 790677b..7ea5d7b 100644
--- a/StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs
+++ b/StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs
@@ -1,4 +1,5 @@
-锘縰sing MES.Service.DB;
+锘縰sing Masuit.Tools;
+using MES.Service.DB;
 using MES.Service.Dto.service;
 using MES.Service.Modes;
 
@@ -14,88 +15,96 @@
         var itemOutFrom = oItemOut.from;
         var itemOutLists = oItemOut.items;
 
-        // 鏍规嵁AsnNo鍜孧esNo瀵规槑缁嗚繘琛屽垎缁�
-        var groupedItems = itemOutLists
-            .GroupBy(item => new {   item.MesNo, item.SqNo })
-            .ToList();
-
-        bool result = true;
-        foreach (var group in groupedItems)
+        return UseTransaction(db =>
         {
-            //if (group.Key.AsnNo == null)
-            //{
-            //    throw new NotImplementedException("AsnNo涓嶈兘涓虹┖");
-            //}
+            // 鏍规嵁AsnNo鍜孧esNo瀵规槑缁嗚繘琛屽垎缁�
+            var groupedItems = itemOutLists
+               // .GroupBy(item => new {  item.MesNo, item.SqNo })
+                .GroupBy(item => new { item.MesNo })
+                .ToList();
 
-            if (group.Key.MesNo == null)
+            int result = 1;
+            int count = 1;
+            foreach (var group in groupedItems)
             {
-                throw new NotImplementedException("鍏ュ簱鍗曞崟鍙蜂笉鑳戒负绌�");
-            }
+                //if (group.Key.AsnNo == null)
+                //{
+                //    throw new NotImplementedException("AsnNo涓嶈兘涓虹┖");
+                //}
 
-            if (group.Key.SqNo == null)
-            {
-                throw new NotImplementedException("閫�璐х敵璇峰崟琛屽彿涓嶈兘涓虹┖");
-            }
-
-            // 鍒涘缓涓�涓复鏃剁殑itemOutFrom瀵硅薄锛屼娇鐢ㄥ垎缁勭殑Key浣滀负涓昏灞炴��
-            var tempItemOutFrom = new ItemOutFrom
-            {
-                
-                MesNo = group.Key.MesNo,
-                SqNo = group.Key.SqNo,
-                // 缁ф壙鍘熷itemOutFrom鐨勫叾浠栧睘鎬�
-                RtnNo = itemOutFrom.RtnNo,
-                Type = itemOutFrom.Type,
-                CreateBy = itemOutFrom.CreateBy,
-                FMRMODE = itemOutFrom.FMRMODE,
-                DepotId = itemOutFrom.DepotId,
-                SupperId = itemOutFrom.SupperId
-            };
-
-            // 鏍规嵁Type鎵ц涓嶅悓鐨勯�昏緫
-            switch (tempItemOutFrom.Type)
-            {
-                case "1":
+                if (group.Key.MesNo == null)
                 {
-                    var mesInvItemOuts = Db.Queryable<MesInvItemOuts>()
-                        .Where(s => s.BillTypeId == BILL_TYPE_ID
-                                    && s.TransactionNo == TRANSACTION_NO
-                                    && s.ItemOutNo == tempItemOutFrom.RtnNo
-                                  
-                        )
-                        .Count();
-
-                    if (mesInvItemOuts > 0)
-                    {
-                        throw new NotImplementedException(
-                            tempItemOutFrom.RtnNo +
-                            "鐨勯��鏂欑敵璇峰崟宸茬粡瀛樺湪");
-                    }
-
-                    // 涓哄綋鍓嶅垎缁勪繚瀛樻暟鎹�
-                    var groupResult = Save(tempItemOutFrom, group.ToList());
-                    if (!groupResult)
-                    {
-                        result = false;
-                    }
-
-                    break;
+                    throw new NotImplementedException("鍏ュ簱鍗曞崟鍙蜂笉鑳戒负绌�");
                 }
-                case "4":
-                    var removeResult = Remove(tempItemOutFrom);
-                    if (!removeResult)
-                    {
-                        result = false;
-                    }
 
-                    break;
-                default:
-                    result = false;
-                    break;
+                //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,
+                    // 缁ф壙鍘熷itemOutFrom鐨勫叾浠栧睘鎬�
+                    //RtnNo = itemOutFrom.RtnNo+ "-"+count.ToString(),
+                    RtnNo = itemOutFrom.RtnNo,
+                    Type = itemOutFrom.Type,
+                    CreateBy = itemOutFrom.CreateBy,
+                    FMRMODE = itemOutFrom.FMRMODE,
+                    DepotId = itemOutFrom.DepotId,
+                    SupperId = itemOutFrom.SupperId
+                };
+                count++;
+                // 鏍规嵁Type鎵ц涓嶅悓鐨勯�昏緫
+                switch (tempItemOutFrom.Type)
+                {
+                    case "1":
+                        {
+                            var mesInvItemOuts = Db.Queryable<MesInvItemOuts>()
+                                .Where(s => s.BillTypeId == BILL_TYPE_ID
+                                            && s.TransactionNo == TRANSACTION_NO
+                                            && s.ItemOutNo == tempItemOutFrom.RtnNo
+                                            && s.Sapno == tempItemOutFrom.SqNo
+                                )
+                                .Count();
+
+                            if (mesInvItemOuts > 0)
+                            {
+                                throw new NotImplementedException(
+                                    tempItemOutFrom.RtnNo +
+                                    "鐨勯��鏂欑敵璇峰崟宸茬粡瀛樺湪");
+                            }
+
+                            // 涓哄綋鍓嶅垎缁勪繚瀛樻暟鎹�
+                            var groupResult = Save(tempItemOutFrom, group.ToList());
+                            if (!groupResult)
+                            {
+                                result = 0;
+                            }
+
+                            break;
+                        }
+                    case "4":
+                        var removeResult = Remove(tempItemOutFrom);
+                        if (!removeResult)
+                        {
+                            result = 0;
+                        }
+
+                        break;
+                    default:
+                        result = 0;
+                        break;
+                }
             }
-        }
 
-        return result;
+            return result;
+        }) > 0;
+
+
     }
 
     private bool Save(ItemOutFrom from, List<ItemOutList> items)
@@ -103,13 +112,13 @@
         var mesInvItemIns = Db.Queryable<MesInvItemIns>()
             .Where(s => s.BillTypeId == 100
                         && s.TransctionNo == "101"
-                        && s.BillNo == from.MesNo
+                        && 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();
@@ -154,7 +163,7 @@
         {
             Id = nextSequenceValue,
             ItemOutNo = billCode,
-            Status = 0,
+            Status = 1,
             CreateBy = "PL017",
             CreateDate = DateTime.Now,
             BillTypeId = 200,
@@ -172,7 +181,7 @@
             Nflag = 0,
             Fmrmode = from.FMRMODE,
             Sapno = from.SqNo,
-            Organizeid = "1002503270000079",
+            Organizeid = "1002011210000095",
         };
 
         // 鍒涘缓閲囪喘閫�鏂欏崟璁板綍
@@ -181,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))
             //{
@@ -206,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) ==
@@ -225,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)
             {
@@ -241,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)
@@ -324,10 +395,11 @@
         }
 
         // 妫�鏌ユ槸鍚︽湁宸插鏍哥殑鍗曟嵁锛屽鏋滃瓨鍦ㄥ凡瀹℃牳(Status=1)鍒欎笉鍏佽鍒犻櫎
-        if (mesInvItemOuts.Any(item => item.Status == 1))
-        {
-            throw new NotImplementedException("瀛樺湪宸插鏍哥殑閲囪喘閫�鏂欏崟锛屼笉鍏佽鍒犻櫎");
-        }
+        //榛樿u9杩囨潵灏辨槸瀹℃牳鐨勶紝涓嶉渶瑕佸仛瀹℃牳鍒ゆ柇
+        //if (mesInvItemOuts.Any(item => item.Status == 1))
+        //{
+        //    throw new NotImplementedException("瀛樺湪宸插鏍哥殑閲囪喘閫�鏂欏崟锛屼笉鍏佽鍒犻櫎");
+        //}
 
         // 鍒犻櫎鎵�鏈夌浉鍏冲崟鎹�
         foreach (var itemOut in mesInvItemOuts)

--
Gitblit v1.9.3