From 1285752d532db452edda09fbbb2006836a7084d3 Mon Sep 17 00:00:00 2001
From: zjh <2207896513@qq.com>
Date: 星期四, 14 八月 2025 18:14:42 +0800
Subject: [PATCH] 杂收杂发添加校验,控制不能物料重复

---
 StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs b/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs
index 268fe67..237e3b3 100644
--- a/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs
+++ b/StandardPda/MES.Service/service/Warehouse/MesItemQtrkManager.cs
@@ -293,7 +293,22 @@
                     }
                     supplierCode = mesSupplier.SuppNo;
                 }
-               
+
+                string mesUnit = "";
+                if (mesItems.ItemUnit != null && mesItems.ItemUnit != "")
+                {
+                   
+                    var mesUnitDb = Db.Queryable<MesUnit>()
+        .Where(s => s.Id == Decimal.Parse(mesItems.ItemUnit))
+        .First();
+                    if (mesUnitDb == null)
+                    {
+                        throw new NotImplementedException("[" + ItemQtRKList.SupplierCode +
+                                                          "]鍗曚綅涓嶅瓨鍦紝璇峰悓姝ョ粰MES");
+                    }
+                    mesUnit = mesUnitDb.Fnumber;
+                }
+
 
                 //var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>()
                 //    .Where(s => s.ItemInId == mesInvItemIns.Id
@@ -327,7 +342,7 @@
                     Qd006= ItemQtRKList.PlannedQuantity,
                     Qd007= ItemQtRKList.AppliedQuantity,
                     Qd008=0, // 宸插叆鏁伴噺榛樿涓�0
-                    Qd009= mesItems.ItemUnit,
+                    Qd009= mesUnit,
                     Qd010= ItemQtRKList.Remark,
                     Qd012= mesItems.Id, // 鐗╂枡鍐呯爜
                     LineNumber= ItemQtRKList.LineNumber,
@@ -347,6 +362,27 @@
                 });
             }
 
+            var itemDB = mesItemQtrrDetail
+    .Where(x => x.Qd002 != null) // 杩囨护鎺� null 鍊�
+    .GroupBy(x => x.Qd002)       // 鎸� Qd002 鍒嗙粍
+    .Select(g => new
+    {
+        no = g.Key,
+        count = g.Count()
+        
+    })
+    .ToList();
+
+            // 杈撳嚭缁熻缁撴灉
+            foreach (var item in itemDB)
+            {
+                if (item.count>1)
+                {
+                    throw new Exception($"鏄庣粏琛岀墿鏂�:{item.no}閲嶅锛岃妫�鏌ュ悗閲嶈瘯锛�");
+                }
+                //Console.WriteLine($"鐗╂枡缂栧彿: {item.鐗╂枡缂栧彿}, 鍑虹幇娆℃暟: {item.鍑虹幇娆℃暟}");
+            }
+
             var outItemCommand = Db.Insertable(mesItemQtrrDetail)
                 .PageSize(1).IgnoreColumnsNull().ExecuteCommand();
             if (outItemCommand <= 0)

--
Gitblit v1.9.3