10. Alarm 服务
通过 client.alarm() 访问。提供报警事件的单条查询/最近查询两项功能。如需详细统计或报警配置(Config)的 CRUD,可直接使用数据网关。
9.1 方法一览
| 方法 | 返回类型 | HTTP | 端点 |
|---|---|---|---|
get(alarm_seq) | AlarmResponseV5 或 null | GET | /api/v5/alarm/{seq} |
list(limit) | List<AlarmResponseV5> | GET | /api/v5/alarm?limit=... |
建议使用
limit ≤ 1000。如需更多数据,建议通过数据网关直接查询。
9.2 AlarmResponseV5 DTO
同时包含报警主体 + 位置(tag/opc/site)JOIN 结果。
报警主体字段
| 字段 | 类型 | 说明 |
|---|---|---|
alarm_seq | long | 报警序列号 (PK) |
alarm_config_id | String | 报警配置 ID |
priority | String | 优先级 (HI_HI、HI、LO、LO_LO、TRIP) |
description | String | 报警消息 |
is_on | String | 当前是否激活 (Y/N) |
is_read | String | 是否已读 (Y/N) |
on_timestamp | long | 发生时刻(毫秒) |
off_timestamp | long | 解除时刻(0 = 未解除) |
on_duration | long | 持续时间(毫秒) |
位置 JOIN 字段(包含在 list 响应中)
| 字段 | 说明 |
|---|---|
tag_id、tag_name、tag_description | 标签信息 |
opc_id、opc_name | OPC 信息 |
site_id、site_name | 站点信息 |
tag_location | 资产路径字符串 (SITE > AREA > LINE > EQUIPMENT) |
单条
get()响应通常仅填充 mm_alarm 主体,JOIN 字段多为null。若用于 UI 显示,建议使用list()的结果。
9.3 报警优先级
| 代码 | 含义 | 常用颜色 |
|---|---|---|
HI_HI | 危险 (Critical) | 红色 |
HI | 注意 (Warning) | 橙色 |
LO | 信息 (Info) | 黄色 |
LO_LO | 恢复 (Recovery) | 蓝色 |
TRIP | 跳闸(强制停机) | 黑色 |
9.4 使用示例
最近报警列表
import java.util.List;
import plantpulse.api.v5.dto.response.AlarmResponseV5;
List<AlarmResponseV5> alarms = client.alarm().list(50);
for (AlarmResponseV5 a : alarms) {
System.out.printf("[%s] %s - %s (%s)%n",
a.getPriority(),
a.getSite_name(),
a.getDescription(),
a.getTag_location());
}
输出示例:
[HI_HI] 대전공장 - Spindle 온도 임계치 초과 (SITE_DJ > A_0001 > L_0001 > CNC #1)
[HI] 대전공장 - 압력 상한 (SITE_DJ > A_0001 > L_0001 > Press #2)
单条查询
AlarmResponseV5 alarm = client.alarm().get(12345L);
if (alarm != null) {
System.out.println("발생 시각: " + alarm.getOn_timestamp());
System.out.println("우선순위: " + alarm.getPriority());
System.out.println("지속 시간: " + alarm.getOn_duration() + " ms");
}
仅筛选激活报警(客户端侧)
V5 不支持服务端激活状态过滤,因此在客户端处理。
import java.util.stream.Collectors;
List<AlarmResponseV5> active = client.alarm().list(500).stream()
.filter(a -> "Y".equals(a.getIs_on()))
.collect(Collectors.toList());
System.out.println("현재 활성 알람: " + active.size() + "건");
按站点分组
import java.util.Map;
import java.util.stream.Collectors;
Map<String, Long> bySite = client.alarm().list(1000).stream()
.filter(a -> "Y".equals(a.getIs_on()))
.collect(Collectors.groupingBy(
AlarmResponseV5::getSite_id,
Collectors.counting()));
bySite.forEach((siteId, count) ->
System.out.printf("%s: %d건%n", siteId, count));
按优先级计数
Map<String, Long> byPriority = client.alarm().list(1000).stream()
.collect(Collectors.groupingBy(
AlarmResponseV5::getPriority,
Collectors.counting()));
9.5 应用场景
场景 —— 实时报警仪表板
while (running) {
List<AlarmResponseV5> alarms = client.alarm().list(100);
long critical = alarms.stream()
.filter(a -> "Y".equals(a.getIs_on()))
.filter(a -> "HI_HI".equals(a.getPriority()))
.count();
updateDashboard(alarms, critical);
Thread.sleep(1_000);
}
场景 —— 仅查看特定资产产线的报警
String targetLine = "SITE_DJ > A_0001 > L_0001";
List<AlarmResponseV5> lineAlarms = client.alarm().list(500).stream()
.filter(a -> a.getTag_location() != null
&& a.getTag_location().startsWith(targetLine))
.collect(Collectors.toList());