From b9c179cc7dddff42fbb0b1437f6737f2d0f44048 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期六, 23 五月 2026 16:26:21 +0800
Subject: [PATCH] fix: 移除检测结果修改为返回合格率

---
 src/main/resources/mapper/quality/QualityInspectMapper.xml |   71 ++++++++++++++++++++++++-----------
 1 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/src/main/resources/mapper/quality/QualityInspectMapper.xml b/src/main/resources/mapper/quality/QualityInspectMapper.xml
index e5ce119..e4c3dd0 100644
--- a/src/main/resources/mapper/quality/QualityInspectMapper.xml
+++ b/src/main/resources/mapper/quality/QualityInspectMapper.xml
@@ -4,13 +4,17 @@
     <select id="qualityInspectListPage" resultType="com.ruoyi.quality.dto.QualityInspectDto">
         SELECT
         qi.*,
+        CASE
+            WHEN (IFNULL(qi.qualified_quantity, 0) + IFNULL(qi.unqualified_quantity, 0)) = 0 THEN 0
+            ELSE ROUND(IFNULL(qi.qualified_quantity, 0) / (IFNULL(qi.qualified_quantity, 0) + IFNULL(qi.unqualified_quantity, 0)) * 100, 2)
+        END AS passRate,
         <choose>
             <when test="qualityInspect.inspectType == 0">
                 pl.purchase_contract_number as purchase_contract_no
             </when>
             <otherwise>
-                pwo.work_order_no,
-                sl.sales_contract_no
+                pot.work_order_no,
+                po_sales.sales_contract_no
             </otherwise>
         </choose>
         FROM
@@ -21,9 +25,17 @@
             </when>
             <otherwise>
                 LEFT JOIN production_product_main ppm ON qi.product_main_id = ppm.id
-                LEFT JOIN product_work_order pwo ON ppm.work_order_id = pwo.id
-                left join product_order po ON po.id = pwo.product_order_id
-                left join sales_ledger sl ON sl.id = po.sales_ledger_id
+                LEFT JOIN production_operation_task pot ON ppm.production_operation_task_id = pot.id
+                left join production_order po ON po.id = pot.production_order_id
+                left join (
+                    select po2.id as order_id,
+                           group_concat(distinct sl2.sales_contract_no order by sl2.sales_contract_no separator ',') as sales_contract_no
+                    from production_order po2
+                             left join production_plan pp2
+                                       on find_in_set(pp2.id, replace(replace(replace(po2.production_plan_ids, '[', ''), ']', ''), ' ', '')) > 0
+                             left join sales_ledger sl2 on sl2.id = pp2.sales_ledger_id
+                    group by po2.id
+                ) po_sales ON po_sales.order_id = po.id
             </otherwise>
         </choose>
         WHERE
@@ -51,7 +63,11 @@
 
     <select id="qualityInspectExport" resultType="com.ruoyi.quality.pojo.QualityInspect">
         SELECT
-        *
+        qi.*,
+        CASE
+            WHEN (IFNULL(qi.qualified_quantity, 0) + IFNULL(qi.unqualified_quantity, 0)) = 0 THEN 0
+            ELSE ROUND(IFNULL(qi.qualified_quantity, 0) / (IFNULL(qi.qualified_quantity, 0) + IFNULL(qi.unqualified_quantity, 0)) * 100, 2)
+        END AS passRate
         FROM quality_inspect
         where
         inspect_type=#{qualityInspect.inspectType}
@@ -120,8 +136,7 @@
                COALESCE(SUM(
                                 CASE
                                     WHEN qi.inspect_state = 1
-                                        AND qi.check_result = '鍚堟牸'
-                                        THEN qi.quantity
+                                        THEN qi.qualified_quantity
                                     ELSE 0
                                     END
                         ), 0)                AS qualifiedCount,
