From e3401192acf7da6ec33f77e6efc56f88b84914fe Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Fri, 13 Feb 2026 15:24:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(aiot):=20=E4=BF=AE=E5=A4=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=93=8D=E4=BD=9C=E9=85=8D=E7=BD=AE=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:删除摄像头/ROI/算法绑定后,Edge节点的SQLite数据库仍保留旧配置 原因:删除操作只修改MySQL,未推送配置更新到Edge 影响:告警汇总显示已删除摄像头的历史告警 修复内容: - AiRoiServiceImpl: 在delete()和unbindAlgo()后推送配置 - StreamProxyServiceImpl: 在delete()后推送配置 - 确保MySQL删除后,配置通过Redis Stream推送到Edge清理SQLite 修复效果: ✅ 删除后自动推送配置更新 ✅ Edge节点同步清理本地数据 ✅ 告警汇总不再显示已删除设备 --- .gitignore | 48 ++++--------------- .../aiot/service/impl/AiRoiServiceImpl.java | 27 +++++++++++ .../service/impl/StreamProxyServiceImpl.java | 14 ++++++ 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 27e157b42..fea7419bd 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRoiServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRoiServiceImpl.java index 31909900d..5821a4f58 100644 --- a/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRoiServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/aiot/service/impl/AiRoiServiceImpl.java @@ -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 后推送配置到 Edge,camera_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] 解绑算法后推送配置到 Edge,camera_id={}", roi.getCameraId()); + } catch (Exception e) { + log.error("[AiRoi] 解绑算法后推送配置失败,camera_id={}", roi.getCameraId(), e); + } + } + } } } diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java index afc9b7b2b..e5f359e4b 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java @@ -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_xxxxxxxxxxxx(12位随机字符) @@ -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] 删除摄像头后推送配置到 Edge,camera_code={}", cameraCode); + } catch (Exception e) { + log.error("[StreamProxy] 删除摄像头后推送配置失败,camera_code={}", cameraCode, e); + } + } } @Override