zouyu
6 天以前 c3211b476e96c8e11eaaa04735620cc3344d8996
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
<?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.safety.mapper.SafetyInspectionRecordMapper">
 
    <select id="selectTodayStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectionTodayStatistics">
        SELECT
            COUNT(1) AS totalCount,
            IFNULL(SUM(CASE WHEN status &lt;&gt; 3 THEN 1 ELSE 0 END), 0) AS completedCount,
            IFNULL(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) AS abnormalCount,
            IFNULL(SUM(CASE WHEN status = 2 OR is_missed = 1 THEN 1 ELSE 0 END), 0) AS missedCount,
            IFNULL(SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END), 0) AS unexecutedCount,
            CASE
                WHEN COUNT(1) = 0 THEN 0
                ELSE ROUND(IFNULL(SUM(CASE WHEN status &lt;&gt; 3 THEN 1 ELSE 0 END), 0) / COUNT(1) * 100, 2)
            END AS completionRate,
            COUNT(DISTINCT inspector_id) AS inspectorCount
        FROM safety_inspection_record
        WHERE del_flag = 0
          AND DATE(inspection_time) = #{statDate}
    </select>
 
    <select id="selectTrendStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectionTrendStat">
        SELECT
            DATE(inspection_time) AS statDate,
            COUNT(1) AS totalCount,
            IFNULL(SUM(CASE WHEN status &lt;&gt; 3 THEN 1 ELSE 0 END), 0) AS completedCount,
            IFNULL(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) AS abnormalCount,
            IFNULL(SUM(CASE WHEN status = 2 OR is_missed = 1 THEN 1 ELSE 0 END), 0) AS missedCount,
            IFNULL(SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END), 0) AS unexecutedCount
        FROM safety_inspection_record
        WHERE del_flag = 0
          AND DATE(inspection_time) BETWEEN #{startDate} AND #{endDate}
        GROUP BY DATE(inspection_time)
        ORDER BY statDate ASC
    </select>
 
    <select id="selectTypeStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectionTypeStat">
        SELECT
            IFNULL(type, 'unknown') AS type,
            COUNT(1) AS count
        FROM safety_inspection_record
        WHERE del_flag = 0
          AND DATE(inspection_time) BETWEEN #{startDate} AND #{endDate}
        GROUP BY IFNULL(type, 'unknown')
        ORDER BY count DESC
    </select>
 
    <select id="selectInspectorStatistics" resultType="com.ruoyi.safety.dto.SafetyInspectorStat">
        SELECT
            inspector_id AS inspectorId,
            inspector AS inspector,
            COUNT(1) AS totalCount,
            IFNULL(SUM(CASE WHEN status &lt;&gt; 3 THEN 1 ELSE 0 END), 0) AS completedCount,
            IFNULL(SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END), 0) AS abnormalCount,
            IFNULL(SUM(CASE WHEN status = 2 OR is_missed = 1 THEN 1 ELSE 0 END), 0) AS missedCount,
            IFNULL(SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END), 0) AS unexecutedCount,
            CASE
                WHEN COUNT(1) = 0 THEN 0
                ELSE ROUND(IFNULL(SUM(CASE WHEN status &lt;&gt; 3 THEN 1 ELSE 0 END), 0) / COUNT(1) * 100, 2)
            END AS completionRate
        FROM safety_inspection_record
        WHERE del_flag = 0
          AND DATE(inspection_time) BETWEEN #{startDate} AND #{endDate}
        GROUP BY inspector_id, inspector
        ORDER BY totalCount DESC
    </select>
</mapper>