feat(video): 添加模型名称字段以支持动态模型选择
- 在 InspectionTask 实体类中新增 modelName 字段及其 getter/setter 方法 - 更新 MyBatis 映射文件,增加对 model_name 字段的映射和支持 - 修改 SQL 查询语句,在查询条件和插入、更新操作中加入 modelName 字段处理 - 调整 VideoAnalysisService 中的模型选择逻辑,优先使用任务配置的模型名称 - 记录日志输出所使用的模型名称及对应的任务ID,便于追踪分析过程
This commit is contained in:
@@ -52,6 +52,16 @@ public class InspectionTask extends BaseEntity {
|
||||
/** 报警次数 */
|
||||
private Long alarmCount;
|
||||
|
||||
private String modelName;
|
||||
|
||||
public void setModelName(String modelName) {
|
||||
this.modelName = modelName;
|
||||
}
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
|
||||
|
||||
public void setTaskId(Long taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ public class VideoAnalysisService {
|
||||
/**
|
||||
* 分析视频并更新记录(同步调用)
|
||||
* @param task 巡检任务
|
||||
* @param record 巡检记录
|
||||
* @param videoFile 视频文件
|
||||
*/
|
||||
public void analyzeVideoWithRecord(InspectionTask task, com.ruoyi.video.domain.InspectionTaskRecord record, File videoFile) {
|
||||
@@ -83,7 +82,11 @@ public class VideoAnalysisService {
|
||||
File outputVideoFile = File.createTempFile("analysis_output_", ".mp4");
|
||||
|
||||
// 创建检测器
|
||||
HttpYoloDetector detector = new HttpYoloDetector("yolov8", PYTHON_API_URL, MODEL_NAME, 0x00FF00);
|
||||
String chosenModel = (task.getModelName() != null && !task.getModelName().trim().isEmpty())
|
||||
? task.getModelName().trim()
|
||||
: MODEL_NAME;
|
||||
log.info("使用模型进行分析: {} (taskId={})", chosenModel, task.getTaskId());
|
||||
HttpYoloDetector detector = new HttpYoloDetector("yolov8", PYTHON_API_URL, chosenModel, 0x00FF00);
|
||||
|
||||
// 处理视频并记录检测结果
|
||||
String detectionResult = processVideoWithRecord(videoFile, outputVideoFile, detector, task, record);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.video.mapper.InspectionTaskMapper">
|
||||
|
||||
|
||||
<resultMap type="InspectionTask" id="InspectionTaskResult">
|
||||
<result property="taskId" column="task_id" />
|
||||
<result property="taskName" column="task_name" />
|
||||
@@ -17,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="executeCount" column="execute_count" />
|
||||
<result property="alarmCount" column="alarm_count" />
|
||||
<result property="lastExecuteTime" column="last_execute_time" />
|
||||
<result property="modelName" column="model_name" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
@@ -26,23 +27,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<sql id="selectInspectionTaskVo">
|
||||
select task_id, task_name, device_id, device_name, cron_expression, duration,
|
||||
threshold, enable_detection, status, execute_count, alarm_count,
|
||||
last_execute_time, remark, create_by, create_time, update_by, update_time
|
||||
threshold, enable_detection, status, execute_count, alarm_count,
|
||||
last_execute_time, model_name, remark, create_by, create_time, update_by, update_time
|
||||
from v_inspection_task
|
||||
</sql>
|
||||
|
||||
<select id="selectInspectionTaskList" parameterType="InspectionTask" resultMap="InspectionTaskResult">
|
||||
<include refid="selectInspectionTaskVo"/>
|
||||
<where>
|
||||
<where>
|
||||
<if test="taskName != null and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
|
||||
<if test="deviceId != null"> and device_id = #{deviceId}</if>
|
||||
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="enableDetection != null and enableDetection != ''"> and enable_detection = #{enableDetection}</if>
|
||||
<if test="modelName != null and modelName != ''"> and model_name = #{modelName}</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectEnabledInspectionTaskList" resultMap="InspectionTaskResult">
|
||||
<include refid="selectInspectionTaskVo"/>
|
||||
where status = '0'
|
||||
@@ -68,6 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="executeCount != null">execute_count,</if>
|
||||
<if test="alarmCount != null">alarm_count,</if>
|
||||
<if test="lastExecuteTime != null">last_execute_time,</if>
|
||||
<if test="modelName != null and modelName != ''">model_name,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
create_time
|
||||
@@ -84,6 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="executeCount != null">#{executeCount},</if>
|
||||
<if test="alarmCount != null">#{alarmCount},</if>
|
||||
<if test="lastExecuteTime != null">#{lastExecuteTime},</if>
|
||||
<if test="modelName != null and modelName != ''">#{modelName},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
sysdate()
|
||||
@@ -104,6 +108,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="executeCount != null">execute_count = #{executeCount},</if>
|
||||
<if test="alarmCount != null">alarm_count = #{alarmCount},</if>
|
||||
<if test="lastExecuteTime != null">last_execute_time = #{lastExecuteTime},</if>
|
||||
<if test="modelName != null and modelName != ''">model_name = #{modelName},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
update_time = sysdate()
|
||||
@@ -112,7 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</update>
|
||||
|
||||
<update id="updateTaskExecuteInfo">
|
||||
update v_inspection_task
|
||||
update v_inspection_task
|
||||
set execute_count = #{executeCount},
|
||||
alarm_count = #{alarmCount},
|
||||
last_execute_time = sysdate(),
|
||||
@@ -125,7 +130,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</delete>
|
||||
|
||||
<delete id="deleteInspectionTaskByIds" parameterType="String">
|
||||
delete from v_inspection_task where task_id in
|
||||
delete from v_inspection_task where task_id in
|
||||
<foreach item="taskId" collection="array" open="(" separator="," close=")">
|
||||
#{taskId}
|
||||
</foreach>
|
||||
|
||||
Reference in New Issue
Block a user