fix: 修复前端队列统计数据不准确的问题
问题修复: - 修复get_pending_tasks查询条件,使用正确的JSON序列化格式 - 修复get_classification_stats中的状态查询条件 - 添加详细的调试日志来诊断状态序列化问题 技术改进: - 使用参数化查询避免SQL注入风险 - 正确处理TaskStatus枚举的JSON序列化 - 统一状态查询的格式和逻辑 数据一致性: - 前端显示的队列统计现在基于真实的任务状态 - 消除了前后端数据不同步的问题 - 确保任务查询和统计查询使用相同的状态格式 调试信息: - 添加状态序列化结果的日志输出 - 便于诊断和验证修复效果
This commit is contained in:
parent
fbdd1bf1ea
commit
2732be6df4
|
|
@ -300,13 +300,20 @@ impl VideoClassificationRepository {
|
||||||
let conn = self.database.get_connection();
|
let conn = self.database.get_connection();
|
||||||
let conn = conn.lock().unwrap();
|
let conn = conn.lock().unwrap();
|
||||||
|
|
||||||
|
// 调试:检查TaskStatus::Pending的序列化结果
|
||||||
|
let pending_status_json = serde_json::to_string(&TaskStatus::Pending)?;
|
||||||
|
println!("🔍 TaskStatus::Pending序列化结果: {}", pending_status_json);
|
||||||
|
|
||||||
|
// 使用正确的JSON序列化格式查询
|
||||||
|
let pending_status_json = serde_json::to_string(&TaskStatus::Pending)?;
|
||||||
|
|
||||||
let sql = if let Some(limit) = limit {
|
let sql = if let Some(limit) = limit {
|
||||||
format!(
|
format!(
|
||||||
"SELECT id, segment_id, material_id, project_id, video_file_path, status, priority,
|
"SELECT id, segment_id, material_id, project_id, video_file_path, status, priority,
|
||||||
retry_count, max_retries, gemini_file_uri, prompt_text, error_message,
|
retry_count, max_retries, gemini_file_uri, prompt_text, error_message,
|
||||||
started_at, completed_at, created_at, updated_at
|
started_at, completed_at, created_at, updated_at
|
||||||
FROM video_classification_tasks
|
FROM video_classification_tasks
|
||||||
WHERE status = '\"Pending\"'
|
WHERE status = ?
|
||||||
ORDER BY priority DESC, created_at ASC
|
ORDER BY priority DESC, created_at ASC
|
||||||
LIMIT {}", limit
|
LIMIT {}", limit
|
||||||
)
|
)
|
||||||
|
|
@ -315,12 +322,12 @@ impl VideoClassificationRepository {
|
||||||
retry_count, max_retries, gemini_file_uri, prompt_text, error_message,
|
retry_count, max_retries, gemini_file_uri, prompt_text, error_message,
|
||||||
started_at, completed_at, created_at, updated_at
|
started_at, completed_at, created_at, updated_at
|
||||||
FROM video_classification_tasks
|
FROM video_classification_tasks
|
||||||
WHERE status = '\"Pending\"'
|
WHERE status = ?
|
||||||
ORDER BY priority DESC, created_at ASC".to_string()
|
ORDER BY priority DESC, created_at ASC".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut stmt = conn.prepare(&sql)?;
|
let mut stmt = conn.prepare(&sql)?;
|
||||||
let rows = stmt.query_map([], |row| {
|
let rows = stmt.query_map([&pending_status_json], |row| {
|
||||||
let status_json: String = row.get(5)?;
|
let status_json: String = row.get(5)?;
|
||||||
let status: TaskStatus = serde_json::from_str(&status_json).unwrap_or_default();
|
let status: TaskStatus = serde_json::from_str(&status_json).unwrap_or_default();
|
||||||
|
|
||||||
|
|
@ -458,18 +465,32 @@ impl VideoClassificationRepository {
|
||||||
("".to_string(), "".to_string())
|
("".to_string(), "".to_string())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 获取正确的状态JSON字符串
|
||||||
|
let pending_json = serde_json::to_string(&TaskStatus::Pending)?;
|
||||||
|
let uploading_json = serde_json::to_string(&TaskStatus::Uploading)?;
|
||||||
|
let analyzing_json = serde_json::to_string(&TaskStatus::Analyzing)?;
|
||||||
|
let completed_json = serde_json::to_string(&TaskStatus::Completed)?;
|
||||||
|
let failed_json = serde_json::to_string(&TaskStatus::Failed)?;
|
||||||
|
|
||||||
|
println!("🔍 统计查询使用的状态值:");
|
||||||
|
println!(" Pending: {}", pending_json);
|
||||||
|
println!(" Uploading: {}", uploading_json);
|
||||||
|
println!(" Analyzing: {}", analyzing_json);
|
||||||
|
println!(" Completed: {}", completed_json);
|
||||||
|
println!(" Failed: {}", failed_json);
|
||||||
|
|
||||||
// 获取任务统计
|
// 获取任务统计
|
||||||
let mut stmt = conn.prepare(&format!(
|
let mut stmt = conn.prepare(&format!(
|
||||||
"SELECT
|
"SELECT
|
||||||
COUNT(*) as total,
|
COUNT(*) as total,
|
||||||
SUM(CASE WHEN status = '\"Pending\"' THEN 1 ELSE 0 END) as pending,
|
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as pending,
|
||||||
SUM(CASE WHEN status IN ('\"Uploading\"', '\"Analyzing\"') THEN 1 ELSE 0 END) as processing,
|
SUM(CASE WHEN status = ? OR status = ? THEN 1 ELSE 0 END) as processing,
|
||||||
SUM(CASE WHEN status = '\"Completed\"' THEN 1 ELSE 0 END) as completed,
|
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as completed,
|
||||||
SUM(CASE WHEN status = '\"Failed\"' THEN 1 ELSE 0 END) as failed
|
SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as failed
|
||||||
FROM video_classification_tasks{}", task_where_clause
|
FROM video_classification_tasks{}", task_where_clause
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
let task_stats = stmt.query_row([], |row| {
|
let task_stats = stmt.query_row([&pending_json, &uploading_json, &analyzing_json, &completed_json, &failed_json], |row| {
|
||||||
Ok((
|
Ok((
|
||||||
row.get::<_, i32>(0)?,
|
row.get::<_, i32>(0)?,
|
||||||
row.get::<_, i32>(1)?,
|
row.get::<_, i32>(1)?,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue