From 4b1f57988caee329bc79cebd1edca02fc5faf710 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 28 五月 2026 15:02:55 +0800
Subject: [PATCH] chore: 智芯智能配置文件

---
 src/main/resources/mapper/quality/QualityInspectMapper.xml |  331 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 319 insertions(+), 12 deletions(-)

diff --git a/src/main/resources/mapper/quality/QualityInspectMapper.xml b/src/main/resources/mapper/quality/QualityInspectMapper.xml
index 4e8a057..72f166c 100644
--- a/src/main/resources/mapper/quality/QualityInspectMapper.xml
+++ b/src/main/resources/mapper/quality/QualityInspectMapper.xml
@@ -1,35 +1,73 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.ruoyi.quality.mapper.QualityInspectMapper">
-    <select id="qualityInspectListPage" resultType="com.ruoyi.quality.pojo.QualityInspect">
+    <select id="qualityInspectListPage" resultType="com.ruoyi.quality.dto.QualityInspectDto">
         SELECT
-        *
-        FROM quality_inspect
-        where
+        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>
+                pot.work_order_no,
+                po_sales.sales_contract_no
+            </otherwise>
+        </choose>
+        FROM
+        quality_inspect qi
+        <choose>
+            <when test="qualityInspect.inspectType == 0 ">
+                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 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
         inspect_type=#{qualityInspect.inspectType}
         <if test="qualityInspect.supplier != null and qualityInspect.supplier != '' ">
