From 211d2887af4608fbdfd40af1e16e4f58131dfaa2 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期五, 28 八月 2026 23:08:54 +0800
Subject: [PATCH] feat: 添加清除当前用户的所有消息接口

---
 src/main/resources/mapper/quality/QualityInspectMapper.xml |  136 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 114 insertions(+), 22 deletions(-)

diff --git a/src/main/resources/mapper/quality/QualityInspectMapper.xml b/src/main/resources/mapper/quality/QualityInspectMapper.xml
index e5ce119..7e0bd51 100644
--- a/src/main/resources/mapper/quality/QualityInspectMapper.xml
+++ b/src/main/resources/mapper/quality/QualityInspectMapper.xml
@@ -9,8 +9,8 @@
                 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 +21,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
@@ -45,6 +53,15 @@
         </if>
         <if test="qualityInspect.entryDateEnd != null and qualityInspect.entryDateEnd != '' ">
             AND qi.check_time &lt;= DATE_FORMAT(#{qualityInspect.entryDateEnd},'%Y-%m-%d')
+        </if>
+        <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 po_sales.sales_contract_no like concat('%',#{qualityInspect.salesContractNo},'%')
         </if>
         ORDER BY qi.check_time DESC
     </select>
@@ -120,8 +137,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 +145,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 +173,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 +254,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 +263,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 +285,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 +318,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 +325,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 +354,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>
@@ -443,5 +469,71 @@
 
     </select>
 
+    <sql id="personGroupRateJoin">
+        FROM quality_inspect qi
+                 INNER JOIN production_product_main ppm ON qi.product_main_id = ppm.id
+                 LEFT JOIN (
+            SELECT production_product_main_id,
+                   CAST(SUM(IFNULL(scrap_qty, 0)) AS DECIMAL(18,4)) AS scrapCount
+            FROM production_product_output
+            GROUP BY production_product_main_id
+        ) ppo ON ppo.production_product_main_id = ppm.id
+                 LEFT JOIN (
+            SELECT inspect_id,
+                   CAST(SUM(CASE WHEN deal_type IN (0, 1) THEN IFNULL(quantity, 0) ELSE 0 END) AS DECIMAL(18,4)) AS reworkCount
+            FROM quality_unqualified
+            WHERE inspect_state = 1
+            GROUP BY inspect_id
+        ) qu ON qu.inspect_id = qi.id
+    </sql>
+
+    <sql id="personGroupRateWhere">
+        WHERE qi.inspect_type IN (1, 2)
+          AND qi.inspect_state = 1
+          AND qi.product_main_id IS NOT NULL
+    </sql>
+
+    <select id="getPersonRateStatistics" resultType="com.ruoyi.quality.dto.QualityPersonGroupRateDto">
+        SELECT ppm.user_id AS dimensionId,
+               COALESCE(NULLIF(ppm.user_name, ''), su.nick_name, CONCAT('鐢ㄦ埛', ppm.user_id)) AS dimensionName,
+               CAST(SUM(IFNULL(qi.quantity, 0)) AS DECIMAL(18,4)) AS totalCount,
+               CAST(SUM(IFNULL(qi.qualified_quantity, 0)) AS DECIMAL(18,4)) AS qualifiedCount,
+               CAST(SUM(IFNULL(qi.unqualified_quantity, 0)) AS DECIMAL(18,4)) AS unqualifiedCount,
+               CAST(SUM(IFNULL(qu.reworkCount, 0)) AS DECIMAL(18,4)) AS reworkCount,
+               CAST(SUM(IFNULL(ppo.scrapCount, 0)) AS DECIMAL(18,4)) AS scrapCount,
+               CAST(IF(SUM(IFNULL(qi.quantity, 0)) = 0, 0,
+                       ROUND(SUM(IFNULL(qi.qualified_quantity, 0)) / SUM(IFNULL(qi.quantity, 0)) * 100, 2)) AS DECIMAL(18,2)) AS passRate,
+               CAST(IF(SUM(IFNULL(qi.quantity, 0)) = 0, 0,
+                       ROUND(SUM(IFNULL(qu.reworkCount, 0)) / SUM(IFNULL(qi.quantity, 0)) * 100, 2)) AS DECIMAL(18,2)) AS reworkRate,
+               CAST(IF(SUM(IFNULL(qi.quantity, 0)) + SUM(IFNULL(ppo.scrapCount, 0)) = 0, 0,
+                       ROUND(SUM(IFNULL(ppo.scrapCount, 0)) / (SUM(IFNULL(qi.quantity, 0)) + SUM(IFNULL(ppo.scrapCount, 0))) * 100, 2)) AS DECIMAL(18,2)) AS scrapRate
+        <include refid="personGroupRateJoin"/>
+                 LEFT JOIN sys_user su ON su.user_id = ppm.user_id
+        <include refid="personGroupRateWhere"/>
+        GROUP BY ppm.user_id, COALESCE(NULLIF(ppm.user_name, ''), su.nick_name, CONCAT('鐢ㄦ埛', ppm.user_id))
+        ORDER BY passRate DESC, totalCount DESC, dimensionId ASC
+    </select>
+
+    <select id="getGroupRateStatistics" resultType="com.ruoyi.quality.dto.QualityPersonGroupRateDto">
+        SELECT ppm.user_id AS dimensionId,
+               COALESCE(NULLIF(ppm.user_name, ''), su.nick_name, CONCAT('鐝粍浜哄憳', ppm.user_id)) AS dimensionName,
+               CAST(SUM(IFNULL(qi.quantity, 0)) AS DECIMAL(18,4)) AS totalCount,
+               CAST(SUM(IFNULL(qi.qualified_quantity, 0)) AS DECIMAL(18,4)) AS qualifiedCount,
+               CAST(SUM(IFNULL(qi.unqualified_quantity, 0)) AS DECIMAL(18,4)) AS unqualifiedCount,
+               CAST(SUM(IFNULL(qu.reworkCount, 0)) AS DECIMAL(18,4)) AS reworkCount,
+               CAST(SUM(IFNULL(ppo.scrapCount, 0)) AS DECIMAL(18,4)) AS scrapCount,
+               CAST(IF(SUM(IFNULL(qi.quantity, 0)) = 0, 0,
+                       ROUND(SUM(IFNULL(qi.qualified_quantity, 0)) / SUM(IFNULL(qi.quantity, 0)) * 100, 2)) AS DECIMAL(18,2)) AS passRate,
+               CAST(IF(SUM(IFNULL(qi.quantity, 0)) = 0, 0,
+                       ROUND(SUM(IFNULL(qu.reworkCount, 0)) / SUM(IFNULL(qi.quantity, 0)) * 100, 2)) AS DECIMAL(18,2)) AS reworkRate,
+               CAST(IF(SUM(IFNULL(qi.quantity, 0)) + SUM(IFNULL(ppo.scrapCount, 0)) = 0, 0,
+                       ROUND(SUM(IFNULL(ppo.scrapCount, 0)) / (SUM(IFNULL(qi.quantity, 0)) + SUM(IFNULL(ppo.scrapCount, 0))) * 100, 2)) AS DECIMAL(18,2)) AS scrapRate
+        <include refid="personGroupRateJoin"/>
+                 LEFT JOIN sys_user su ON su.user_id = ppm.user_id
+        <include refid="personGroupRateWhere"/>
+        GROUP BY ppm.user_id, COALESCE(NULLIF(ppm.user_name, ''), su.nick_name, CONCAT('鐝粍浜哄憳', ppm.user_id))
+        ORDER BY passRate DESC, totalCount DESC, dimensionId ASC
+    </select>
+
 
 </mapper>

--
Gitblit v1.9.3