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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.mes.device.mapper;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mes.device.entity.DeviceGroupConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
/**
 * 设备组配置Mapper接口
 */
@Mapper
public interface DeviceGroupConfigMapper extends BaseMapper<DeviceGroupConfig> {
 
    /**
     * 根据项目ID和设备组类型查询设备组配置列表
     * @param projectId 项目ID
     * @param groupType 设备组类型
     * @param status 设备组状态
     * @return 设备组配置列表
     */
    @Select({
        "<script>",
        "SELECT * FROM device_group_config",
        "WHERE is_deleted = 0",
        "<when test='projectId != null'>",
        "AND project_id = #{projectId}",
        "</when>",
        "<when test='groupType != null'>",
        "AND group_type = #{groupType}",
        "</when>",
        "<when test='status != null'>",
        "AND status = #{status}",
        "</when>",
        "ORDER BY id ASC",
        "</script>"
    })
    java.util.List<DeviceGroupConfig> selectDeviceGroupConfigList(
        @Param("projectId") Long projectId,
        @Param("groupType") Integer groupType,
        @Param("status") Integer status
    );
 
    /**
     * 统计启用设备组数量
     * @param projectId 项目ID
     * @return 启用设备组数量
     */
    @Select({
        "<script>",
        "SELECT COUNT(*) FROM device_group_config",
        "WHERE is_deleted = 0",
        "AND status = 1",
        "<when test='projectId != null'>",
        "AND project_id = #{projectId}",
        "</when>",
        "</script>"
    })
    int countEnabledDeviceGroups(@Param("projectId") Long projectId);
 
    /**
     * 统计设备组状态分布
     * @param projectId 项目ID
     * @return 设备组状态分布
     */
    @Select({
        "<script>",
        "SELECT",
        "    COUNT(CASE WHEN status = 0 THEN 1 END) as disabled_count,",
        "    COUNT(CASE WHEN status = 1 THEN 1 END) as enabled_count,",
        "    COUNT(CASE WHEN status = 2 THEN 1 END) as maintenance_count",
        "FROM device_group_config",
        "WHERE is_deleted = 0",
        "<when test='projectId != null'>",
        "AND project_id = #{projectId}",
        "</when>",
        "</script>"
    })
    java.util.Map<String, Object> getDeviceGroupStatusDistribution(@Param("projectId") Long projectId);
 
    /**
     * 查询设备组下的设备数量统计
     * @param groupId 设备组ID
     * @return 设备数量统计
     */
    @Select({
        "SELECT",
        "    COUNT(*) as total_devices,",
        "    COUNT(CASE WHEN dgr.status = 1 THEN 1 END) as normal_devices,",
        "    COUNT(CASE WHEN dgr.status = 2 THEN 1 END) as fault_devices,",
        "    COUNT(CASE WHEN dgr.status = 3 THEN 1 END) as maintenance_devices",
        "FROM device_group_relation dgr",
        "INNER JOIN device_config dc ON dgr.device_id = dc.id",
        "WHERE dgr.is_deleted = 0",
        "AND dc.is_deleted = 0",
        "AND dgr.group_id = #{groupId}"
    })
    java.util.Map<String, Object> getDeviceGroupDeviceStatistics(@Param("groupId") Long groupId);
}