| | |
| | | #{id} |
| | | </foreach> |
| | | </delete> |
| | | |
| | | <select id="getInspectStatistics" resultType="com.ruoyi.quality.dto.QualityInspectStatDto"> |
| | | SELECT 0 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) FROM procurement_record_storage WHERE type = 1), 0) + |
| | | COALESCE((SELECT SUM(quantity) FROM quality_unqualified WHERE inspect_type = 0), 0) AS totalCount, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 1 |
| | | AND quality_inspect_id != 0 |
| | | AND quality_inspect_id IS NOT NULL), 0) + |
| | | COALESCE((SELECT SUM(quantity) FROM quality_unqualified WHERE inspect_type = 0), 0) AS completedCount |
| | | UNION ALL |
| | | SELECT 1 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id = 0), 0) AS totalCount, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id = 0 |
| | | AND quality_inspect_id != 0 |
| | | AND quality_inspect_id IS NOT NULL), 0) AS completedCount |
| | | UNION ALL |
| | | SELECT 2 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id != 0), 0) AS totalCount, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id != 0 |
| | | AND quality_inspect_id != 0 |
| | | AND quality_inspect_id IS NOT NULL), 0) AS completedCount |
| | | </select> |
| | | |
| | | <select id="getPassRateStatistics" resultType="com.ruoyi.quality.dto.QualityPassRateDto"> |
| | | SELECT t.inspectType, |
| | | COALESCE(prs.totalCount, 0) AS totalCount, |
| | | COALESCE(qi.completedCount, 0) AS completedCount, |
| | | COALESCE(qi.qualifiedCount, 0) AS qualifiedCount, |
| | | COALESCE(qi.unqualifiedCount, 0) AS unqualifiedCount, |
| | | IF(COALESCE(prs.totalCount, 0) = 0, 0, |
| | | ROUND(COALESCE(qi.completedCount, 0) / prs.totalCount * 100, 2)) AS completionRate, |
| | | IF(COALESCE(qi.completedCount, 0) = 0, 0, |
| | | ROUND(COALESCE(qi.qualifiedCount, 0) / qi.completedCount * 100, 2)) AS passRate |
| | | FROM (SELECT 0 AS inspectType |
| | | UNION ALL |
| | | SELECT 1 |
| | | UNION ALL |
| | | SELECT 2) t |
| | | LEFT JOIN (SELECT inspect_type, |
| | | SUM(quantity) AS completedCount, |
| | | SUM(IF(check_result = '合格', quantity, 0)) AS qualifiedCount, |
| | | SUM(IF(check_result = '不合格', quantity, 0)) AS unqualifiedCount |
| | | FROM quality_inspect |
| | | WHERE inspect_state = 1 |
| | | GROUP BY inspect_type) qi |
| | | ON t.inspectType = qi.inspect_type |
| | | LEFT JOIN (SELECT 0 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) FROM procurement_record_storage WHERE type = 1), |
| | | 0) + |
| | | COALESCE((SELECT SUM(quantity) FROM quality_unqualified WHERE inspect_type = 0), |
| | | 0) AS totalCount |
| | | UNION ALL |
| | | SELECT 1 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id = 0), 0) AS totalCount |
| | | UNION ALL |
| | | SELECT 2 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id != 0), 0) AS totalCount) prs |
| | | ON t.inspectType = prs.inspectType |
| | | ORDER BY t.inspectType; |
| | | </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 < 12), |
| | | types AS (SELECT 0 AS inspectType |
| | | UNION ALL |
| | | SELECT 1 |
| | | UNION ALL |
| | | SELECT 2), |
| | | base AS (SELECT m.month_num, t.inspectType |
| | | FROM months m, |
| | | types t), |
| | | qi_data AS (SELECT MONTH(check_time) AS month_num, |
| | | inspect_type, |
| | | SUM(quantity) AS completedCount, |
| | | SUM(CASE WHEN check_result = '合格' THEN quantity ELSE 0 END) AS qualifiedCount, |
| | | SUM(CASE WHEN check_result = '不合格' THEN quantity ELSE 0 END) AS unqualifiedCount |
| | | FROM quality_inspect |
| | | WHERE YEAR(check_time) = #{year} |
| | | AND inspect_state = 1 |
| | | GROUP BY MONTH(check_time), inspect_type), |
| | | prs_data AS (SELECT month_num, |
| | | inspectType, |
| | | SUM(totalCount) AS totalCount |
| | | FROM (SELECT MONTH(create_time) AS month_num, |
| | | 0 AS inspectType, |
| | | inbound_num AS totalCount |
| | | FROM procurement_record_storage |
| | | WHERE type = 1 |
| | | AND YEAR(create_time) = #{year} |
| | | UNION ALL |
| | | SELECT MONTH(check_time) AS month_num, |
| | | 0 AS inspectType, |
| | | quantity AS totalCount |
| | | FROM quality_unqualified |
| | | WHERE inspect_type = 0 |
| | | AND YEAR(check_time) = #{year} |
| | | UNION ALL |
| | | SELECT MONTH(create_time) AS month_num, |
| | | CASE |
| | | WHEN sales_ledger_product_id = 0 THEN 1 |
| | | ELSE 2 |
| | | END AS inspectType, |
| | | inbound_num AS totalCount |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND YEAR(create_time) = #{year}) sub |
| | | GROUP BY month_num, inspectType) |
| | | SELECT CASE b.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, |
| | | b.inspectType, |
| | | COALESCE(p.totalCount, 0) AS totalCount, |
| | | COALESCE(q.completedCount, 0) AS completedCount, |
| | | COALESCE(q.qualifiedCount, 0) AS qualifiedCount, |
| | | COALESCE(q.unqualifiedCount, 0) AS unqualifiedCount, |
| | | CASE |
| | | WHEN COALESCE(p.totalCount, 0) = 0 THEN 0 |
| | | ELSE ROUND(COALESCE(q.completedCount, 0) / p.totalCount * 100, 2) |
| | | END AS completionRate, |
| | | CASE |
| | | WHEN COALESCE(q.completedCount, 0) = 0 THEN 0 |
| | | ELSE ROUND(COALESCE(q.qualifiedCount, 0) / q.completedCount * 100, 2) |
| | | END AS passRate |
| | | FROM base b |
| | | LEFT JOIN qi_data q ON b.month_num = q.month_num AND b.inspectType = q.inspect_type |
| | | LEFT JOIN prs_data p ON b.month_num = p.month_num AND b.inspectType = p.inspectType |
| | | ORDER BY b.month_num, b.inspectType |
| | | </select> |
| | | |
| | | <select id="getYearlyPassRateStatistics" resultType="com.ruoyi.quality.dto.QualityPassRateDto"> |
| | | SELECT t.inspectType, |
| | | COALESCE(prs.totalCount, 0) AS totalCount, |
| | | COALESCE(qi.completedCount, 0) AS completedCount, |
| | | COALESCE(qi.qualifiedCount, 0) AS qualifiedCount, |
| | | COALESCE(qi.unqualifiedCount, 0) AS unqualifiedCount, |
| | | CASE |
| | | WHEN COALESCE(prs.totalCount, 0) = 0 THEN 0 |
| | | ELSE ROUND(COALESCE(qi.completedCount, 0) / prs.totalCount * 100, 2) |
| | | END AS completionRate, |
| | | CASE |
| | | WHEN COALESCE(qi.completedCount, 0) = 0 THEN 0 |
| | | ELSE ROUND(COALESCE(qi.qualifiedCount, 0) / qi.completedCount * 100, 2) |
| | | END AS passRate |
| | | FROM (SELECT 0 AS inspectType |
| | | UNION ALL |
| | | SELECT 1 |
| | | UNION ALL |
| | | SELECT 2) t |
| | | LEFT JOIN (SELECT inspect_type, |
| | | SUM(quantity) AS completedCount, |
| | | SUM(CASE WHEN check_result = '合格' THEN quantity ELSE 0 END) AS qualifiedCount, |
| | | SUM(CASE WHEN check_result = '不合格' THEN quantity ELSE 0 END) AS unqualifiedCount |
| | | FROM quality_inspect |
| | | WHERE YEAR(check_time) = #{year} |
| | | AND inspect_state = 1 |
| | | GROUP BY inspect_type) qi |
| | | ON t.inspectType = qi.inspect_type |
| | | LEFT JOIN (SELECT 0 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 1 |
| | | AND YEAR(create_time) = #{year}), 0) + |
| | | COALESCE((SELECT SUM(quantity) |
| | | FROM quality_unqualified |
| | | WHERE inspect_type = 0 |
| | | AND YEAR(check_time) = #{year}), 0) AS totalCount |
| | | UNION ALL |
| | | SELECT 1 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id = 0 |
| | | AND YEAR(create_time) = #{year}), 0) AS totalCount |
| | | UNION ALL |
| | | SELECT 2 AS inspectType, |
| | | COALESCE((SELECT SUM(inbound_num) |
| | | FROM procurement_record_storage |
| | | WHERE type = 2 |
| | | AND sales_ledger_product_id != 0 |
| | | AND YEAR(create_time) = #{year}), 0) AS totalCount) prs |
| | | ON t.inspectType = prs.inspectType |
| | | ORDER BY t.inspectType |
| | | </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 < 12), |
| | | qi_data AS (SELECT MONTH(check_time) AS month_num, |
| | | SUM(CASE WHEN inspect_type = 0 THEN quantity ELSE 0 END) AS rawMaterialCount, |
| | | SUM(CASE WHEN inspect_type = 1 THEN quantity ELSE 0 END) AS processCount, |
| | | SUM(CASE WHEN inspect_type = 2 THEN quantity ELSE 0 END) AS outgoingCount |
| | | FROM quality_inspect |
| | | WHERE YEAR(check_time) = #{year} |
| | | AND inspect_state = 1 |
| | | GROUP BY MONTH(check_time)) |
| | | 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(d.rawMaterialCount, 0) AS rawMaterialCount, |
| | | COALESCE(d.processCount, 0) AS processCount, |
| | | COALESCE(d.outgoingCount, 0) AS outgoingCount |
| | | FROM months m |
| | | LEFT JOIN qi_data d ON m.month_num = d.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, |
| | | SUM(COALESCE(qi.quantity, 0)) AS count |
| | | FROM quality_inspect qi |
| | | JOIN quality_inspect_param qip ON qip.inspect_id = qi.id |
| | | WHERE qi.inspect_type = #{inspectType} |
| | | 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 <= 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> |