feat(mq): 增加阈值和DCS报警事件处理功能
- 新增ThresholdAlarmEvent和DcsAlarmEvent事件类 - 实现ThresholdAlarmEventConsumer,处理阈值报警事件,生成报警记录 - 实现DcsAlarmEventConsumer,处理DCS报警事件,生成报警记录 - 自动分配区域负责人并记录处置日志 - 发送报警自动推送消息给负责人 - 阈值报警增加负责人待办任务通知 - AlarmMessageService消息模板改为静态常量,移除配置注入 - SensorDeviceGateway新增根据传感器编码查询接口实现 - 配置文件中新增RocketMQ消费组和绑定设置 - 修改启动类主类配置为com.zcloud.Applicationmain
parent
d92f3c4c4f
commit
d554dcea9c
|
|
@ -39,7 +39,7 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>com.zcloud.iotalarm.IotAlarmApplication</mainClass>
|
||||
<mainClass>com.zcloud.Application</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
mq:
|
||||
topic: springcloudStream-jjb-dragon-test
|
||||
server: ${common.mq.host}
|
||||
threshold-alarm-topic: iot-alarm-threshold-event
|
||||
dcs-alarm-topic: iot-alarm-dcs-event
|
||||
spring:
|
||||
cloud:
|
||||
stream:
|
||||
function:
|
||||
definition: thresholdAlarmConsumer;dcsAlarmConsumer
|
||||
bindings:
|
||||
input:
|
||||
destination: springcloudStream-jjb-dragon-test
|
||||
|
|
@ -11,6 +15,12 @@ spring:
|
|||
output:
|
||||
destination: springcloudStream-jjb-dragon-test
|
||||
group: ${spring.application.name}-${spring.profiles.active}
|
||||
thresholdAlarmConsumer-in-0:
|
||||
destination: iot-alarm-threshold-event
|
||||
group: iot-alarm-main-service
|
||||
dcsAlarmConsumer-in-0:
|
||||
destination: iot-alarm-dcs-event
|
||||
group: iot-alarm-main-service
|
||||
rocketmq:
|
||||
binder:
|
||||
name-server: ${common.mq.host}
|
||||
|
|
@ -19,3 +29,11 @@ spring:
|
|||
input:
|
||||
consumer:
|
||||
tags: a
|
||||
thresholdAlarmConsumer-in-0:
|
||||
consumer:
|
||||
messageModel: CLUSTERING
|
||||
orderly: false
|
||||
dcsAlarmConsumer-in-0:
|
||||
consumer:
|
||||
messageModel: CLUSTERING
|
||||
orderly: false
|
||||
|
|
@ -0,0 +1,203 @@
|
|||
package com.zcloud.mq.consumer;
|
||||
|
||||
import com.zcloud.domain.gateway.AlarmDisposeLogGateway;
|
||||
import com.zcloud.domain.gateway.AlarmRecordGateway;
|
||||
import com.zcloud.domain.gateway.DeviceRegionGateway;
|
||||
import com.zcloud.domain.gateway.RegionSensorRelGateway;
|
||||
import com.zcloud.domain.gateway.SensorDeviceGateway;
|
||||
import com.zcloud.domain.model.AlarmDisposeLogE;
|
||||
import com.zcloud.domain.model.AlarmRecordE;
|
||||
import com.zcloud.domain.model.DeviceRegionE;
|
||||
import com.zcloud.domain.model.RegionSensorRelE;
|
||||
import com.zcloud.domain.model.SensorDeviceE;
|
||||
import com.zcloud.mq.event.DcsAlarmEvent;
|
||||
import com.zcloud.service.AlarmMessageService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* DcsAlarmEventConsumer - DCS报警事件消费者
|
||||
* 消费来自同步服务的DCS报警事件,生成报警记录并自动分配区域负责人
|
||||
* @Author wangyan
|
||||
* @Date 2026-04-03 00:00:00
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class DcsAlarmEventConsumer {
|
||||
|
||||
private final SensorDeviceGateway sensorDeviceGateway;
|
||||
private final RegionSensorRelGateway regionSensorRelGateway;
|
||||
private final DeviceRegionGateway deviceRegionGateway;
|
||||
private final AlarmRecordGateway alarmRecordGateway;
|
||||
private final AlarmDisposeLogGateway alarmDisposeLogGateway;
|
||||
private final AlarmMessageService alarmMessageService;
|
||||
|
||||
@Bean
|
||||
public Consumer<DcsAlarmEvent> dcsAlarmConsumer() {
|
||||
return event -> {
|
||||
try {
|
||||
log.info("收到DCS报警事件: sourceRecordKey={}, sensorCode={}, alarmDesc={}, alarmTime={}",
|
||||
event.getSourceRecordKey(), event.getSensorCode(), event.getAlarmDesc(), event.getAlarmTime());
|
||||
|
||||
// 1. 查找传感器信息
|
||||
SensorDeviceE sensorDevice = sensorDeviceGateway.getBySensorCode(event.getSensorCode());
|
||||
if (sensorDevice == null) {
|
||||
log.warn("未找到传感器: sensorCode={}", event.getSensorCode());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 查找传感器绑定的区域
|
||||
RegionSensorRelE regionSensorRel = regionSensorRelGateway.getBySensorId(sensorDevice.getId());
|
||||
DeviceRegionE deviceRegion = null;
|
||||
if (regionSensorRel != null && regionSensorRel.getFireRegionId() != null) {
|
||||
deviceRegion = deviceRegionGateway.getByFireRegionId(regionSensorRel.getFireRegionId());
|
||||
}
|
||||
|
||||
if (deviceRegion == null) {
|
||||
log.warn("未找到传感器绑定的区域配置: sensorCode={}, sensorId={}",
|
||||
event.getSensorCode(), sensorDevice.getId());
|
||||
}
|
||||
|
||||
// 3. 生成报警记录
|
||||
AlarmRecordE alarmRecord = buildAlarmRecord(event, sensorDevice, deviceRegion, regionSensorRel);
|
||||
Long alarmId = alarmRecordGateway.add(alarmRecord);
|
||||
|
||||
// 4. 记录处置日志(自动分配)
|
||||
AlarmDisposeLogE disposeLog = buildAutoAssignLog(alarmId, alarmRecord.getAlarmNo(),
|
||||
deviceRegion != null ? deviceRegion.getManagerId() : null, event.getTenantId(), event.getOrgId());
|
||||
alarmDisposeLogGateway.add(disposeLog);
|
||||
|
||||
// 5. 发送报警自动推送消息给区域负责人
|
||||
if (deviceRegion != null && deviceRegion.getManagerId() != null) {
|
||||
alarmMessageService.sendAutoPushMessage(alarmRecord, deviceRegion.getManagerId());
|
||||
}
|
||||
|
||||
log.info("DCS报警记录生成成功: alarmId={}, alarmNo={}, managerId={}",
|
||||
alarmId, alarmRecord.getAlarmNo(), alarmRecord.getManagerId());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理DCS报警事件失败: sourceRecordKey={}, error={}",
|
||||
event.getSourceRecordKey(), e.getMessage(), e);
|
||||
// 抛出异常让 RocketMQ 进行消息重试
|
||||
throw new RuntimeException("处理DCS报警事件失败", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建报警记录实体
|
||||
*/
|
||||
private AlarmRecordE buildAlarmRecord(DcsAlarmEvent event, SensorDeviceE sensorDevice,
|
||||
DeviceRegionE deviceRegion, RegionSensorRelE regionSensorRel) {
|
||||
AlarmRecordE alarmRecord = new AlarmRecordE();
|
||||
|
||||
// 业务ID和报警编号
|
||||
alarmRecord.setAlarmRecordId(UUID.randomUUID().toString().replace("-", ""));
|
||||
alarmRecord.setAlarmNo(generateAlarmNo("DCS"));
|
||||
|
||||
// 报警来源
|
||||
alarmRecord.setAlarmSource("DCS");
|
||||
|
||||
// 设备来源描述快照
|
||||
alarmRecord.setDeviceSourceDesc(event.getDeviceSourceDesc());
|
||||
|
||||
// 传感器信息
|
||||
alarmRecord.setSensorId(sensorDevice.getId());
|
||||
alarmRecord.setSensorCode(event.getSensorCode());
|
||||
alarmRecord.setUnitName(sensorDevice.getUnitName());
|
||||
|
||||
// 区域信息(从传感器绑定关系获取)
|
||||
if (regionSensorRel != null && regionSensorRel.getFireRegionId() != null) {
|
||||
alarmRecord.setFireRegionId(regionSensorRel.getFireRegionId());
|
||||
}
|
||||
|
||||
// 负责人信息(自动分配)
|
||||
if (deviceRegion != null) {
|
||||
alarmRecord.setDepartmentId(deviceRegion.getDepartmentId());
|
||||
alarmRecord.setManagerId(deviceRegion.getManagerId());
|
||||
}
|
||||
|
||||
// 报警级别和类型(DCS报警默认为一般级别)
|
||||
alarmRecord.setAlarmLevel("NORMAL");
|
||||
alarmRecord.setAlarmType("DCS_ALARM");
|
||||
|
||||
// 报警描述
|
||||
alarmRecord.setAlarmDesc(event.getAlarmDesc());
|
||||
|
||||
// 报警时间
|
||||
alarmRecord.setAlarmTime(event.getAlarmTime());
|
||||
alarmRecord.setAssignTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
// 状态:10(报警中-待研判)
|
||||
alarmRecord.setStatus(10);
|
||||
|
||||
// 活跃告警标识
|
||||
alarmRecord.setActiveFlag(1);
|
||||
|
||||
// 外部记录唯一键(用于去重)
|
||||
alarmRecord.setSourceRecordKey(event.getSourceRecordKey());
|
||||
|
||||
// 租户和组织
|
||||
alarmRecord.setTenantId(event.getTenantId());
|
||||
alarmRecord.setOrgId(event.getOrgId());
|
||||
|
||||
// 删除标识
|
||||
alarmRecord.setDeleteEnum("FALSE");
|
||||
|
||||
return alarmRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建自动分配处置日志
|
||||
*/
|
||||
private AlarmDisposeLogE buildAutoAssignLog(Long alarmId, String alarmNo, Long managerId, Long tenantId, Long orgId) {
|
||||
AlarmDisposeLogE disposeLog = new AlarmDisposeLogE();
|
||||
|
||||
disposeLog.setAlarmDisposalLogId(UUID.randomUUID().toString().replace("-", ""));
|
||||
disposeLog.setAlarmId(alarmId);
|
||||
disposeLog.setAlarmNo(alarmNo);
|
||||
|
||||
// 操作类型:自动分配
|
||||
disposeLog.setActionType("AUTO_ASSIGN");
|
||||
|
||||
// 状态变更:从无到10(待研判)
|
||||
disposeLog.setBeforeStatus(null);
|
||||
disposeLog.setAfterStatus(10);
|
||||
|
||||
// 操作人:系统自动分配,operatorId 为 managerId
|
||||
disposeLog.setOperatorId(managerId);
|
||||
|
||||
// 操作说明
|
||||
disposeLog.setActionDesc("系统自动分配区域负责人");
|
||||
|
||||
// 操作时间
|
||||
disposeLog.setActionTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
// 租户和组织
|
||||
disposeLog.setTenantId(tenantId);
|
||||
disposeLog.setOrgId(orgId);
|
||||
|
||||
// 删除标识
|
||||
disposeLog.setDeleteEnum("FALSE");
|
||||
|
||||
return disposeLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成报警编号
|
||||
* 格式:DCS-yyyyMMddHHmmss-随机码(8位)
|
||||
*/
|
||||
private String generateAlarmNo(String alarmSource) {
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
String randomCode = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
return alarmSource + "-" + timestamp + "-" + randomCode;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,227 @@
|
|||
package com.zcloud.mq.consumer;
|
||||
|
||||
import com.zcloud.domain.gateway.AlarmDisposeLogGateway;
|
||||
import com.zcloud.domain.gateway.AlarmRecordGateway;
|
||||
import com.zcloud.domain.gateway.DeviceRegionGateway;
|
||||
import com.zcloud.domain.gateway.SensorDeviceGateway;
|
||||
import com.zcloud.domain.model.AlarmDisposeLogE;
|
||||
import com.zcloud.domain.model.AlarmRecordE;
|
||||
import com.zcloud.domain.model.DeviceRegionE;
|
||||
import com.zcloud.domain.model.SensorDeviceE;
|
||||
import com.zcloud.mq.event.ThresholdAlarmEvent;
|
||||
import com.zcloud.service.AlarmMessageService;
|
||||
import com.zcloud.service.AlarmTodoService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* ThresholdAlarmEventConsumer - 阈值报警事件消费者
|
||||
* 消费来自同步服务的阈值报警事件,生成报警记录并自动分配区域负责人
|
||||
* @Author wangyan
|
||||
* @Date 2026-04-03 00:00:00
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class ThresholdAlarmEventConsumer {
|
||||
|
||||
private final SensorDeviceGateway sensorDeviceGateway;
|
||||
private final DeviceRegionGateway deviceRegionGateway;
|
||||
private final AlarmRecordGateway alarmRecordGateway;
|
||||
private final AlarmDisposeLogGateway alarmDisposeLogGateway;
|
||||
private final AlarmMessageService alarmMessageService;
|
||||
private final AlarmTodoService alarmTodoService;
|
||||
|
||||
@Bean
|
||||
public Consumer<ThresholdAlarmEvent> thresholdAlarmConsumer() {
|
||||
return event -> {
|
||||
try {
|
||||
log.info("收到阈值报警事件: sensorCode={}, currentValue={}, thresholdType={}, alarmTime={}",
|
||||
event.getSensorCode(), event.getCurrentValue(), event.getThresholdType(), event.getAlarmTime());
|
||||
|
||||
// 1. 查找传感器信息
|
||||
SensorDeviceE sensorDevice = sensorDeviceGateway.getBySensorCode(event.getSensorCode());
|
||||
if (sensorDevice == null) {
|
||||
log.warn("未找到传感器: sensorCode={}", event.getSensorCode());
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 查找区域配置
|
||||
DeviceRegionE deviceRegion = null;
|
||||
if (event.getFireRegionId() != null) {
|
||||
deviceRegion = deviceRegionGateway.getByFireRegionId(event.getFireRegionId());
|
||||
}
|
||||
|
||||
if (deviceRegion == null) {
|
||||
log.warn("未找到区域配置: fireRegionId={}", event.getFireRegionId());
|
||||
}
|
||||
|
||||
// 3. 生成报警记录
|
||||
AlarmRecordE alarmRecord = buildAlarmRecord(event, sensorDevice, deviceRegion);
|
||||
Long alarmId = alarmRecordGateway.add(alarmRecord);
|
||||
|
||||
// 4. 记录处置日志(自动分配)
|
||||
AlarmDisposeLogE disposeLog = buildAutoAssignLog(alarmId, alarmRecord.getAlarmNo(),
|
||||
deviceRegion != null ? deviceRegion.getManagerId() : null, event.getTenantId(), event.getOrgId());
|
||||
alarmDisposeLogGateway.add(disposeLog);
|
||||
|
||||
// 5. 发送报警自动推送消息给区域负责人
|
||||
if (deviceRegion != null && deviceRegion.getManagerId() != null) {
|
||||
alarmMessageService.sendAutoPushMessage(alarmRecord, deviceRegion.getManagerId());
|
||||
}
|
||||
|
||||
// 6. 新增负责人待办(PC端)
|
||||
if (deviceRegion != null && deviceRegion.getManagerId() != null) {
|
||||
alarmTodoService.addManagerTodo(alarmRecord, deviceRegion.getManagerId());
|
||||
}
|
||||
|
||||
log.info("阈值报警记录生成成功: alarmId={}, alarmNo={}, managerId={}",
|
||||
alarmId, alarmRecord.getAlarmNo(), alarmRecord.getManagerId());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理阈值报警事件失败: sensorCode={}, error={}",
|
||||
event.getSensorCode(), e.getMessage(), e);
|
||||
// 抛出异常让 RocketMQ 进行消息重试
|
||||
throw new RuntimeException("处理阈值报警事件失败", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建报警记录实体
|
||||
*/
|
||||
private AlarmRecordE buildAlarmRecord(ThresholdAlarmEvent event, SensorDeviceE sensorDevice, DeviceRegionE deviceRegion) {
|
||||
AlarmRecordE alarmRecord = new AlarmRecordE();
|
||||
|
||||
// 业务ID和报警编号
|
||||
alarmRecord.setAlarmRecordId(UUID.randomUUID().toString().replace("-", ""));
|
||||
alarmRecord.setAlarmNo(generateAlarmNo("THRESHOLD"));
|
||||
|
||||
// 报警来源
|
||||
alarmRecord.setAlarmSource("THRESHOLD");
|
||||
|
||||
// 设备来源描述快照
|
||||
alarmRecord.setDeviceSourceDesc(event.getDeviceSourceDesc());
|
||||
|
||||
// 传感器信息
|
||||
alarmRecord.setSensorId(sensorDevice.getId());
|
||||
alarmRecord.setSensorCode(event.getSensorCode());
|
||||
alarmRecord.setUnitName(sensorDevice.getUnitName());
|
||||
|
||||
// 区域信息
|
||||
if (event.getFireRegionId() != null) {
|
||||
alarmRecord.setFireRegionId(event.getFireRegionId());
|
||||
}
|
||||
|
||||
// 负责人信息(自动分配)
|
||||
if (deviceRegion != null) {
|
||||
alarmRecord.setDepartmentId(deviceRegion.getDepartmentId());
|
||||
alarmRecord.setManagerId(deviceRegion.getManagerId());
|
||||
}
|
||||
|
||||
// 报警级别和类型
|
||||
alarmRecord.setAlarmLevel(mapThresholdTypeToAlarmLevel(event.getThresholdType()));
|
||||
alarmRecord.setAlarmType("THRESHOLD_ALARM");
|
||||
alarmRecord.setThresholdType(event.getThresholdType());
|
||||
|
||||
// 告警值和比较方向
|
||||
alarmRecord.setCurrentValue(event.getCurrentValue());
|
||||
alarmRecord.setCompareFlag(mapThresholdTypeToCompareFlag(event.getThresholdType()));
|
||||
|
||||
// 报警时间
|
||||
alarmRecord.setAlarmTime(event.getAlarmTime());
|
||||
alarmRecord.setAssignTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
// 状态:10(报警中-待研判)
|
||||
alarmRecord.setStatus(10);
|
||||
|
||||
// 活跃告警标识
|
||||
alarmRecord.setActiveFlag(1);
|
||||
|
||||
// 租户和组织
|
||||
alarmRecord.setTenantId(event.getTenantId());
|
||||
alarmRecord.setOrgId(event.getOrgId());
|
||||
|
||||
// 删除标识
|
||||
alarmRecord.setDeleteEnum("FALSE");
|
||||
|
||||
return alarmRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建自动分配处置日志
|
||||
*/
|
||||
private AlarmDisposeLogE buildAutoAssignLog(Long alarmId, String alarmNo, Long managerId, Long tenantId, Long orgId) {
|
||||
AlarmDisposeLogE disposeLog = new AlarmDisposeLogE();
|
||||
|
||||
disposeLog.setAlarmDisposalLogId(UUID.randomUUID().toString().replace("-", ""));
|
||||
disposeLog.setAlarmId(alarmId);
|
||||
disposeLog.setAlarmNo(alarmNo);
|
||||
|
||||
// 操作类型:自动分配
|
||||
disposeLog.setActionType("AUTO_ASSIGN");
|
||||
|
||||
// 状态变更:从无到10(待研判)
|
||||
disposeLog.setBeforeStatus(null);
|
||||
disposeLog.setAfterStatus(10);
|
||||
|
||||
// 操作人:系统自动分配,operatorId 为 null
|
||||
disposeLog.setOperatorId(managerId);
|
||||
|
||||
// 操作说明
|
||||
disposeLog.setActionDesc("系统自动分配区域负责人");
|
||||
|
||||
// 操作时间
|
||||
disposeLog.setActionTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
|
||||
// 租户和组织
|
||||
disposeLog.setTenantId(tenantId);
|
||||
disposeLog.setOrgId(orgId);
|
||||
|
||||
// 删除标识
|
||||
disposeLog.setDeleteEnum("FALSE");
|
||||
|
||||
return disposeLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成报警编号
|
||||
* 格式:THRESHOLD-yyyyMMddHHmmss-随机码(8位)
|
||||
*/
|
||||
private String generateAlarmNo(String alarmSource) {
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
String randomCode = UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
return alarmSource + "-" + timestamp + "-" + randomCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 阈值类型映射为报警级别
|
||||
* LOW_LOW/HIGH_HIGH -> 紧急
|
||||
* LOW/HIGH -> 一般
|
||||
*/
|
||||
private String mapThresholdTypeToAlarmLevel(String thresholdType) {
|
||||
if ("LOW_LOW".equals(thresholdType) || "HIGH_HIGH".equals(thresholdType)) {
|
||||
return "URGENT";
|
||||
}
|
||||
return "NORMAL";
|
||||
}
|
||||
|
||||
/**
|
||||
* 阈值类型映射为比较方向
|
||||
* LOW/LOW_LOW -> DOWN(下降)
|
||||
* HIGH/HIGH_HIGH -> UP(上升)
|
||||
*/
|
||||
private String mapThresholdTypeToCompareFlag(String thresholdType) {
|
||||
if ("LOW".equals(thresholdType) || "LOW_LOW".equals(thresholdType)) {
|
||||
return "DOWN";
|
||||
}
|
||||
return "UP";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.zcloud.mq.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* DcsAlarmEvent - DCS报警事件
|
||||
* 来自同步服务的DCS报警事件
|
||||
* @Author wangyan
|
||||
* @Date 2026-04-03 00:00:00
|
||||
*/
|
||||
@Data
|
||||
public class DcsAlarmEvent implements Serializable {
|
||||
|
||||
/**
|
||||
* 源记录唯一键(用于去重)
|
||||
*/
|
||||
private String sourceRecordKey;
|
||||
|
||||
/**
|
||||
* 传感器编码
|
||||
*/
|
||||
private String sensorCode;
|
||||
|
||||
/**
|
||||
* 报警描述
|
||||
*/
|
||||
private String alarmDesc;
|
||||
|
||||
/**
|
||||
* 报警时间(格式:yyyy-MM-dd HH:mm:ss)
|
||||
*/
|
||||
private String alarmTime;
|
||||
|
||||
/**
|
||||
* 设备来源描述
|
||||
*/
|
||||
private String deviceSourceDesc;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 组织ID
|
||||
*/
|
||||
private Long orgId;
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.zcloud.mq.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* ThresholdAlarmEvent - 阈值报警事件
|
||||
* 来自同步服务的阈值报警事件
|
||||
* @Author wangyan
|
||||
* @Date 2026-04-03 00:00:00
|
||||
*/
|
||||
@Data
|
||||
public class ThresholdAlarmEvent implements Serializable {
|
||||
|
||||
/**
|
||||
* 传感器编码
|
||||
*/
|
||||
private String sensorCode;
|
||||
|
||||
/**
|
||||
* 当前值
|
||||
*/
|
||||
private BigDecimal currentValue;
|
||||
|
||||
/**
|
||||
* 阈值类型(LOW_LOW/LOW/HIGH/HIGH_HIGH)
|
||||
*/
|
||||
private String thresholdType;
|
||||
|
||||
/**
|
||||
* 报警时间(格式:yyyy-MM-dd HH:mm:ss)
|
||||
*/
|
||||
private String alarmTime;
|
||||
|
||||
/**
|
||||
* 设备来源描述
|
||||
*/
|
||||
private String deviceSourceDesc;
|
||||
|
||||
/**
|
||||
* 消防区域ID
|
||||
*/
|
||||
private Long fireRegionId;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 组织ID
|
||||
*/
|
||||
private Long orgId;
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ import com.zcloud.gbscommon.utils.UuidUtil;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -29,11 +28,9 @@ public class AlarmMessageService {
|
|||
@DubboReference
|
||||
private MessageFacade messageFacade;
|
||||
|
||||
@Value("${alarm.message.template.auto-push:}")
|
||||
private String autoPushTemplateCode;
|
||||
|
||||
@Value("${alarm.message.template.dispose-push:}")
|
||||
private String disposePushTemplateCode;
|
||||
// TODO: 后续需要配置消息模板编码
|
||||
private static final String AUTO_PUSH_TEMPLATE_CODE = "MT0001XX";
|
||||
private static final String DISPOSE_PUSH_TEMPLATE_CODE = "MT0001XX";
|
||||
|
||||
/**
|
||||
* 发送报警自动推送消息
|
||||
|
|
@ -54,11 +51,12 @@ public class AlarmMessageService {
|
|||
messageTargetCmd.setUserId(managerId);
|
||||
messageSendCmd.setTargetCmd(messageTargetCmd);
|
||||
|
||||
messageSendCmd.setSourceCode(autoPushTemplateCode);
|
||||
messageSendCmd.setSourceCode(AUTO_PUSH_TEMPLATE_CODE);
|
||||
messageSendCmd.setNeedTokenEnum(false);
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("deviceSourceDesc", alarmRecord.getDeviceSourceDesc());
|
||||
params.put("alarmNo", alarmRecord.getAlarmNo());
|
||||
params.put("alarmLevel", alarmRecord.getAlarmLevel());
|
||||
params.put("alarmTime", alarmRecord.getAlarmTime());
|
||||
params.put("alarmDesc", alarmRecord.getAlarmDesc());
|
||||
|
|
@ -91,11 +89,12 @@ public class AlarmMessageService {
|
|||
messageTargetCmd.setUserId(disposeUserId);
|
||||
messageSendCmd.setTargetCmd(messageTargetCmd);
|
||||
|
||||
messageSendCmd.setSourceCode(disposePushTemplateCode);
|
||||
messageSendCmd.setSourceCode(DISPOSE_PUSH_TEMPLATE_CODE);
|
||||
messageSendCmd.setNeedTokenEnum(false);
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("deviceSourceDesc", alarmRecord.getDeviceSourceDesc());
|
||||
params.put("alarmNo", alarmRecord.getAlarmNo());
|
||||
params.put("alarmLevel", alarmRecord.getAlarmLevel());
|
||||
params.put("assignTime", alarmRecord.getAssignTime());
|
||||
params.put("disposeRemark", alarmRecord.getDisposeRemark());
|
||||
|
|
|
|||
|
|
@ -28,4 +28,9 @@ public interface SensorDeviceGateway {
|
|||
* 根据ID获取
|
||||
*/
|
||||
SensorDeviceE getById(Long id);
|
||||
|
||||
/**
|
||||
* 根据传感器编码获取
|
||||
*/
|
||||
SensorDeviceE getBySensorCode(String sensorCode);
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.zcloud.domain.gateway.SensorDeviceGateway;
|
|||
import com.zcloud.domain.model.SensorDeviceE;
|
||||
import com.zcloud.persistence.dataobject.SensorDeviceDO;
|
||||
import com.zcloud.persistence.repository.SensorDeviceRepository;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -50,4 +51,19 @@ public class SensorDeviceGatewayImpl implements SensorDeviceGateway {
|
|||
BeanUtils.copyProperties(d, sensorDeviceE);
|
||||
return sensorDeviceE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SensorDeviceE getBySensorCode(String sensorCode) {
|
||||
LambdaQueryWrapper<SensorDeviceDO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SensorDeviceDO::getSensorCode, sensorCode)
|
||||
.eq(SensorDeviceDO::getDeleteEnum, "FALSE");
|
||||
|
||||
SensorDeviceDO d = sensorDeviceRepository.getOne(wrapper);
|
||||
if (d == null) {
|
||||
return null;
|
||||
}
|
||||
SensorDeviceE sensorDeviceE = new SensorDeviceE();
|
||||
BeanUtils.copyProperties(d, sensorDeviceE);
|
||||
return sensorDeviceE;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue