From 0debf5b7bb0246eaef1397975cdb16f4adb9e8d9 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 29 十月 2026 14:36:31 +0800
Subject: [PATCH] refactor(inspection-order): 1.检验委托单绑定机制支持多次下单 2.合格率统计口径调整 3.外购铜导体推送入库MES增加米重 4.报告英文字段调整

---
 inspect-server/src/main/resources/mapper/DataAnalysisMapper.xml |  300 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 158 insertions(+), 142 deletions(-)

diff --git a/inspect-server/src/main/resources/mapper/DataAnalysisMapper.xml b/inspect-server/src/main/resources/mapper/DataAnalysisMapper.xml
index 40c572b..5950330 100644
--- a/inspect-server/src/main/resources/mapper/DataAnalysisMapper.xml
+++ b/inspect-server/src/main/resources/mapper/DataAnalysisMapper.xml
@@ -2,65 +2,15 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.ruoyi.inspect.mapper.DataAnalysisMapper">
 
-    <!-- 鑾峰彇鏈懆鐨勭墿鏂欏睘鎬т俊鎭� -->
-    <select id="getRawPassRateByBarChartByWeek" resultType="java.util.Map">
-        WITH RECURSIVE AllWeeks AS (
-        SELECT 1 AS week
-        UNION ALL
-        SELECT week + 1 FROM AllWeeks WHERE week &lt; 7
-        )
-        SELECT
-        COALESCE(sub.qualified, 0) AS qualified,
-        COALESCE(sub.unQualified, 0) AS unQualified,
-        CASE am.week
-        WHEN 1 THEN '鏄熸湡鏃�'
-        WHEN 2 THEN '鏄熸湡涓�'
-        WHEN 3 THEN '鏄熸湡浜�'
-        WHEN 4 THEN '鏄熸湡涓�'
-        WHEN 5 THEN '鏄熸湡鍥�'
-        WHEN 6 THEN '鏄熸湡浜�'
-        WHEN 7 THEN '鏄熸湡鍏�'
-        END AS searchTime
-        FROM AllWeeks am
-        LEFT JOIN (
-        SELECT
-        DAYOFWEEK(io1.send_time) AS week,
-        SUM(CASE WHEN iiq.inspect_status = 1 THEN 1 ELSE 0 END) AS qualified,
-        SUM(CASE WHEN iiq.inspect_status = 2 or iiq.inspect_status = 4 THEN 1 ELSE 0 END) AS unQualified
-        FROM ifs_inventory_quantity iiq
-        INNER JOIN ins_order io1
-        ON io1.ifs_inventory_id = iiq.id
-        LEFT JOIN (
-        SELECT ins_order_id, MAX(sample) AS sample, MAX(model) AS model
-        FROM ins_sample
-        GROUP BY ins_order_id
-        ) ins ON ins.ins_order_id = io1.id
-        WHERE
-        iiq.is_finish = 1
-        AND iiq.inspect_status IN (1, 2,4)
-        AND io1.order_type = #{dto.orderType}
-        AND io1.state != -1
-        AND io1.send_time BETWEEN #{dto.beginDate} AND #{dto.endDate}
-
-        <if test="dto.materialProp != null and dto.materialProp.trim() != ''">
-            AND IFNULL(iiq.material_prop,'') LIKE CONCAT('%',#{dto.materialProp},'%')
-        </if>
-        <if test="dto.sampleName != null and dto.sampleName.trim() != ''">
-            AND IFNULL(ins.sample,'') LIKE CONCAT('%',#{dto.sampleName},'%')
-        </if>
-        <if test="dto.modelName != null and dto.modelName.trim() != ''">
-            AND IFNULL(ins.model,'') LIKE CONCAT('%',#{dto.modelName},'%')
-        </if>
-        <if test="dto.supplierName != null and dto.supplierName.trim() != ''">
-            AND IFNULL(iiq.supplier_name,'') LIKE CONCAT('%',#{dto.supplierName},'%')
-        </if>
-
-        GROUP BY DAYOFWEEK(io1.send_time)
-        ) sub ON am.week = sub.week
-        ORDER BY am.week
-
-    </select>
-
+    <!-- 鏈夐潪绌虹櫧鎻忚堪涓旂鍚堝師鏈� OA 鏉′欢鐨勫鐞嗚褰曪紝鎵嶄綔涓轰笉鍚堟牸渚濇嵁銆� -->
+    <sql id="countableUnqualifiedBatch">
+        SELECT inventory_quantity_id, 1 AS has_unqualified
+        FROM ins_unqualified_handler
+        WHERE oa_state IS NOT NULL
+          AND oa_state != 4
+          AND unqualified_desc REGEXP '[^[:space:]銆�]'
+        GROUP BY inventory_quantity_id
+    </sql>
 
     <!-- 鑾峰彇鏈湀鐨勭墿鏂欏睘鎬т俊鎭� -->
     <!-- 鑾峰彇鏈湀鐨勭墿鏂欏睘鎬т俊鎭紙鎸夊ぉ锛岃ˉ鍏ㄦ棩鏈燂級 -->
@@ -83,16 +33,32 @@
         FROM AllDays ad
         LEFT JOIN (
         SELECT
-        DATE(io1.send_time) AS day,
+        DATE(report_time) AS day,
         COUNT(*) AS total,
-        SUM(CASE WHEN iiq.inspect_status = 1 THEN 1 ELSE 0 END) AS qualified,
-        SUM(CASE WHEN iiq.inspect_status = 2 or iiq.inspect_status = 4 THEN 1 ELSE 0 END) AS unQualified
+        SUM(CASE WHEN has_unqualified = 0 THEN 1 ELSE 0 END) AS qualified,
+        SUM(CASE WHEN has_unqualified = 1 THEN 1 ELSE 0 END) AS unQualified
+        FROM (SELECT
+        IFNULL(iuh.feedback_time,io1.send_time) report_time,
+        iuh.id AS iuh_id,
+        COALESCE(counted_iuh.has_unqualified, 0) AS has_unqualified,
+        iiq.inspect_status
         FROM ifs_inventory_quantity iiq
         LEFT JOIN ins_order io1
         ON io1.ifs_inventory_id = iiq.id
         AND io1.order_type = #{dto.orderType}
         AND io1.state != -1
-        AND io1.send_time BETWEEN #{dto.beginDate} AND #{dto.endDate}
+        LEFT JOIN (
+        <include refid="countableUnqualifiedBatch"/>
+        ) counted_iuh ON counted_iuh.inventory_quantity_id = iiq.id
+        LEFT JOIN (
+        SELECT
+        MAX(iuh.id) AS id,
+        iuh.inventory_quantity_id,
+        iuh.feedback_time
+        FROM ins_unqualified_handler iuh
+        WHERE iuh.oa_state !=4 AND iuh.oa_state is not null
+        GROUP BY iuh.inventory_quantity_id
+        ) iuh ON iiq.id = iuh.inventory_quantity_id
         LEFT JOIN (
         SELECT ins_order_id, MAX(sample) AS sample, MAX(model) AS model
         FROM ins_sample
@@ -101,9 +67,9 @@
         WHERE
         iiq.is_finish = 1
         AND iiq.inspect_status IN (1,2,4)
-
+        AND IFNULL(iuh.feedback_time,io1.send_time) BETWEEN #{dto.beginDate} AND #{dto.endDate}
         <if test="dto.materialProp != null and dto.materialProp != ''">
-            AND IFNULL(iiq.material_prop,'') LIKE CONCAT('%',#{dto.materialProp},'%')
+            AND iiq.material_prop = #{dto.materialProp}
         </if>
         <if test="dto.sampleName != null and dto.sampleName != ''">
             AND IFNULL(ins.sample,'') LIKE CONCAT('%',#{dto.sampleName},'%')
@@ -115,9 +81,9 @@
             AND IFNULL(iiq.supplier_name,'') LIKE CONCAT('%',#{dto.supplierName},'%')
         </if>
         <if test="dto.contract != null and dto.contract != ''">
-            AND IFNULL(iiq.contract,'') = #{dto.contract}
-        </if>
-        GROUP BY DATE(io1.send_time)
+            AND iiq.contract = #{dto.contract}
+        </if>)temp
+        GROUP BY day
         ) sub ON ad.day = sub.day
         ORDER BY ad.day
     </select>
@@ -157,16 +123,33 @@
         FROM AllMonths am
         LEFT JOIN (
         SELECT
-        MONTH(io1.send_time) AS month,
-        COUNT(*) AS total,
-        SUM(CASE WHEN iiq.inspect_status = 1 THEN 1 ELSE 0 END) AS qualified,
-        SUM(CASE WHEN iiq.inspect_status = 2 or iiq.inspect_status = 4 THEN 1 ELSE 0 END) AS unQualified
+            MONTH(report_time) AS month,
+            COUNT(*) AS total,
+            SUM(CASE WHEN has_unqualified = 0 THEN 1 ELSE 0 END) AS qualified,
+            SUM(CASE WHEN has_unqualified = 1 THEN 1 ELSE 0 END) AS unQualified
+        FROM (
+        SELECT
+        IFNULL(iuh.feedback_time,io1.send_time) report_time,
+        iuh.id AS iuh_id,
+        COALESCE(counted_iuh.has_unqualified, 0) AS has_unqualified,
+        iiq.inspect_status
         FROM ifs_inventory_quantity iiq
         LEFT JOIN ins_order io1
         ON io1.ifs_inventory_id = iiq.id
         AND io1.order_type = #{dto.orderType}
         AND io1.state != -1
-        AND io1.send_time BETWEEN #{dto.beginDate} AND #{dto.endDate}
+        LEFT JOIN (
+        <include refid="countableUnqualifiedBatch"/>
+        ) counted_iuh ON counted_iuh.inventory_quantity_id = iiq.id
+        LEFT JOIN (
+        SELECT
+        MAX(iuh.id) AS id,
+        iuh.inventory_quantity_id,
+        iuh.feedback_time
+        FROM ins_unqualified_handler iuh
+        WHERE iuh.oa_state !=4 AND iuh.oa_state is not null
+        GROUP BY iuh.inventory_quantity_id
+        ) iuh ON iiq.id = iuh.inventory_quantity_id
         LEFT JOIN (
         SELECT ins_order_id, MAX(sample) AS sample, MAX(model) AS model
         FROM ins_sample
@@ -175,9 +158,10 @@
         WHERE
         iiq.is_finish = 1
         AND iiq.inspect_status IN (1,2,4)
+        AND IFNULL(iuh.feedback_time,io1.send_time) BETWEEN #{dto.beginDate} AND #{dto.endDate}
 
         <if test="dto.materialProp != null and dto.materialProp != ''">
-            AND IFNULL(iiq.material_prop,'') LIKE CONCAT('%',#{dto.materialProp},'%')
+            AND iiq.material_prop = #{dto.materialProp}
         </if>
         <if test="dto.sampleName != null and dto.sampleName != ''">
             AND IFNULL(ins.sample,'') LIKE CONCAT('%',#{dto.sampleName},'%')
@@ -189,9 +173,9 @@
             AND IFNULL(iiq.supplier_name,'') LIKE CONCAT('%',#{dto.supplierName},'%')
         </if>
         <if test="dto.contract != null and dto.contract != ''">
-            AND IFNULL(iiq.contract,'') = #{dto.contract}
-        </if>
-        GROUP BY MONTH(io1.send_time)
+            AND iiq.contract = #{dto.contract}
+        </if>)temp
+        GROUP BY month
         ) sub ON am.month = sub.month
         ORDER BY am.month
     </select>
@@ -200,19 +184,30 @@
     <!-- 鏌ョ湅鐗╂枡灞炴�чゼ鐘跺浘 -->
     <select id="getRawPassRateByCake" resultType="java.util.Map">
         SELECT
-        COUNT(*) AS sum,
-        /* 鍚堟牸 */
-        SUM(CASE WHEN iiq.inspect_status = 1 THEN 1 ELSE 0 END) AS qualified,
-        /* 涓嶅悎鏍� */
-        SUM(CASE WHEN iiq.inspect_status = 2 or iiq.inspect_status = 4 THEN 1 ELSE 0 END) AS unQualified,
-        ROUND(
-        SUM(CASE WHEN iiq.inspect_status = 1 THEN 1 ELSE 0 END)
-        / COUNT(*) * 100,
-        2
-        ) AS passRate
+            COUNT(*) AS sum,
+            /* 鍚堟牸 */
+            SUM(CASE WHEN has_unqualified = 0 THEN 1 ELSE 0 END) AS qualified,
+            /* 涓嶅悎鏍� */
+            SUM(CASE WHEN has_unqualified = 1 THEN 1 ELSE 0 END) AS unQualified
+        FROM (
+        SELECT
+        iiq.inspect_status,
+        COALESCE(counted_iuh.has_unqualified, 0) AS has_unqualified
         FROM ifs_inventory_quantity iiq
         INNER JOIN ins_order io1
         ON io1.ifs_inventory_id = iiq.id
+        LEFT JOIN (
+        <include refid="countableUnqualifiedBatch"/>
+        ) counted_iuh ON counted_iuh.inventory_quantity_id = iiq.id
+        LEFT JOIN (
+        SELECT
+        MAX(iuh.id) AS id,
+        iuh.inventory_quantity_id,
+        iuh.feedback_time
+        FROM ins_unqualified_handler iuh
+        WHERE iuh.oa_state !=4 AND iuh.oa_state is not null
+        GROUP BY iuh.inventory_quantity_id
+        ) iuh ON iiq.id = iuh.inventory_quantity_id
         LEFT JOIN (
         SELECT
         is2.ins_order_id,
@@ -227,10 +222,9 @@
         AND iiq.inspect_status IN (1, 2,4)
         AND io1.order_type = #{dto.orderType}
         AND io1.state != -1
-        AND io1.send_time BETWEEN #{dto.beginDate} AND #{dto.endDate}
-
+        AND IFNULL(iuh.feedback_time,io1.send_time) BETWEEN #{dto.beginDate} AND #{dto.endDate}
         <if test="dto.materialProp != null and dto.materialProp.trim() != ''">
-            AND IFNULL(iiq.material_prop, '') LIKE CONCAT('%', #{dto.materialProp}, '%')
+            AND iiq.material_prop = #{dto.materialProp}
         </if>
         <if test="dto.sampleName != null and dto.sampleName.trim() != ''">
             AND IFNULL(ins.sample, '') LIKE CONCAT('%', #{dto.sampleName}, '%')
@@ -242,60 +236,74 @@
             AND IFNULL(iiq.supplier_name, '') LIKE CONCAT('%', #{dto.supplierName}, '%')
         </if>
         <if test="dto.contract != null and dto.contract != ''">
-            AND IFNULL(iiq.contract,'') = #{dto.contract}
+            AND iiq.contract = #{dto.contract}
         </if>
+        )temp
     </select>
 
     <select id="getMaterialPropTable" resultType="com.ruoyi.inspect.dto.MaterialPropTableDTO">
         SELECT
-        iiq.supplier_name AS supplierName,
-        COUNT(*) AS totalBatch,
-        SUM(CASE WHEN iiq.inspect_status = 2 or iiq.inspect_status = 4 THEN 1 ELSE 0 END) AS unqualifiedBatch,
-        ROUND(SUM(CASE WHEN iiq.inspect_status = 1 THEN 1 ELSE 0 END) / COUNT(*)* 100, 2 ) AS passRate
+            supplier_name,
+            COUNT(id) AS totalBatch,
+            SUM(CASE WHEN has_unqualified = 1 THEN 1 ELSE 0 END) AS unqualifiedBatch,
+            ROUND(SUM(CASE WHEN has_unqualified = 0 THEN 1 ELSE 0 END) / COUNT(*)* 100, 2 ) AS passRate
+        FROM
+        (
+            SELECT
+                iiq.supplier_name,
+                iiq.id,
+                COALESCE(counted_iuh.has_unqualified, 0) AS has_unqualified,
+                iiq.inspect_status
+            FROM ifs_inventory_quantity iiq
+            INNER JOIN ins_order io1
+            ON io1.ifs_inventory_id = iiq.id
+            AND io1.order_type = #{dto.orderType}
+            AND io1.state != -1
+            LEFT JOIN (
+                <include refid="countableUnqualifiedBatch"/>
+            ) counted_iuh ON counted_iuh.inventory_quantity_id = iiq.id
+            LEFT JOIN (
+            SELECT
+                MAX(iuh.id) AS id,
+                iuh.inventory_quantity_id,
+                iuh.feedback_time
+                FROM ins_unqualified_handler iuh
+                WHERE iuh.oa_state !=4 AND iuh.oa_state is not null
+                GROUP BY iuh.inventory_quantity_id
+            ) iuh ON iiq.id = iuh.inventory_quantity_id
+            LEFT JOIN (
+                SELECT
+                    ins_order_id,
+                    MAX(sample) AS sample,
+                    MAX(model) AS model
+                FROM ins_sample
+                GROUP BY ins_order_id
+            ) ins ON ins.ins_order_id = io1.id
+            WHERE
+            iiq.is_finish = 1
+            AND iiq.inspect_status IN (1,2,4)
+            AND IFNULL(iuh.feedback_time,io1.send_time) between #{dto.beginDate} and #{dto.endDate}
+            <if test="dto.materialProp != null and dto.materialProp != ''">
+                AND iiq.material_prop = #{dto.materialProp}
+            </if>
 
-        FROM ifs_inventory_quantity iiq
-        INNER JOIN ins_order io1
-        ON io1.ifs_inventory_id = iiq.id
-        AND io1.order_type = #{dto.orderType}
-        AND io1.state != -1
-        AND io1.send_time BETWEEN #{dto.beginDate} AND #{dto.endDate}
+            <if test="dto.sampleName != null and dto.sampleName != ''">
+                AND IFNULL(ins.sample,'') LIKE CONCAT('%',#{dto.sampleName},'%')
+            </if>
 
-        LEFT JOIN (
-        SELECT
-        ins_order_id,
-        MAX(sample) AS sample,
-        MAX(model) AS model
-        FROM ins_sample
-        GROUP BY ins_order_id
-        ) ins ON ins.ins_order_id = io1.id
+            <if test="dto.modelName != null and dto.modelName != ''">
+                AND IFNULL(ins.model,'') LIKE CONCAT('%',#{dto.modelName},'%')
+            </if>
 
-        WHERE
-        iiq.is_finish = 1
-        AND iiq.inspect_status IN (1,2,4)
-
-        <if test="dto.materialProp != null and dto.materialProp != ''">
-            AND IFNULL(iiq.material_prop,'') LIKE CONCAT('%',#{dto.materialProp},'%')
-        </if>
-
-        <if test="dto.sampleName != null and dto.sampleName != ''">
-            AND IFNULL(ins.sample,'') LIKE CONCAT('%',#{dto.sampleName},'%')
-        </if>
-
-        <if test="dto.modelName != null and dto.modelName != ''">
-            AND IFNULL(ins.model,'') LIKE CONCAT('%',#{dto.modelName},'%')
-        </if>
-
-        <if test="dto.supplierName != null and dto.supplierName != ''">
-            AND IFNULL(iiq.supplier_name,'') LIKE CONCAT('%',#{dto.supplierName},'%')
-        </if>
-        <if test="dto.contract != null and dto.contract != ''">
-            AND IFNULL(iiq.contract,'') = #{dto.contract}
-        </if>
-        GROUP BY
-        iiq.supplier_name
-
-        ORDER BY
-        passRate DESC;
+            <if test="dto.supplierName != null and dto.supplierName != ''">
+                AND IFNULL(iiq.supplier_name,'') LIKE CONCAT('%',#{dto.supplierName},'%')
+            </if>
+            <if test="dto.contract != null and dto.contract != ''">
+                AND iiq.contract = #{dto.contract}
+            </if>
+        )temp
+        GROUP BY supplier_name
+        ORDER BY passRate DESC;
 
     </select>
 
@@ -398,13 +406,17 @@
     <!-- 鏌ヨ鏈湀涓庝笂鏈堝悎鏍肩巼瀵规瘮 -->
     <select id="getRawUpMonth" resultType="java.util.Map">
         select DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 MONTH), '%Y-%m') as                           month,
-               (select ROUND((COUNT(*) - SUM(CASE WHEN inspect_status in (2, 4) THEN 1 ELSE 0 END)) / COUNT(*) *
-                             100,
-                             2) passRate
+               (select ROUND(
+                            SUM(CASE WHEN counted_iuh.has_unqualified IS NULL THEN 1 ELSE 0 END) / COUNT(*) *
+                            100,
+                            2) passRate
                 from ifs_inventory_quantity iiq
                          LEFT JOIN ins_order io1 on io1.ifs_inventory_id = iiq.id
                     and io1.order_type = '杩涘巶妫�楠�'
                     and io1.state != -1
+                LEFT JOIN (
+                    <include refid="countableUnqualifiedBatch"/>
+                ) counted_iuh ON counted_iuh.inventory_quantity_id = iiq.id
                 where iiq.is_finish = 1
                   and iiq.inspect_status not in (0, 3)
                   and (io1.send_time between DATE_FORMAT(DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-01'), INTERVAL 1 MONTH),
@@ -412,13 +424,17 @@
                     and DATE_FORMAT(LAST_DAY(DATE_SUB(NOW(), INTERVAL 1 MONTH)), '%Y-%m-%d 23:59:59'))) passRate
         UNION ALL
         select DATE_FORMAT(CURRENT_DATE, '%Y-%m') as                            month,
-               (select ROUND((COUNT(*) - SUM(CASE WHEN inspect_status in (2, 4) THEN 1 ELSE 0 END)) / COUNT(*) *
-                             100,
-                             2) passRate
+               (select ROUND(
+                            SUM(CASE WHEN counted_iuh.has_unqualified IS NULL THEN 1 ELSE 0 END) / COUNT(*) *
+                            100,
+                            2) passRate
                 from ifs_inventory_quantity iiq
                          LEFT JOIN ins_order io1 on io1.ifs_inventory_id = iiq.id
                     and io1.order_type = '杩涘巶妫�楠�'
                     and io1.state != -1
+                LEFT JOIN (
+                    <include refid="countableUnqualifiedBatch"/>
+                ) counted_iuh ON counted_iuh.inventory_quantity_id = iiq.id
                 where iiq.is_finish = 1
                   and iiq.inspect_status not in (0, 3)
                   and (io1.send_time between

--
Gitblit v1.9.3