diff --git a/ALOps_sys_backend/alops-admin/src/main/java/com/alops/web/controller/equManagement/EquBaseController.java b/ALOps_sys_backend/alops-admin/src/main/java/com/alops/web/controller/equManagement/EquBaseController.java index e17e40fd..c6dca97c 100644 --- a/ALOps_sys_backend/alops-admin/src/main/java/com/alops/web/controller/equManagement/EquBaseController.java +++ b/ALOps_sys_backend/alops-admin/src/main/java/com/alops/web/controller/equManagement/EquBaseController.java @@ -16,6 +16,7 @@ import com.alops.common.enums.BusinessType; import com.alops.common.utils.poi.ExcelUtil; import com.alops.system.domain.EquBase; import com.alops.system.domain.dto.EquBaseQueryDto; +import com.alops.system.domain.dto.EquMonitorHomeDto; import com.alops.system.domain.dto.MonitorListDto; import com.alops.system.domain.dto.MonitorStatisticDto; import com.alops.system.domain.vo.EquMonitorVO; @@ -60,16 +61,28 @@ public class EquBaseController extends BaseController } /**查询设备监测信息列表(查询多台显示界面的单独信息)**/ + /** + * 查询多台设备的最新监测信息 + **/ + @PreAuthorize("@ss.hasPermi('device:files:query')") + @GetMapping("/monitorpage") + @ApiOperation("分页查询多台设备的最新监测信息") + public TableDataInfo getMonitorList() { + startPage(); // 无参调用,自动获取 pageNum/pageSize + List list = equBaseService.selectEquMonitorListPaged(); + return getDataTable(list); // 自动封装分页结果 + } + + /** + * 首页展示:查询每台设备的最新监测信息 + */ @PreAuthorize("@ss.hasPermi('device:files:query')") @GetMapping("/monitorById") - @ApiOperation("根据设备ID查询设备最新监测信息(查询多台显示界面的单台信息)") - public AjaxResult getMonitorById(@RequestParam String id) { - MonitorListDto monitor = equBaseService.selectEquMonitorListById(id); - if (monitor != null) { - return AjaxResult.success("查询成功", monitor); - } else { - return AjaxResult.error("未找到设备或监测信息"); - } + @ApiOperation("首页展示:查询每台设备的最新监测信息") + public TableDataInfo getLatestEquMonitorList() { + startPage(); // 启用分页(如果首页不分页可删除) + List list = equBaseService.selectLatestEquMonitorList(); + return getDataTable(list); } diff --git a/ALOps_sys_backend/alops-admin/src/main/resources/application-druid.yml b/ALOps_sys_backend/alops-admin/src/main/resources/application-druid.yml index 5b4337af..f719c265 100644 --- a/ALOps_sys_backend/alops-admin/src/main/resources/application-druid.yml +++ b/ALOps_sys_backend/alops-admin/src/main/resources/application-druid.yml @@ -7,7 +7,7 @@ spring: # 主库数据源 master: url: jdbc:mysql://localhost:3306/aiops_sys?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: root + username: aiops_sys password: 1234 # 从库数据源 slave: diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/AlertStatisticDto.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/AlertStatisticDto.java index 3fe6246c..c53a4876 100644 --- a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/AlertStatisticDto.java +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/AlertStatisticDto.java @@ -1,6 +1,9 @@ package com.alops.system.domain.dto; import lombok.Data; + +import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -8,15 +11,23 @@ import java.util.Map; */ @Data public class AlertStatisticDto { - // 按设备类型统计 - private Map typeCount; - - // 按等级统计 - private Map levelCount; - // 本年度预警次数 + private List typeCount = new ArrayList<>(); + private List levelCount = new ArrayList<>(); private Integer yearCount; - - // 本月预警次数 private Integer monthCount; + + public List getTypeCount() { return typeCount; } + public void setTypeCount(List typeCount) { this.typeCount = typeCount; } + + public List getLevelCount() { return levelCount; } + public void setLevelCount(List levelCount) { this.levelCount = levelCount; } + + public Integer getYearCount() { return yearCount; } + public void setYearCount(Integer yearCount) { this.yearCount = yearCount; } + + public Integer getMonthCount() { return monthCount; } + public void setMonthCount(Integer monthCount) { this.monthCount = monthCount; } + } + diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/EquMonitorHomeDto.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/EquMonitorHomeDto.java new file mode 100644 index 00000000..f7d51901 --- /dev/null +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/EquMonitorHomeDto.java @@ -0,0 +1,21 @@ +package com.alops.system.domain.dto; + +import lombok.Data; + +import java.util.Date; + +/** + * 首页展示:设备监测简要信息 + */ +@Data +public class EquMonitorHomeDto { + private String id; + private String name; // 设备名称 + private String location; // 设备位置 + private Float cpuUtilization; // CPU 使用率 + private Float memoryUtilization; // 内存使用率 + private Float temperature; // 温度 + private String health; // 健康度 + private String contWorkPeriod; // 持续运行时长 + private Date gatherTime; // 采集时间 +} diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/LevelCountDto.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/LevelCountDto.java new file mode 100644 index 00000000..ed5e76dd --- /dev/null +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/LevelCountDto.java @@ -0,0 +1,22 @@ +package com.alops.system.domain.dto; + +public class LevelCountDto { + private String level; + private Integer count; + + // 无参构造器 + public LevelCountDto() {} + + // 带参构造器 + public LevelCountDto(String level, Integer count) { + this.level = level; + this.count = count; + } + + // getter & setter + public String getLevel() { return level; } + public void setLevel(String level) { this.level = level; } + + public Integer getCount() { return count; } + public void setCount(Integer count) { this.count = count; } +} diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/TypeCountDto.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/TypeCountDto.java new file mode 100644 index 00000000..9b120e25 --- /dev/null +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/domain/dto/TypeCountDto.java @@ -0,0 +1,17 @@ +package com.alops.system.domain.dto; + +public class TypeCountDto { + private String name; + private Integer count; + + public TypeCountDto() {} + public TypeCountDto(String name, Integer count) { + this.name = name; + this.count = count; + } + // getter/setter + public String getName() { return name; } + public void setName(String name) { this.name = name; } + public Integer getCount() { return count; } + public void setCount(Integer count) { this.count = count; } +} diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/mapper/EquBaseMapper.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/mapper/EquBaseMapper.java index 29d74d3d..028b2c45 100644 --- a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/mapper/EquBaseMapper.java +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/mapper/EquBaseMapper.java @@ -4,19 +4,13 @@ import java.util.List; import java.util.Map; import com.alops.system.domain.EquBase; -import com.alops.system.domain.dto.EquBaseQueryDto; -import com.alops.system.domain.dto.MonitorLastDto; -import com.alops.system.domain.dto.MonitorListDto; -import com.alops.system.domain.dto.MonitorStatisticDto; +import com.alops.system.domain.dto.*; import com.alops.system.domain.vo.imageVo; import com.alops.system.domain.vo.queryEquBaseVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Update; import org.springframework.data.repository.query.Param; -import java.util.List; -import java.util.Map; - /** * 设备基本信息Mapper接口 @@ -63,7 +57,13 @@ public interface EquBaseMapper MonitorLastDto selectEquMonitorById(String id); List> selectEquMonitorByIdToList(EquBaseQueryDto queryDto); - MonitorListDto selectEquMonitorListById(String id); + List selectEquMonitorListPaged(); + + /** + * 查询每台设备的最新监测信息(首页展示用) + */ + List selectLatestEquMonitorList(); + /**分类统计界面信息 -YY**/ List selectEquStatisticByType(); diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/IEquBaseService.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/IEquBaseService.java index cc7a1869..4ee9e582 100644 --- a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/IEquBaseService.java +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/IEquBaseService.java @@ -60,7 +60,12 @@ public interface IEquBaseService */ public List selectEquBaseList(EquBaseQueryDto equBase); - public MonitorListDto selectEquMonitorListById(String id); + public List selectEquMonitorListPaged(); + + /** + * 查询每台设备的最新监测信息(首页展示用) + */ + List selectLatestEquMonitorList(); /**分类统计信息**/ List selectEquStatisticByType(); diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertMessageServiceImpl.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertMessageServiceImpl.java index c2effeae..c6feb4ac 100644 --- a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertMessageServiceImpl.java +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/AlertMessageServiceImpl.java @@ -10,6 +10,8 @@ import java.util.Map; import com.alops.system.domain.AlertMessage; import com.alops.system.domain.dto.AlertDto; import com.alops.system.domain.dto.AlertStatisticDto; +import com.alops.system.domain.dto.LevelCountDto; +import com.alops.system.domain.dto.TypeCountDto; import com.alops.system.domain.vo.homeEquAlertMessage; import com.alops.system.mapper.AlertMessageMapper; import com.alops.system.service.IAlertMessageService; @@ -73,18 +75,18 @@ public class AlertMessageServiceImpl implements IAlertMessageService AlertStatisticDto dto = new AlertStatisticDto(); // 按设备类型统计 - Map typeMap = new HashMap<>(); for (Map row : alertMessageMapper.countByType()) { - typeMap.put((String) row.get("equ_type"), ((Long) row.get("cnt")).intValue()); + String name = (String) row.get("equ_type"); + Integer count = ((Long) row.get("cnt")).intValue(); + dto.getTypeCount().add(new TypeCountDto(name, count)); } - dto.setTypeCount(typeMap); // 按等级统计 - Map levelMap = new HashMap<>(); for (Map row : alertMessageMapper.countByLevel()) { - levelMap.put(((Integer) row.get("level")), ((Long) row.get("cnt")).intValue()); + String level = String.valueOf(row.get("level")); + Integer count = ((Long) row.get("cnt")).intValue(); + dto.getLevelCount().add(new LevelCountDto(level, count)); } - dto.setLevelCount(levelMap); // 年 / 月 LocalDate now = LocalDate.now(); @@ -97,7 +99,8 @@ public class AlertMessageServiceImpl implements IAlertMessageService return dto; } - /** + + /** * 新增故障统计 * * @param alertMessage 故障统计 diff --git a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/EquBaseServiceImpl.java b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/EquBaseServiceImpl.java index 8a046847..1de921ea 100644 --- a/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/EquBaseServiceImpl.java +++ b/ALOps_sys_backend/alops-system/src/main/java/com/alops/system/service/impl/EquBaseServiceImpl.java @@ -131,12 +131,20 @@ public class EquBaseServiceImpl implements IEquBaseService } /** - * 查询多台显示界面的单独信息 + * 查询多台设备的最新监测信息 **/ @Override - public MonitorListDto selectEquMonitorListById(String id) { - return equBaseMapper.selectEquMonitorListById(id); + public List selectEquMonitorListPaged() { + return equBaseMapper.selectEquMonitorListPaged(); } + /** + * 查询多台设备的最新监测信息首页展示 + **/ + @Override + public List selectLatestEquMonitorList() { + return equBaseMapper.selectLatestEquMonitorList(); + } + /** * 设备类型分类统计信息 diff --git a/ALOps_sys_backend/alops-system/src/main/resources/mapper/system/EquBaseMapper.xml b/ALOps_sys_backend/alops-system/src/main/resources/mapper/system/EquBaseMapper.xml index 34fad4e3..7c769953 100644 --- a/ALOps_sys_backend/alops-system/src/main/resources/mapper/system/EquBaseMapper.xml +++ b/ALOps_sys_backend/alops-system/src/main/resources/mapper/system/EquBaseMapper.xml @@ -152,36 +152,82 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT - b.id, - b.name, - b.ip, - t.name as equType, - m.name as manufacture, - b.version, - b.device_level AS deviceLevel, - b.location, - b.status, - g.cpu_utilization AS cpuUtilization, - g.health, - g.fan_speed AS fanSpeed, - g.cont_work_period AS contWorkPeriod, - b.failure_frequency AS failureFrequency, - -- 新增列:统计未处理告警数量 - (SELECT COUNT(1) - FROM alert_message a - WHERE a.equ_id = b.id AND a.status = 'HANDLED') AS unhandledAlertCount - FROM equ_base b - LEFT JOIN equ_gather g ON b.id = g.equ_id - LEFT JOIN equ_type t ON b.equ_type = t.id - LEFT JOIN equ_manu m ON b.manufacture = m.id - where b.id = #{id} - AND g.cpu_utilization is not null + t.id, + t.name, + t.ip, + t.equType, + t.manufacture, + t.version, + t.deviceLevel, + t.location, + t.status, + t.cpuUtilization, + t.health, + t.fanSpeed, + t.contWorkPeriod, + t.failureFrequency, + t.unhandledAlertCount + FROM ( + SELECT + b.id, + b.name, + b.ip, + t.name AS equType, + m.name AS manufacture, + b.version, + b.device_level AS deviceLevel, + b.location, + b.status, + g.cpu_utilization AS cpuUtilization, + g.health, + g.fan_speed AS fanSpeed, + g.cont_work_period AS contWorkPeriod, + b.failure_frequency AS failureFrequency, + (SELECT COUNT(1) + FROM alert_message a + WHERE a.equ_id = b.id AND a.status = 'HANDLED') AS unhandledAlertCount, + ROW_NUMBER() OVER (PARTITION BY b.id ORDER BY g.gather_time DESC) AS rn + FROM equ_base b + LEFT JOIN equ_type t ON b.equ_type = t.id + LEFT JOIN equ_manu m ON b.manufacture = m.id + LEFT JOIN equ_gather g ON b.id = g.equ_id + ) t + WHERE t.rn = 1 + ORDER BY t.id + - ORDER BY g.gather_time desc limit 1 + +