diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiAlertMapper.java b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiAlertMapper.java
new file mode 100644
index 000000000..ae58d09eb
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiAlertMapper.java
@@ -0,0 +1,52 @@
+package com.genersoft.iot.vmp.aiot.dao;
+
+import com.genersoft.iot.vmp.aiot.bean.AiAlert;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+@Mapper
+public interface AiAlertMapper {
+
+ @Insert("INSERT INTO wvp_ai_alert (alert_id, camera_id, roi_id, bind_id, alert_type, target_class, " +
+ "confidence, bbox, message, image_path, duration_minutes, extra_data, received_at) " +
+ "VALUES (#{alertId}, #{cameraId}, #{roiId}, #{bindId}, #{alertType}, #{targetClass}, " +
+ "#{confidence}, #{bbox}, #{message}, #{imagePath}, #{durationMinutes}, #{extraData}, #{receivedAt})")
+ @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
+ int add(AiAlert alert);
+
+ @Select("SELECT * FROM wvp_ai_alert WHERE alert_id=#{alertId}")
+ AiAlert queryByAlertId(@Param("alertId") String alertId);
+
+ @Select(value = {""})
+ List queryList(@Param("cameraId") String cameraId,
+ @Param("alertType") String alertType,
+ @Param("startTime") String startTime,
+ @Param("endTime") String endTime);
+
+ @Delete("DELETE FROM wvp_ai_alert WHERE alert_id=#{alertId}")
+ int deleteByAlertId(@Param("alertId") String alertId);
+
+ @Delete(value = {""})
+ int deleteByAlertIds(@Param("alertIds") List alertIds);
+
+ @Select("SELECT alert_type, COUNT(*) as cnt FROM wvp_ai_alert " +
+ "WHERE received_at >= #{startTime} GROUP BY alert_type")
+ List> statisticsByType(@Param("startTime") String startTime);
+
+ @Select("SELECT camera_id, COUNT(*) as cnt FROM wvp_ai_alert " +
+ "WHERE received_at >= #{startTime} GROUP BY camera_id ORDER BY cnt DESC")
+ List> statisticsByCamera(@Param("startTime") String startTime);
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiAlgoTemplateMapper.java b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiAlgoTemplateMapper.java
new file mode 100644
index 000000000..d124f297c
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiAlgoTemplateMapper.java
@@ -0,0 +1,35 @@
+package com.genersoft.iot.vmp.aiot.dao;
+
+import com.genersoft.iot.vmp.aiot.bean.AiAlgoTemplate;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+@Mapper
+public interface AiAlgoTemplateMapper {
+
+ @Insert("INSERT INTO wvp_ai_algo_template (template_id, template_name, algo_code, params, " +
+ "description, create_time, update_time) " +
+ "VALUES (#{templateId}, #{templateName}, #{algoCode}, #{params}, " +
+ "#{description}, #{createTime}, #{updateTime})")
+ @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
+ int add(AiAlgoTemplate template);
+
+ @Update("UPDATE wvp_ai_algo_template SET template_name=#{templateName}, algo_code=#{algoCode}, " +
+ "params=#{params}, description=#{description}, update_time=#{updateTime} " +
+ "WHERE template_id=#{templateId}")
+ int updateByTemplateId(AiAlgoTemplate template);
+
+ @Delete("DELETE FROM wvp_ai_algo_template WHERE template_id=#{templateId}")
+ int deleteByTemplateId(@Param("templateId") String templateId);
+
+ @Select("SELECT * FROM wvp_ai_algo_template WHERE template_id=#{templateId}")
+ AiAlgoTemplate queryByTemplateId(@Param("templateId") String templateId);
+
+ @Select(value = {""})
+ List queryList(@Param("algoCode") String algoCode);
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiConfigSnapshotMapper.java b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiConfigSnapshotMapper.java
new file mode 100644
index 000000000..35fcf26db
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiConfigSnapshotMapper.java
@@ -0,0 +1,41 @@
+package com.genersoft.iot.vmp.aiot.dao;
+
+import com.genersoft.iot.vmp.aiot.bean.AiConfigSnapshot;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+@Mapper
+public interface AiConfigSnapshotMapper {
+
+ @Insert("INSERT INTO wvp_ai_config_snapshot (version, scope_type, scope_id, camera_id, snapshot, " +
+ "change_type, change_desc, created_by, created_at) " +
+ "VALUES (#{version}, #{scopeType}, #{scopeId}, #{cameraId}, #{snapshot}, " +
+ "#{changeType}, #{changeDesc}, #{createdBy}, #{createdAt})")
+ @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
+ int add(AiConfigSnapshot snapshot);
+
+ @Select("SELECT COALESCE(MAX(version), 0) FROM wvp_ai_config_snapshot " +
+ "WHERE scope_type=#{scopeType} AND scope_id=#{scopeId}")
+ int getMaxVersion(@Param("scopeType") String scopeType, @Param("scopeId") String scopeId);
+
+ @Select("SELECT * FROM wvp_ai_config_snapshot WHERE id=#{id}")
+ AiConfigSnapshot queryById(@Param("id") Long id);
+
+ @Select("SELECT * FROM wvp_ai_config_snapshot " +
+ "WHERE scope_type=#{scopeType} AND scope_id=#{scopeId} AND version=#{version}")
+ AiConfigSnapshot queryByVersion(@Param("scopeType") String scopeType,
+ @Param("scopeId") String scopeId,
+ @Param("version") Integer version);
+
+ @Select(value = {""})
+ List queryList(@Param("scopeType") String scopeType,
+ @Param("scopeId") String scopeId,
+ @Param("cameraId") String cameraId);
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiEdgeDeviceMapper.java b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiEdgeDeviceMapper.java
new file mode 100644
index 000000000..94a23a082
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiEdgeDeviceMapper.java
@@ -0,0 +1,33 @@
+package com.genersoft.iot.vmp.aiot.dao;
+
+import com.genersoft.iot.vmp.aiot.bean.AiEdgeDevice;
+import org.apache.ibatis.annotations.*;
+
+import java.util.List;
+
+@Mapper
+public interface AiEdgeDeviceMapper {
+
+ @Insert("INSERT INTO wvp_ai_edge_device (device_id, status, last_heartbeat, uptime_seconds, " +
+ "frames_processed, alerts_generated, stream_stats, updated_at) " +
+ "VALUES (#{deviceId}, #{status}, #{lastHeartbeat}, #{uptimeSeconds}, " +
+ "#{framesProcessed}, #{alertsGenerated}, #{streamStats}, #{updatedAt})")
+ @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
+ int add(AiEdgeDevice device);
+
+ @Update("UPDATE wvp_ai_edge_device SET status=#{status}, last_heartbeat=#{lastHeartbeat}, " +
+ "uptime_seconds=#{uptimeSeconds}, frames_processed=#{framesProcessed}, " +
+ "alerts_generated=#{alertsGenerated}, stream_stats=#{streamStats}, " +
+ "updated_at=#{updatedAt} WHERE device_id=#{deviceId}")
+ int updateByDeviceId(AiEdgeDevice device);
+
+ @Select("SELECT * FROM wvp_ai_edge_device WHERE device_id=#{deviceId}")
+ AiEdgeDevice queryByDeviceId(@Param("deviceId") String deviceId);
+
+ @Select("SELECT * FROM wvp_ai_edge_device ORDER BY updated_at DESC")
+ List queryAll();
+
+ @Update("UPDATE wvp_ai_edge_device SET status='offline', updated_at=#{now} " +
+ "WHERE status='online' AND last_heartbeat < #{threshold}")
+ int markOffline(@Param("threshold") String threshold, @Param("now") String now);
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiAlgoBindMapper.java b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiAlgoBindMapper.java
index ee6e79d95..29890de45 100644
--- a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiAlgoBindMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiAlgoBindMapper.java
@@ -8,13 +8,16 @@ import java.util.List;
@Mapper
public interface AiRoiAlgoBindMapper {
- @Insert("INSERT INTO wvp_ai_roi_algo_bind (bind_id, roi_id, algo_code, params, priority, enabled, create_time, update_time) " +
- "VALUES (#{bindId}, #{roiId}, #{algoCode}, #{params}, #{priority}, #{enabled}, #{createTime}, #{updateTime})")
+ @Insert("INSERT INTO wvp_ai_roi_algo_bind (bind_id, roi_id, algo_code, params, priority, enabled, " +
+ "template_id, param_override, create_time, update_time) " +
+ "VALUES (#{bindId}, #{roiId}, #{algoCode}, #{params}, #{priority}, #{enabled}, " +
+ "#{templateId}, #{paramOverride}, #{createTime}, #{updateTime})")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int add(AiRoiAlgoBind bind);
@Update("UPDATE wvp_ai_roi_algo_bind SET params=#{params}, priority=#{priority}, " +
- "enabled=#{enabled}, update_time=#{updateTime} WHERE bind_id=#{bindId}")
+ "enabled=#{enabled}, template_id=#{templateId}, param_override=#{paramOverride}, " +
+ "update_time=#{updateTime} WHERE bind_id=#{bindId}")
int updateByBindId(AiRoiAlgoBind bind);
@Delete("DELETE FROM wvp_ai_roi_algo_bind WHERE bind_id=#{bindId}")
@@ -31,4 +34,12 @@ public interface AiRoiAlgoBindMapper {
@Select("SELECT * FROM wvp_ai_roi_algo_bind WHERE roi_id=#{roiId} AND algo_code=#{algoCode}")
AiRoiAlgoBind queryByRoiIdAndAlgoCode(@Param("roiId") String roiId, @Param("algoCode") String algoCode);
+
+ @Select("SELECT * FROM wvp_ai_roi_algo_bind WHERE template_id=#{templateId}")
+ List queryByTemplateId(@Param("templateId") String templateId);
+
+ @Select("SELECT b.* FROM wvp_ai_roi_algo_bind b " +
+ "INNER JOIN wvp_ai_roi r ON b.roi_id = r.roi_id " +
+ "WHERE r.camera_id=#{cameraId} ORDER BY b.priority DESC, b.id")
+ List queryByCameraId(@Param("cameraId") String cameraId);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiMapper.java b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiMapper.java
index 8b021fbd0..fbefbeb9d 100644
--- a/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/aiot/dao/AiRoiMapper.java
@@ -43,4 +43,7 @@ public interface AiRoiMapper {
@Select("SELECT * FROM wvp_ai_roi WHERE camera_id=#{cameraId} AND enabled=1 ORDER BY priority DESC")
List queryByCameraId(@Param("cameraId") String cameraId);
+
+ @Select("SELECT * FROM wvp_ai_roi WHERE camera_id=#{cameraId} ORDER BY priority DESC")
+ List queryAllByCameraId(@Param("cameraId") String cameraId);
}