From caed1e3200578fae1e2ee6c8bf24826707d7596a Mon Sep 17 00:00:00 2001
From: 如洲 陈 <1278080563@qq.com>
Date: 星期二, 30 九月 2025 11:10:52 +0800
Subject: [PATCH] 首检巡检和平板自动更新优化

---
 MES.Service/service/QC/XJService.cs |   90 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 64 insertions(+), 26 deletions(-)

diff --git a/MES.Service/service/QC/XJService.cs b/MES.Service/service/QC/XJService.cs
index 65a3a08..590856b 100644
--- a/MES.Service/service/QC/XJService.cs
+++ b/MES.Service/service/QC/XJService.cs
@@ -142,7 +142,7 @@
     }
 
 
-    public List<QsQaItemXj01> setJYItem(string itemNo)
+    public List<QsQaItemXj01> setJYItem(string itemNo, decimal? workQty = null)
     {
         var db = SqlSugarHelper.GetInstance();
 
@@ -151,32 +151,70 @@
 
         if (count <= 0) return new List<QsQaItemXj01>();
 
-        return db
+        // 濡傛灉娌℃湁浼犻�掑伐鍗曟暟閲忥紝灏濊瘯浠庡伐鍗曡〃涓幏鍙�
+        if (workQty == null || workQty <= 0)
+        {
+            // 閫氳繃鐗╂枡缂栫爜锛圖aa002锛夊尮閰嶅伐鍗�
+            var workOrder = db.Queryable<Womdaa>()
+                .Where(w => w.Daa002 == itemNo)
+                .OrderByDescending(w => w.Id)
+                .First();
+            
+            if (workOrder != null)
+            {
+                workQty = workOrder.Daa008; // 宸ュ崟鏁伴噺
+            }
+        }
+
+        // 鍏堣幏鍙栧熀纭�鏁版嵁
+        var qualityStandards = db
             .Queryable<MesQualityStandard>()
-            .Where(b => b.QsType == "2"
-                        && b.ItemNo == itemNo).Select(
-                b => new QsQaItemXj01
-                {
-                    ProjName = b.ProjName,
-                    ItemMod = b.ItemMod,
-                    InspectionMethod = b.InspectionMethod,
-                    UsingInstruments = b.UsingInstruments,
-                    LevelNum = SqlFunc.IsNull(
-                        SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
-                        b.InspectionLevel),
-                    MaxValue = b.MaxValue,
-                    StandardValue = b.StandardValue,
-                    MinValue = b.MinValue,
-                    Notes = b.Notes,
-                    FcheckLevel = b.FcheckLevel,
-                    FacLevel = b.FacLevel,
-                    QsCode = b.QsCode,
-                    QsName = b.QsName,
-                    result = "鏈娴�",
-                    isCheck = 0,
-                    Picture = b.Picture,
-                    Picturename = b.Picturename
-                }).ToList();
+            .Where(b => b.QsType == "2" && b.ItemNo == itemNo)
+            .ToList();
+
+        // 鍦ㄥ唴瀛樹腑璁$畻妫�楠屾暟閲�
+        return qualityStandards.Select(b => {
+            var calculatedLevelNum = CalculateInspectionQuantity(b.InspectionLevel, workQty);
+            
+            return new QsQaItemXj01
+            {
+                ProjName = b.ProjName,
+                ItemMod = b.ItemMod,
+                InspectionMethod = b.InspectionMethod,
+                UsingInstruments = b.UsingInstruments,
+                LevelNum = calculatedLevelNum,
+                MaxValue = b.MaxValue,
+                StandardValue = b.StandardValue,
+                MinValue = b.MinValue,
+                Notes = b.Notes,
+                FcheckLevel = b.FcheckLevel,
+                FacLevel = b.FacLevel,
+                QsCode = b.QsCode,
+                QsName = b.QsName,
+                result = "鏈娴�",
+                isCheck = 0,
+                Picture = b.Picture,
+                Picturename = b.Picturename
+            };
+        }).ToList();
+    }
+
+    /// <summary>
+    /// 璁$畻妫�楠屾暟閲忥細濡傛灉鎶芥鏁伴噺澶т簬宸ュ崟鏁伴噺锛屽垯妫�楠屾暟閲忎负宸ュ崟鏁伴噺锛屽惁鍒欎负鎶芥鏁伴噺
+    /// </summary>
+    /// <param name="samplingQuantity">鎶芥鏁伴噺</param>
+    /// <param name="workQty">宸ュ崟鏁伴噺</param>
+    /// <returns>妫�楠屾暟閲�</returns>
+    private decimal? CalculateInspectionQuantity(decimal? samplingQuantity, decimal? workQty)
+    {
+        // 濡傛灉娌℃湁宸ュ崟鏁伴噺锛屼娇鐢ㄦ娊妫�鏁伴噺
+        if (workQty == null || workQty <= 0)
+        {
+            return samplingQuantity;
+        }
+
+        // 濡傛灉鎶芥鏁伴噺澶т簬宸ュ崟鏁伴噺锛屽垯妫�楠屾暟閲忎负宸ュ崟鏁伴噺锛屽惁鍒欎负鎶芥鏁伴噺
+        return samplingQuantity > workQty ? workQty : samplingQuantity;
     }
 
     public List<QsQaItemXj01> getJYItem(decimal? pid, decimal? id)

--
Gitblit v1.9.3