huminmin
2026-06-05 24019a8c1d8e78656e85b29ee7be223e0dd253a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?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.report.mapper.SampleProgressMapper">
 
    <!-- 分页查询样品进度 -->
    <select id="pageSampleProgress" resultType="com.ruoyi.report.vo.SampleProgressVo">
        SELECT
            s.id AS sampleId,
            o.entrust_code AS entrustCode,
            s.sample_code AS sampleCode,
            s.sample AS sampleName,
            r.code AS reportCode,
            o.ins_state AS insState,
            COUNT(p.id) AS totalItems,
            SUM(CASE WHEN p.ins_result IS NOT NULL THEN 1 ELSE 0 END) AS finishedItems,
            o.appointed AS planFinishTime,
            o.ins_time AS actualFinishTime,
            u.name AS chargeUser,
            o.custom AS custom,
            s.create_time AS createTime
        FROM ins_sample s
        LEFT JOIN ins_order o ON s.ins_order_id = o.id
        LEFT JOIN ins_product p ON s.id = p.ins_sample_id
        LEFT JOIN ins_report r ON o.id = r.ins_order_id
        LEFT JOIN user u ON o.prepare_user_id = u.id
        WHERE 1=1
        <if test="dto.entrustCode != null and dto.entrustCode != ''">
            AND o.entrust_code LIKE CONCAT('%', #{dto.entrustCode}, '%')
        </if>
        <if test="dto.sampleCode != null and dto.sampleCode != ''">
            AND s.sample_code LIKE CONCAT('%', #{dto.sampleCode}, '%')
        </if>
        <if test="dto.sampleName != null and dto.sampleName != ''">
            AND s.sample LIKE CONCAT('%', #{dto.sampleName}, '%')
        </if>
        <if test="dto.reportCode != null and dto.reportCode != ''">
            AND r.code LIKE CONCAT('%', #{dto.reportCode}, '%')
        </if>
        <if test="dto.insState != null">
            AND o.ins_state = #{dto.insState}
        </if>
        <if test="dto.custom != null and dto.custom != ''">
            AND o.custom LIKE CONCAT('%', #{dto.custom}, '%')
        </if>
        <if test="dto.startTime != null and dto.startTime != ''">
            AND s.create_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND s.create_time &lt;= #{dto.endTime}
        </if>
        GROUP BY s.id
        ORDER BY s.create_time DESC
    </select>
 
    <!-- 获取统计数据 -->
    <select id="getStatistics" resultType="java.util.Map">
        SELECT
            SUM(CASE WHEN o.ins_state = 0 THEN 1 ELSE 0 END) AS waitInspection,
            SUM(CASE WHEN o.ins_state = 1 THEN 1 ELSE 0 END) AS inspecting,
            SUM(CASE WHEN o.ins_state = 3 THEN 1 ELSE 0 END) AS waitAudit,
            SUM(CASE WHEN o.ins_state = 5 THEN 1 ELSE 0 END) AS finished
        FROM ins_sample s
        LEFT JOIN ins_order o ON s.ins_order_id = o.id
        WHERE 1=1
        <if test="dto.custom != null and dto.custom != ''">
            AND o.custom LIKE CONCAT('%', #{dto.custom}, '%')
        </if>
        <if test="dto.startTime != null and dto.startTime != ''">
            AND s.create_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND s.create_time &lt;= #{dto.endTime}
        </if>
    </select>
 
    <!-- 获取图表数据 -->
    <select id="getChartData" resultType="java.util.Map">
        SELECT
            DATE_FORMAT(s.create_time, '%Y-%m-%d') AS date,
            COUNT(*) AS totalCount,
            SUM(CASE WHEN o.ins_state = 5 THEN 1 ELSE 0 END) AS finishedCount
        FROM ins_sample s
        LEFT JOIN ins_order o ON s.ins_order_id = o.id
        WHERE 1=1
        <if test="dto.custom != null and dto.custom != ''">
            AND o.custom LIKE CONCAT('%', #{dto.custom}, '%')
        </if>
        <if test="dto.startTime != null and dto.startTime != ''">
            AND s.create_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND s.create_time &lt;= #{dto.endTime}
        </if>
        GROUP BY DATE_FORMAT(s.create_time, '%Y-%m-%d')
        ORDER BY date ASC
    </select>
 
</mapper>