feat(device): 优化设备报警处理逻辑与数据存储
- 调整报警确认阈值从3次到15次 - 增加最小报警持续时间至60秒 - 改进Redis数据存储结构,按设备ID单独存储避免覆盖 - 实现设备ID历史列表的增量更新维护 - 完善报警确认与恢复的时间判断机制 - 优化报警日志与告警信息表的处理流程dev
parent
9658b6dc50
commit
391164a205
|
|
@ -54,10 +54,10 @@ public class AppPosiDeviceController {
|
|||
private final Map<String, Map<String, Object>> currentAlarmInfo = new ConcurrentHashMap<>();
|
||||
|
||||
// 报警确认次数阈值
|
||||
private static final int ALARM_CONFIRM_THRESHOLD = 3;
|
||||
private static final int ALARM_CONFIRM_THRESHOLD = 15;
|
||||
|
||||
// 最小报警持续时间(毫秒),默认10秒
|
||||
private static final long MIN_ALARM_DURATION = 10 * 1000;
|
||||
private static final long MIN_ALARM_DURATION = 60 * 1000;
|
||||
|
||||
@PostMapping("/test1")
|
||||
public R test1(@RequestBody HashMap<String, String> parma) throws Exception {
|
||||
|
|
@ -228,8 +228,39 @@ public class AppPosiDeviceController {
|
|||
// 存储集合中处理好的数据
|
||||
if (!dataList.isEmpty()) {
|
||||
mesDeviceMonitoringMapper.saveBatchFromMes(dataList);
|
||||
// 将物联网数据存入Redis缓存
|
||||
redisUtil.set("WMK_DATA_LIST", JSONObject.toJSONString(dataList));
|
||||
// 将物联网数据存入Redis缓存,以设备ID为键存储,避免覆盖和重复
|
||||
for (Map<String, Object> data : dataList) {
|
||||
String equipmentId = (String) data.get("EQUIPMENT_ID");
|
||||
if (equipmentId != null && !equipmentId.isEmpty()) {
|
||||
// 使用设备ID作为键存储单个设备数据
|
||||
String key = "WMK_DEVICE:" + equipmentId;
|
||||
redisUtil.set(key, JSONObject.toJSONString(data), 3600); // 1小时过期
|
||||
}
|
||||
}
|
||||
|
||||
// 维护一个包含所有历史设备ID的集合(增量更新)
|
||||
// 首先获取现有的设备ID列表
|
||||
Set<String> allEquipmentIds = new HashSet<>();
|
||||
String existingEquipmentIdsJson = (String) redisUtil.get("WMK_ALL_DEVICES");
|
||||
if (existingEquipmentIdsJson != null && !existingEquipmentIdsJson.isEmpty()) {
|
||||
try {
|
||||
List<String> existingEquipmentIds = JSONArray.parseArray(existingEquipmentIdsJson, String.class);
|
||||
allEquipmentIds.addAll(existingEquipmentIds);
|
||||
} catch (Exception e) {
|
||||
// 解析失败则忽略现有数据
|
||||
XxlJobHelper.log("解析现有设备ID列表失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 添加当前批次的新设备ID
|
||||
List<String> currentEquipmentIds = dataList.stream()
|
||||
.map(data -> (String) data.get("EQUIPMENT_ID"))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
allEquipmentIds.addAll(currentEquipmentIds);
|
||||
|
||||
// 存储更新后的设备ID列表
|
||||
redisUtil.set("WMK_ALL_DEVICES", JSONObject.toJSONString(new ArrayList<>(allEquipmentIds)), 3600);
|
||||
XxlJobHelper.log("成功保存{}条物联网模块数据到本地数据库", dataList.size());
|
||||
|
||||
// 处理报警数据
|
||||
|
|
|
|||
Loading…
Reference in New Issue