feat(aiot): 新增方案B Mapper接口

- AiAlertMapper: AI告警数据访问
- AiAlgoTemplateMapper: 算法模板数据访问
- AiConfigSnapshotMapper: 配置快照数据访问
- AiEdgeDeviceMapper: 边缘设备数据访问
- 更新 AiRoiMapper 和 AiRoiAlgoBindMapper

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 13:31:24 +08:00
parent b0df1485ad
commit efdc08c469
6 changed files with 178 additions and 3 deletions

View File

@@ -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 = {"<script>" +
"SELECT * FROM wvp_ai_alert WHERE 1=1 " +
"<if test='cameraId != null'> AND camera_id=#{cameraId}</if> " +
"<if test='alertType != null'> AND alert_type=#{alertType}</if> " +
"<if test='startTime != null'> AND received_at &gt;= #{startTime}</if> " +
"<if test='endTime != null'> AND received_at &lt;= #{endTime}</if> " +
"ORDER BY received_at DESC" +
"</script>"})
List<AiAlert> 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 = {"<script>" +
"DELETE FROM wvp_ai_alert WHERE alert_id IN " +
"<foreach collection='alertIds' item='id' open='(' separator=',' close=')'>" +
"#{id}" +
"</foreach>" +
"</script>"})
int deleteByAlertIds(@Param("alertIds") List<String> alertIds);
@Select("SELECT alert_type, COUNT(*) as cnt FROM wvp_ai_alert " +
"WHERE received_at >= #{startTime} GROUP BY alert_type")
List<java.util.Map<String, Object>> 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<java.util.Map<String, Object>> statisticsByCamera(@Param("startTime") String startTime);
}

View File

@@ -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 = {"<script>" +
"SELECT * FROM wvp_ai_algo_template WHERE 1=1 " +
"<if test='algoCode != null'> AND algo_code=#{algoCode}</if> " +
"ORDER BY id DESC" +
"</script>"})
List<AiAlgoTemplate> queryList(@Param("algoCode") String algoCode);
}

View File

@@ -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 = {"<script>" +
"SELECT * FROM wvp_ai_config_snapshot WHERE 1=1 " +
"<if test='scopeType != null'> AND scope_type=#{scopeType}</if> " +
"<if test='scopeId != null'> AND scope_id=#{scopeId}</if> " +
"<if test='cameraId != null'> AND camera_id=#{cameraId}</if> " +
"ORDER BY version DESC" +
"</script>"})
List<AiConfigSnapshot> queryList(@Param("scopeType") String scopeType,
@Param("scopeId") String scopeId,
@Param("cameraId") String cameraId);
}

View File

@@ -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<AiEdgeDevice> 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);
}

View File

@@ -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<AiRoiAlgoBind> 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<AiRoiAlgoBind> queryByCameraId(@Param("cameraId") String cameraId);
}

View File

@@ -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<AiRoi> queryByCameraId(@Param("cameraId") String cameraId);
@Select("SELECT * FROM wvp_ai_roi WHERE camera_id=#{cameraId} ORDER BY priority DESC")
List<AiRoi> queryAllByCameraId(@Param("cameraId") String cameraId);
}