@@ -129,8 +144,7 @@
                COALESCE(SUM(
                                 CASE
                                     WHEN qi.inspect_state = 1
-                                        AND qi.check_result = '涓嶅悎鏍�'
-                                        THEN qi.quantity
+                                        THEN qi.unqualified_quantity
                                     ELSE 0
                                     END
                         ), 0)                AS unqualifiedCount,
@@ -158,8 +172,7 @@
                           COALESCE(SUM(
                                            CASE
                                                WHEN qi.inspect_state = 1
-                                                   AND qi.check_result = '鍚堟牸'
-                                                   THEN qi.quantity
+                                                   THEN qi.qualified_quantity
                                                ELSE 0
                                                END
                                    ), 0)
@@ -240,8 +253,8 @@
             /* 鍚堟牸 */
                COALESCE(SUM(
                                 CASE
-                                    WHEN qi.inspect_state = 1 AND qi.check_result = '鍚堟牸'
-                                        THEN qi.quantity
+                                    WHEN qi.inspect_state = 1
+                                        THEN qi.qualified_quantity
                                     ELSE 0
                                     END
                         ), 0)                AS qualifiedCount,
@@ -249,8 +262,8 @@
             /* 涓嶅悎鏍� */
                COALESCE(SUM(
                                 CASE
-                                    WHEN qi.inspect_state = 1 AND qi.check_result = '涓嶅悎鏍�'
-                                        THEN qi.quantity
+                                    WHEN qi.inspect_state = 1
+                                        THEN qi.unqualified_quantity
                                     ELSE 0
                                     END
                         ), 0)                AS unqualifiedCount,
@@ -271,8 +284,8 @@
                   ROUND(
                           COALESCE(SUM(
                                            CASE
-                                               WHEN qi.inspect_state = 1 AND qi.check_result = '鍚堟牸'
-                                                   THEN qi.quantity
+                                               WHEN qi.inspect_state = 1
+                                                   THEN qi.qualified_quantity
                                                ELSE 0
                                                END
                                    ), 0)
@@ -304,7 +317,6 @@
 
     <select id="getYearlyPassRateStatistics" resultType="com.ruoyi.quality.dto.QualityPassRateDto">
         SELECT t.modelType,
-
                COALESCE(SUM(
                                 CASE
                                     WHEN pp.product_name = '鍘熸潗鏂�' AND t.modelType = 0 THEN qi.quantity
@@ -312,8 +324,23 @@
                                     WHEN pp.product_name = '鎴愬搧' AND t.modelType = 2 THEN qi.quantity
                                     ELSE 0
                                     END
-                        ), 0) AS totalCount
-
+                        ), 0) AS totalCount,
+               COALESCE(SUM(
+                                CASE
+                                    WHEN pp.product_name = '鍘熸潗鏂�' AND t.modelType = 0 THEN qi.qualified_quantity
+                                    WHEN pp.product_name = '鍗婃垚鍝�' AND t.modelType = 1 THEN qi.qualified_quantity
+                                    WHEN pp.product_name = '鎴愬搧' AND t.modelType = 2 THEN qi.qualified_quantity
+                                    ELSE 0
+                                    END
+                        ), 0) AS qualifiedCount,
+               COALESCE(SUM(
+                                CASE
+                                    WHEN pp.product_name = '鍘熸潗鏂�' AND t.modelType = 0 THEN qi.unqualified_quantity
+                                    WHEN pp.product_name = '鍗婃垚鍝�' AND t.modelType = 1 THEN qi.unqualified_quantity
+                                    WHEN pp.product_name = '鎴愬搧' AND t.modelType = 2 THEN qi.unqualified_quantity
+                                    ELSE 0
+                                    END
+                        ), 0) AS unqualifiedCount
         FROM (SELECT 0 AS modelType
               UNION ALL
               SELECT 1
@@ -326,8 +353,6 @@
                            ON qi.product_model_id = pm.id
                                AND YEAR(qi.check_time) = #{year}
                                AND qi.inspect_state = 1
-                               AND qi.check_result = '鍚堟牸'
-
         GROUP BY t.modelType
         ORDER BY t.modelType;
     </select>

--
Gitblit v1.9.3