From 5d81fcc5768741323a2e343fc01f44e17e68b65b Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 25 六月 2026 14:59:38 +0800
Subject: [PATCH] 1.库存入库新增质检流程 2.销售相关查询返回总合同号 3.采购相关查询返回总合同号

---
 src/main/resources/mapper/quality/QualityInspectMapper.xml |   73 ++++++++++++++++++++++++++----------
 1 files changed, 52 insertions(+), 21 deletions(-)

diff --git a/src/main/resources/mapper/quality/QualityInspectMapper.xml b/src/main/resources/mapper/quality/QualityInspectMapper.xml
index f252881..29cc361 100644
--- a/src/main/resources/mapper/quality/QualityInspectMapper.xml
+++ b/src/main/resources/mapper/quality/QualityInspectMapper.xml
@@ -5,23 +5,24 @@
         SELECT
         qi.*,
         <choose>
-            <when test="qualityInspect.inspectType == 0">
+            <when test="qualityInspect.inspectType != 2">
                 pl.purchase_contract_number as purchase_contract_no
             </when>
             <otherwise>
                 pot.work_order_no,
-                po_sales.sales_contract_no
+                COALESCE(sl.sales_contract_no, po_sales.sales_contract_no) as sales_contract_no
             </otherwise>
         </choose>
         FROM
         quality_inspect qi
         <choose>
-            <when test="qualityInspect.inspectType == 0 ">
+            <when test="qualityInspect.inspectType != 2 ">
                 LEFT JOIN purchase_ledger pl ON pl.id = qi.purchase_ledger_id
             </when>
             <otherwise>
                 LEFT JOIN production_product_main ppm ON qi.product_main_id = ppm.id
                 LEFT JOIN production_operation_task pot ON ppm.production_operation_task_id = pot.id
+                LEFT JOIN sales_ledger sl ON sl.id = qi.sales_ledger_id
                 left join production_order po ON po.id = pot.production_order_id
                 left join (
                     select po2.id as order_id,
@@ -54,7 +55,17 @@
         <if test="qualityInspect.entryDateEnd != null and qualityInspect.entryDateEnd != '' ">
             AND qi.check_time &lt;= DATE_FORMAT(#{qualityInspect.entryDateEnd},'%Y-%m-%d')
         </if>
-        ORDER BY qi.check_time DESC
+        <if test="qualityInspect.purchaseContractNo != null and qualityInspect.purchaseContractNo != '' ">
+            AND pl.purchase_contract_number like concat('%',#{qualityInspect.purchaseContractNo},'%')
+        </if>
+        <if test="qualityInspect.workOrderNo != null and qualityInspect.workOrderNo != '' ">
+            AND pot.work_order_no like concat('%',#{qualityInspect.workOrderNo},'%')
+        </if>
+        <if test="qualityInspect.salesContractNo != null and qualityInspect.salesContractNo != '' ">
+            AND (sl.sales_contract_no like concat('%',#{qualityInspect.salesContractNo},'%')
+                OR po_sales.sales_contract_no like concat('%',#{qualityInspect.salesContractNo},'%'))
+        </if>
+        ORDER BY qi.create_time DESC
     </select>
 
     <select id="qualityInspectExport" resultType="com.ruoyi.quality.pojo.QualityInspect">
@@ -128,8 +139,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,
@@ -137,8 +147,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,
@@ -166,8 +175,7 @@
                           COALESCE(SUM(
                                            CASE
                                                WHEN qi.inspect_state = 1
-                                                   AND qi.check_result = '鍚堟牸'
-                                                   THEN qi.quantity
+                                                   THEN qi.qualified_quantity
                                                ELSE 0
                                                END
                                    ), 0)
@@ -248,8 +256,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,
@@ -257,8 +265,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,
@@ -279,8 +287,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)
@@ -312,7 +320,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
@@ -320,8 +327,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
@@ -334,8 +356,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>
@@ -451,5 +471,16 @@
 
     </select>
 
+    <select id="selectProductModelById" resultType="com.ruoyi.basic.pojo.ProductModel">
+        SELECT id, product_id, model, unit
+        FROM product_model
+        WHERE id = #{id}
+    </select>
+
+    <select id="selectProductById" resultType="com.ruoyi.basic.pojo.Product">
+        SELECT id, product_name
+        FROM product
+        WHERE id = #{id}
+    </select>
 
 </mapper>

--
Gitblit v1.9.3