diff --git a/apps/desktop/src-tauri/src/business/services/video_classification_service.rs b/apps/desktop/src-tauri/src/business/services/video_classification_service.rs index 06f669e..97d3e4d 100644 --- a/apps/desktop/src-tauri/src/business/services/video_classification_service.rs +++ b/apps/desktop/src-tauri/src/business/services/video_classification_service.rs @@ -274,7 +274,20 @@ impl VideoClassificationService { // 移动文件 FileSystemService::move_file(&segment.file_path, target_path.to_str().unwrap())?; - println!("视频文件已移动到分类文件夹: {} -> {}", segment.file_path, target_path.display()); + println!("✅ 视频文件已移动到分类文件夹: {} -> {}", segment.file_path, target_path.display()); + + // 更新片段的文件路径 + let new_path = target_path.to_str().unwrap().to_string(); + match self.material_repo.update_segment_file_path(&record.segment_id, &new_path).await { + Ok(()) => { + println!("✅ 片段路径已更新: {}", new_path); + } + Err(e) => { + println!("⚠️ 更新片段路径失败: {}", e); + // 注意:文件已经移动,但数据库更新失败 + // 这种情况下应该考虑回滚文件移动或者记录错误 + } + } Ok(()) } diff --git a/apps/desktop/src-tauri/src/data/repositories/material_repository.rs b/apps/desktop/src-tauri/src/data/repositories/material_repository.rs index 530d5f2..63b5e24 100644 --- a/apps/desktop/src-tauri/src/data/repositories/material_repository.rs +++ b/apps/desktop/src-tauri/src/data/repositories/material_repository.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use rusqlite::{Connection, Row}; +use rusqlite::{Connection, Row, params}; use std::sync::{Arc, Mutex}; use crate::data::models::material::{ Material, MaterialSegment, MaterialType, ProcessingStatus, @@ -492,6 +492,22 @@ impl MaterialRepository { } } + /// 更新片段的文件路径 + pub async fn update_segment_file_path(&self, segment_id: &str, new_file_path: &str) -> Result<()> { + let conn = self.connection.lock().unwrap(); + + let updated_rows = conn.execute( + "UPDATE video_segments SET file_path = ?, updated_at = datetime('now') WHERE id = ?", + params![new_file_path, segment_id] + )?; + + if updated_rows == 0 { + return Err(anyhow::anyhow!("片段不存在或更新失败: {}", segment_id)); + } + + Ok(()) + } + /// 根据片段ID获取片段信息 pub async fn get_segment_by_id(&self, segment_id: &str) -> Result> { let conn = self.connection.lock().unwrap();