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
<?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.ReportDeviceRecordMapper">
 
    <!-- 分页查询设备使用记录 -->
    <select id="pageDeviceRecord" resultType="com.ruoyi.report.vo.DeviceRecordVo">
        SELECT
            r.id AS id,
            d.id AS deviceId,
            d.management_number AS deviceCode,
            d.device_name AS deviceName,
            r.sample_code AS sampleCode,
            r.use_person AS useUser,
            r.use_start_date AS startTime,
            r.use_end_date AS endTime,
            r.temperature,
            r.humidity,
            r.use_before AS useBefore,
            r.use_after AS useAfter,
            r.abnormal,
            r.remark
        FROM device_record r
        LEFT JOIN device d ON r.device_id = d.id
        WHERE 1=1
        <if test="dto.deviceCode != null and dto.deviceCode != ''">
            AND d.management_number LIKE CONCAT('%', #{dto.deviceCode}, '%')
        </if>
        <if test="dto.deviceName != null and dto.deviceName != ''">
            AND d.device_name LIKE CONCAT('%', #{dto.deviceName}, '%')
        </if>
        <if test="dto.useUser != null and dto.useUser != ''">
            AND r.use_person LIKE CONCAT('%', #{dto.useUser}, '%')
        </if>
        <if test="dto.sampleCode != null and dto.sampleCode != ''">
            AND r.sample_code LIKE CONCAT('%', #{dto.sampleCode}, '%')
        </if>
        <if test="dto.startTime != null and dto.startTime != ''">
            AND r.use_start_date >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND r.use_end_date &lt;= #{dto.endTime}
        </if>
        ORDER BY r.use_start_date DESC
    </select>
 
    <!-- 设备使用统计 -->
    <select id="getStatistics" resultType="java.util.Map">
        SELECT
            d.device_name AS deviceName,
            d.management_number AS deviceCode,
            COUNT(*) AS useCount,
            COUNT(DISTINCT r.sample_code) AS sampleCount,
            COUNT(DISTINCT r.use_person_id) AS userCount
        FROM device_record r
        LEFT JOIN device d ON r.device_id = d.id
        WHERE 1=1
        <if test="dto.deviceCode != null and dto.deviceCode != ''">
            AND d.management_number LIKE CONCAT('%', #{dto.deviceCode}, '%')
        </if>
        <if test="dto.deviceName != null and dto.deviceName != ''">
            AND d.device_name LIKE CONCAT('%', #{dto.deviceName}, '%')
        </if>
        <if test="dto.startTime != null and dto.startTime != ''">
            AND r.use_start_date >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null and dto.endTime != ''">
            AND r.use_end_date &lt;= #{dto.endTime}
        </if>
        GROUP BY d.id
        ORDER BY useCount DESC
    </select>
 
</mapper>