From 4cb264cc320d4721eca815db98370883c848611d Mon Sep 17 00:00:00 2001 From: imeepos Date: Mon, 14 Jul 2025 16:02:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6=20=E7=A7=BB=E5=8A=A8=E5=88=B0=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E4=BD=8D=E7=BD=AE=E5=90=8E=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=AF=B9=E5=BA=94=E5=AD=97=E6=AE=B5=E6=9C=AA=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/video_classification_service.rs | 15 ++++++++++++++- .../data/repositories/material_repository.rs | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) 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();