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
<?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.WorkStatisticsMapper">
 
    <!-- 按人员统计 -->
    <select id="getByUser" resultType="com.ruoyi.report.vo.WorkStatisticsVo">
        SELECT
            u.id AS userId,
            u.name AS userName,
            d.dept_name AS deptName,
            COUNT(DISTINCT s.id) AS sampleCount,
            COUNT(p.id) AS itemCount,
            SUM(CASE WHEN o.ins_time IS NOT NULL AND o.ins_time &lt;= o.appointed THEN 1 ELSE 0 END) AS timelyCount,
            SUM(CASE WHEN o.ins_time IS NOT NULL AND o.ins_time > o.appointed THEN 1 ELSE 0 END) AS overdueCount
        FROM ins_product p
        LEFT JOIN ins_sample s ON p.ins_sample_id = s.id
        LEFT JOIN ins_order o ON s.ins_order_id = o.id
        LEFT JOIN ins_product_user pu ON p.id = pu.ins_product_id
        LEFT JOIN user u ON pu.create_user = u.id
        LEFT JOIN sys_dept d ON u.dept_id = d.dept_id
        WHERE p.ins_result IS NOT NULL
        <if test="dto.startTime != null and dto.startTime != ''">
            AND o.ins_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND o.ins_time &lt;= #{dto.endTime}
        </if>
        <if test="dto.userId != null">
            AND pu.create_user = #{dto.userId}
        </if>
        <if test="dto.deptId != null">
            AND u.dept_id = #{dto.deptId}
        </if>
        GROUP BY u.id
        ORDER BY sampleCount DESC
    </select>
 
    <!-- 及时率统计 -->
    <select id="getTimelyRate" resultType="java.util.Map">
        SELECT
            u.name AS userName,
            COUNT(*) AS totalCount,
            SUM(CASE WHEN o.ins_time IS NOT NULL AND o.ins_time &lt;= o.appointed THEN 1 ELSE 0 END) AS timelyCount,
            ROUND(SUM(CASE WHEN o.ins_time IS NOT NULL AND o.ins_time &lt;= o.appointed THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 2) AS timelyRate
        FROM ins_order o
        LEFT JOIN ins_sample s ON o.id = s.ins_order_id
        LEFT JOIN ins_product p ON s.id = p.ins_sample_id
        LEFT JOIN user u ON o.prepare_user_id = u.id
        WHERE o.ins_state = 5
        <if test="dto.startTime != null and dto.startTime != ''">
            AND o.ins_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND o.ins_time &lt;= #{dto.endTime}
        </if>
        <if test="dto.deptId != null">
            AND u.dept_id = #{dto.deptId}
        </if>
        GROUP BY u.id
        ORDER BY timelyRate DESC
    </select>
 
    <!-- 工作趋势图 -->
    <select id="getTrend" resultType="java.util.Map">
        SELECT
            DATE_FORMAT(o.ins_time, '%Y-%m-%d') AS date,
            COUNT(DISTINCT s.id) AS sampleCount,
            COUNT(p.id) AS itemCount
        FROM ins_product p
        LEFT JOIN ins_sample s ON p.ins_sample_id = s.id
        LEFT JOIN ins_order o ON s.ins_order_id = o.id
        LEFT JOIN ins_product_user pu ON p.id = pu.ins_product_id
        WHERE p.ins_result IS NOT NULL
        <if test="dto.startTime != null and dto.startTime != ''">
            AND o.ins_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND o.ins_time &lt;= #{dto.endTime}
        </if>
        <if test="dto.userId != null">
            AND pu.create_user = #{dto.userId}
        </if>
        GROUP BY DATE_FORMAT(o.ins_time, '%Y-%m-%d')
        ORDER BY date ASC
    </select>
 
</mapper>