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