fix(aiot): 修复删除操作配置推送问题

问题:删除摄像头/ROI/算法绑定后,Edge节点的SQLite数据库仍保留旧配置
原因:删除操作只修改MySQL,未推送配置更新到Edge
影响:告警汇总显示已删除摄像头的历史告警

修复内容:
- AiRoiServiceImpl: 在delete()和unbindAlgo()后推送配置
- StreamProxyServiceImpl: 在delete()后推送配置
- 确保MySQL删除后,配置通过Redis Stream推送到Edge清理SQLite

修复效果:
 删除后自动推送配置更新
 Edge节点同步清理本地数据
 告警汇总不再显示已删除设备
This commit is contained in:
2026-02-13 15:24:36 +08:00
parent b2c2159967
commit e3401192ac
3 changed files with 49 additions and 40 deletions

48
.gitignore vendored
View File

@@ -1,44 +1,12 @@
# Compiled class file
# Existing ignores (preserve)
target/
*.class
# Log file
*.log
logs/*
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
src/main/resources/application-*.yml
# Package Files #
#*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
.idea/
*.iml
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.idea/*
/target/*
/.idea/
/target/
/src/main/resources/static/
certificates
/.vs
/docker/volumes
/docker/wvp/config/jwk.json
# IDE与工具目录
.claude/
.trae/
# 临时脚本与文档
QUICKSTART.md
启动.bat
编译.bat
启动指南-Java17.md
开始使用.md
# Diagnostic documents - DO NOT COMMIT
数据库/aiot/执行指南-*.md
数据库/aiot/*诊断*.md
数据库/aiot/*分析*.md
数据库/aiot/*报告*.md

View File

@@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.aiot.dao.AiEdgeDeviceMapper;
import com.genersoft.iot.vmp.aiot.dao.AiRoiAlgoBindMapper;
import com.genersoft.iot.vmp.aiot.dao.AiRoiMapper;
import com.genersoft.iot.vmp.aiot.service.IAiConfigLogService;
import com.genersoft.iot.vmp.aiot.service.IAiRedisConfigService;
import com.genersoft.iot.vmp.aiot.service.IAiRoiService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -40,6 +41,9 @@ public class AiRoiServiceImpl implements IAiRoiService {
@Autowired
private IAiConfigLogService configLogService;
@Autowired
private IAiRedisConfigService redisConfigService;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
@@ -103,9 +107,19 @@ public class AiRoiServiceImpl implements IAiRoiService {
public void delete(String roiId) {
AiRoi old = roiMapper.queryByRoiId(roiId);
if (old != null) {
String cameraId = old.getCameraId();
bindMapper.deleteByRoiId(roiId);
roiMapper.deleteByRoiId(roiId);
configLogService.addLog("ROI", roiId, toJson(old), null, null);
// 推送配置到 Edge删除操作
if (cameraId != null) {
try {
redisConfigService.writeDeviceAggregatedConfig(cameraId, "UPDATE");
log.info("[AiRoi] 删除 ROI 后推送配置到 Edgecamera_id={}", cameraId);
} catch (Exception e) {
log.error("[AiRoi] 删除 ROI 后推送配置失败camera_id={}", cameraId, e);
}
}
}
}
@@ -171,8 +185,21 @@ public class AiRoiServiceImpl implements IAiRoiService {
public void unbindAlgo(String bindId) {
AiRoiAlgoBind old = bindMapper.queryByBindId(bindId);
if (old != null) {
String roiId = old.getRoiId();
bindMapper.deleteByBindId(bindId);
configLogService.addLog("BIND", bindId, toJson(old), null, null);
// 推送配置到 Edge解绑算法
if (roiId != null) {
AiRoi roi = roiMapper.queryByRoiId(roiId);
if (roi != null && roi.getCameraId() != null) {
try {
redisConfigService.writeDeviceAggregatedConfig(roi.getCameraId(), "UPDATE");
log.info("[AiRoi] 解绑算法后推送配置到 Edgecamera_id={}", roi.getCameraId());
} catch (Exception e) {
log.error("[AiRoi] 解绑算法后推送配置失败camera_id={}", roi.getCameraId(), e);
}
}
}
}
}

View File

@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.streamProxy.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.aiot.service.IAiRedisConfigService;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.common.enums.ChannelDataType;
import com.genersoft.iot.vmp.conf.UserSetting;
@@ -75,6 +76,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
@Autowired
TransactionDefinition transactionDefinition;
@Autowired
private IAiRedisConfigService redisConfigService;
/**
* 生成唯一的 camera_code
* 格式cam_xxxxxxxxxxxx12位随机字符
@@ -194,6 +198,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
private void delete(StreamProxy streamProxy) {
Assert.notNull(streamProxy, "代理不可为NULL");
String cameraCode = streamProxy.getCameraCode();
if (streamProxy.getPulling() != null && streamProxy.getPulling()) {
playService.stopProxy(streamProxy);
}
@@ -201,6 +206,15 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
gbChannelService.delete(streamProxy.getGbId());
}
streamProxyMapper.delete(streamProxy.getId());
// 推送配置到 Edge删除摄像头
if (cameraCode != null) {
try {
redisConfigService.writeDeviceAggregatedConfig(cameraCode, "UPDATE");
log.info("[StreamProxy] 删除摄像头后推送配置到 Edgecamera_code={}", cameraCode);
} catch (Exception e) {
log.error("[StreamProxy] 删除摄像头后推送配置失败camera_code={}", cameraCode, e);
}
}
}
@Override