-            AND supplier like concat('%',#{qualityInspect.supplier},'%')
+            AND qi.supplier like concat('%',#{qualityInspect.supplier},'%')
         </if>
         <if test="qualityInspect.customer != null and qualityInspect.customer != '' ">
-            AND customer like concat('%',#{qualityInspect.customer},'%')
+            AND qi.customer like concat('%',#{qualityInspect.customer},'%')
         </if>
         <if test="qualityInspect.process != null and qualityInspect.process != '' ">
-            AND process like concat('%',#{qualityInspect.process},'%')
+            AND qi.process like concat('%',#{qualityInspect.process},'%')
         </if>
         <if test="qualityInspect.productName != null and qualityInspect.productName != '' ">
-            AND product_name like concat('%',#{qualityInspect.productName},'%')
+            AND qi.product_name like concat('%',#{qualityInspect.productName},'%')
         </if>
         <if test="qualityInspect.entryDateStart != null and qualityInspect.entryDateStart != '' ">
-            AND check_time &gt;= DATE_FORMAT(#{qualityInspect.entryDateStart},'%Y-%m-%d')
+            AND qi.check_time &gt;= DATE_FORMAT(#{qualityInspect.entryDateStart},'%Y-%m-%d')
         </if>
         <if test="qualityInspect.entryDateEnd != null and qualityInspect.entryDateEnd != '' ">
-            AND  check_time &lt;= DATE_FORMAT(#{qualityInspect.entryDateEnd},'%Y-%m-%d')
+            AND qi.check_time &lt;= DATE_FORMAT(#{qualityInspect.entryDateEnd},'%Y-%m-%d')
         </if>
-        ORDER BY check_time DESC
+        ORDER BY qi.check_time DESC
     </select>
+
     <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}
@@ -55,4 +93,273 @@
         </foreach>
     </delete>
 
+    <select id="getInspectStatistics" resultType="com.ruoyi.quality.dto.QualityInspectStatDto">
+        SELECT qi.inspect_type AS modelType,
+
+               IFNULL(SUM(qi.quantity), 0) AS totalCount,
+
+               IFNULL(SUM(CASE
+                              WHEN qi.inspect_state = 1 THEN qi.quantity
+                              ELSE 0
+                   END), 0)                AS completedCount
+
+        FROM quality_inspect qi
+
+        GROUP BY qi.inspect_type
+
+    </select>
+
+    <select id="getPassRateStatistics" resultType="com.ruoyi.quality.dto.QualityPassRateDto">
+        SELECT t.modelType,
+               t.totalCount,
+               t.completedCount,
+               t.qualifiedCount,
+               t.unqualifiedCount,
+
+            /* 瀹屾垚鐜囷細
+               濡傛灉鎬绘暟涓� 0 鍒欒繑鍥� 0锛涘惁鍒欒绠楁瘮渚嬶紝浣跨敤 TRUNCATE 淇濈暀 4 浣嶅皬鏁帮紙濡� 99.9992锛�
+            */
+               IF(t.totalCount = 0, 0,
+                  TRUNCATE((t.completedCount / t.totalCount) * 100, 2)
+               ) AS completionRate,
+
+            /* 鍚堟牸鐜囷細
+               濡傛灉瀹屽伐鏁颁负 0 鍒欒繑鍥� 0锛涗娇鐢� TRUNCATE 鎴柇锛岄槻姝㈡瀬鍏舵帴杩� 100% 鐨勬暟鎹鍥涜垗浜斿叆鎴� 100
+            */
+               IF(t.completedCount = 0, 0,
+                  TRUNCATE((t.qualifiedCount / t.completedCount) * 100, 2)
+               ) AS passRate
+        FROM (
+                 /* 鍏堥�氳繃瀛愭煡璇㈡妸鍩虹鏁版嵁杩涜鑱氬悎缁熻锛岄伩鍏嶅灞傞噸澶嶇紪鍐欏鏉傜殑 CASE WHEN */
+                 SELECT qi.inspect_type                                                                          AS modelType,
+                        COALESCE(SUM(qi.quantity), 0)                                                            AS totalCount,
+                        COALESCE(SUM(CASE WHEN qi.inspect_state = 1 THEN qi.quantity ELSE 0 END),
+                                 0)                                                                              AS completedCount,
+                        COALESCE(SUM(CASE WHEN qi.inspect_state = 1 THEN qi.qualified_quantity ELSE 0 END),
+                                 0)                                                                              AS qualifiedCount,
+                        COALESCE(SUM(CASE WHEN qi.inspect_state = 1 THEN qi.unqualified_quantity ELSE 0 END),
+                                 0)                                                                              AS unqualifiedCount
+                 FROM quality_inspect qi
+                 GROUP BY qi.inspect_type) t
+        ORDER BY t.modelType;
+    </select>
+
+
+    <select id="getMonthlyPassRateStatistics" resultType="com.ruoyi.quality.dto.QualityMonthlyPassRateDto">
+        WITH RECURSIVE
+            months AS (SELECT 1 AS month_num
+                       UNION ALL
+                       SELECT month_num + 1
+                       FROM months
+                       WHERE month_num &lt; 12),
+            types AS (SELECT 0 AS modelType
+                      UNION ALL
+                      SELECT 1
+                      UNION ALL
+                      SELECT 2),
+            base AS (SELECT m.month_num, t.modelType
+                     FROM months m
+                              CROSS JOIN types t)
+
+        SELECT
+            CASE t.month_num
+                WHEN 1 THEN '涓�鏈�'
+                WHEN 2 THEN '浜屾湀'
+                WHEN 3 THEN '涓夋湀'
+                WHEN 4 THEN '鍥涙湀'
+                WHEN 5 THEN '浜旀湀'
+                WHEN 6 THEN '鍏湀'
+                WHEN 7 THEN '涓冩湀'
+                WHEN 8 THEN '鍏湀'
+                WHEN 9 THEN '涔濇湀'
+                WHEN 10 THEN '鍗佹湀'
+                WHEN 11 THEN '鍗佷竴鏈�'
+                WHEN 12 THEN '鍗佷簩鏈�'
+                END AS month,
+
+        t.modelType,
+        t.totalCount,
+        t.completedCount,
+        t.qualifiedCount,
+        t.unqualifiedCount,
+
+        IF(t.totalCount = 0, 0,
+           TRUNCATE((t.completedCount / t.totalCount) * 100, 2)
+        ) AS completionRate,
+
+        IF(t.completedCount = 0, 0,
+           TRUNCATE((t.qualifiedCount / t.completedCount) * 100, 2)
+        ) AS passRate
+
+        FROM (
+            SELECT
+            b.month_num,
+            b.modelType,
+            COALESCE(SUM(qi.quantity), 0) AS totalCount,
+            COALESCE(SUM(CASE WHEN qi.inspect_state = 1 THEN qi.quantity ELSE 0 END), 0) AS completedCount,
+            COALESCE(SUM(CASE WHEN qi.inspect_state = 1 THEN qi.qualified_quantity ELSE 0 END), 0) AS qualifiedCount,
+            COALESCE(SUM(CASE WHEN qi.inspect_state = 1 THEN qi.unqualified_quantity ELSE 0 END), 0) AS unqualifiedCount
+            FROM base b
+            LEFT JOIN quality_inspect qi ON qi.inspect_type = b.modelType
+            AND YEAR(qi.check_time) = #{year}
+            AND MONTH(qi.check_time) = b.month_num
+            GROUP BY b.month_num, b.modelType
+            ) t
+        ORDER BY t.month_num, t.modelType;
+    </select>
+    <select id="getYearlyPassRateStatistics" resultType="com.ruoyi.quality.dto.QualityPassRateDto">
+        SELECT qi.inspect_type AS modelType,
+
+               COALESCE(SUM(qi.quantity), 0) AS totalCount,
+
+               COALESCE(SUM(
+                                CASE
+                                    WHEN qi.inspect_state = 1 THEN qi.quantity
+                                    ELSE 0
+                                    END
+                        ), 0)                AS completedCount,
+
+               COALESCE(SUM(
+                                CASE
+                                    WHEN qi.inspect_state = 1 THEN qi.qualified_quantity
+                                    ELSE 0
+                                    END
+                        ), 0)                AS qualifiedCount,
+
+               COALESCE(SUM(
+                                CASE
+                                    WHEN qi.inspect_state = 1 THEN qi.unqualified_quantity
+                                    ELSE 0
+                                    END
+                        ), 0)                AS unqualifiedCount,
+
+            /* 瀹屾垚鐜� */
+               IF(COALESCE(SUM(qi.quantity), 0) = 0, 0,
+                  ROUND(
+                          COALESCE(SUM(
+                                           CASE WHEN qi.inspect_state = 1 THEN qi.quantity ELSE 0 END
+                                   ), 0)
+                              / SUM(qi.quantity) * 100, 2)
+               )                             AS completionRate,
+
+            /* 鍚堟牸鐜� */
+               IF(COALESCE(SUM(
+                                   CASE WHEN qi.inspect_state = 1 THEN qi.quantity ELSE 0 END
+                           ), 0) = 0, 0,
+                  ROUND(
+                          COALESCE(SUM(
+                                           CASE WHEN qi.inspect_state = 1 THEN qi.qualified_quantity ELSE 0 END
+                                   ), 0)
+                              /
+                          COALESCE(SUM(
+                                           CASE WHEN qi.inspect_state = 1 THEN qi.quantity ELSE 0 END
+                                   ), 0) * 100, 2)
+               )                             AS passRate
+
+        FROM quality_inspect qi
+        WHERE YEAR(qi.check_time) = #{year}
+        GROUP BY qi.inspect_type
+        ORDER BY qi.inspect_type;
+    </select>
+
+
+
+    <select id="getMonthlyCompletionDetails" resultType="com.ruoyi.quality.dto.QualityMonthlyDetailDto">
+        WITH RECURSIVE months AS (SELECT 1 AS month_num
+                                  UNION ALL
+                                  SELECT month_num + 1
+                                  FROM months
+                                  WHERE month_num &lt; 12)
+        SELECT CASE m.month_num
+                   WHEN 1 THEN '涓�鏈�'
+                   WHEN 2 THEN '浜屾湀'
+                   WHEN 3 THEN '涓夋湀'
+                   WHEN 4 THEN '鍥涙湀'
+                   WHEN 5 THEN '浜旀湀'
+                   WHEN 6 THEN '鍏湀'
+                   WHEN 7 THEN '涓冩湀'
+                   WHEN 8 THEN '鍏湀'
+                   WHEN 9 THEN '涔濇湀'
+                   WHEN 10 THEN '鍗佹湀'
+                   WHEN 11 THEN '鍗佷竴鏈�'
+                   WHEN 12 THEN '鍗佷簩鏈�'
+                   END        AS month,
+
+            /* 鍘熸潗鏂� */
+               COALESCE(SUM(
+                                CASE
+                                    WHEN qi.inspect_type = 0
+                                        THEN qi.quantity
+                                    ELSE 0
+                                    END
+                        ), 0) AS rawMaterialCount,
+
+            /* 鍗婃垚鍝� */
+               COALESCE(SUM(
+                                CASE
+                                    WHEN qi.inspect_type = 1
+                                        THEN qi.quantity
+                                    ELSE 0
+                                    END
+                        ), 0) AS processCount,
+
+            /* 鎴愬搧 */
+               COALESCE(SUM(
+                                CASE
+                                    WHEN qi.inspect_type = 2
+                                        THEN qi.quantity
+                                    ELSE 0
+                                    END
+                        ), 0) AS outgoingCount
+
+        FROM months m
+                 LEFT JOIN quality_inspect qi
+                           ON qi.inspect_state = 1
+                               AND YEAR(qi.check_time) = #{year}
+                               AND MONTH(qi.check_time) = m.month_num
+
+        GROUP BY m.month_num
+        ORDER BY m.month_num;
+
+    </select>
+
+    <select id="getTopParameters" resultType="com.ruoyi.quality.dto.QualityParameterStatDto">
+        WITH parameter_counts AS (SELECT qip.parameter_item AS name,
+                                         COUNT(*)           AS count
+                                  FROM quality_inspect_param qip
+                                           JOIN quality_inspect qi
+                                                ON qip.inspect_id = qi.id
+                                  WHERE qi.inspect_state = 1
+                                    AND qi.inspect_type = #{modelType} - 1
+                                  GROUP BY qip.parameter_item),
+             ranked AS (SELECT name,
+                               count,
+                               ROW_NUMBER() OVER (ORDER BY count DESC) AS rn
+                        FROM parameter_counts),
+             total AS (SELECT SUM(count) AS total_count
+                       FROM parameter_counts)
+
+        SELECT name,
+               count,
+               CASE
+                   WHEN (SELECT total_count FROM total) = 0 THEN 0
+                   ELSE ROUND(count / (SELECT total_count FROM total) * 100, 2)
+                   END AS percentage
+        FROM (SELECT name, count, rn
+              FROM ranked
+              WHERE rn &lt;= 4
+
+              UNION ALL
+
+              SELECT '鍏朵粬妫�娴�' AS name,
+                     SUM(count) AS count,
+                     5          AS rn
+              FROM ranked
+              WHERE rn > 4
+              HAVING SUM(count) > 0) t
+        ORDER BY rn;
+
+    </select>
+
+
 </mapper>

--
Gitblit v1.9.3