huang
2025-11-20 366ba040d2447bacd3455299425e3166f1f992bb
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
package com.mes.device.mapper;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mes.device.entity.DeviceConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
/**
 * 设备配置Mapper接口
 */
@Mapper
public interface DeviceConfigMapper extends BaseMapper<DeviceConfig> {
 
    /**
     * 根据项目ID和设备类型查询设备配置列表
     * @param projectId 项目ID
     * @param deviceType 设备类型
     * @param status 设备状态
     * @return 设备配置列表
     */
    @Select({
        "<script>",
        "SELECT * FROM device_config",
        "WHERE is_deleted = 0",
        "<when test='projectId != null'>",
        "AND project_id = #{projectId}",
        "</when>",
        "<when test='deviceType != null'>",
        "AND device_type = #{deviceType}",
        "</when>",
        "<when test='status != null'>",
        "AND status = #{status}",
        "</when>",
        "ORDER BY id ASC",
        "</script>"
    })
    java.util.List<DeviceConfig> selectDeviceConfigList(
        @Param("projectId") Long projectId,
        @Param("deviceType") String deviceType,
        @Param("status") String status
    );
 
    /**
     * 统计在线设备数量
     * @param projectId 项目ID
     * @return 在线设备数量
     */
    @Select({
        "<script>",
        "SELECT COUNT(*) FROM device_config",
        "WHERE is_deleted = 0",
        "AND status = '在线'",
        "<when test='projectId != null'>",
        "AND project_id = #{projectId}",
        "</when>",
        "</script>"
    })
    int countOnlineDevices(@Param("projectId") Long projectId);
 
    /**
     * 统计设备状态分布
     * @param projectId 项目ID
     * @return 设备状态分布
     */
    @Select({
        "<script>",
        "SELECT",
        "    COUNT(CASE WHEN status = '离线' THEN 1 END) as offline_count,",
        "    COUNT(CASE WHEN status = '在线' THEN 1 END) as online_count,",
        "    COUNT(CASE WHEN status = '维护中' THEN 1 END) as maintenance_count,",
        "    COUNT(CASE WHEN status = '故障' THEN 1 END) as fault_count",
        "FROM device_config",
        "WHERE is_deleted = 0",
        "<when test='projectId != null'>",
        "AND project_id = #{projectId}",
        "</when>",
        "</script>"
    })
    java.util.Map<String, Object> getDeviceStatusDistribution(@Param("projectId") Long projectId);
}