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);
|
}
|