File tree Expand file tree Collapse file tree
src-tauri/src/services/curd Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ impl DocumentCurd {
6666 // Ok(())
6767 // }
6868 /// 批量删除文档,同时删除文档和标签的关联关系
69- /// 由于有外键关系,所以需要先删除doc_and_tag表的关联关系 ,再删除文档
69+ /// 由于有外键关系,所以需要先删除 doc_and_tag 表的关联关系 ,再删除文档
7070 pub async fn delete_many ( ids : Vec < i32 > ) -> AppResult < ( ) > {
7171 let db = crate :: entities:: DB
7272 . get ( )
@@ -80,21 +80,33 @@ impl DocumentCurd {
8080 . into_iter ( )
8181 . map ( |doc| doc. path ) // 假设 `path` 是 Option<String>
8282 . collect ( ) ;
83+
84+ // 删除每个文档对应的笔记
85+ for doc_id in & ids {
86+ if let Err ( e) = crate :: services:: curd:: note:: NoteCurd :: delete_by_document_id ( * doc_id) . await {
87+ error ! ( "删除文档 {} 的笔记失败:{:#}" , doc_id, e) ;
88+ }
89+ }
90+
91+ // 删除文档和标签的关联关系
8392 DocAndTags :: delete_many ( )
8493 . filter ( crate :: entities:: doc_and_tag:: Column :: DocId . is_in ( ids. clone ( ) ) )
8594 . exec ( db)
8695 . await ?;
96+
97+ // 删除文档
8798 Documents :: delete_many ( )
8899 . filter ( Column :: Id . is_in ( ids. clone ( ) ) )
89100 . exec ( db)
90101 . await
91102 . map_err ( |e| Tip ( format ! ( "删除文档失败:{:#}" , e) ) ) ?;
103+
92104 // 删除本地文件
93105 for path in paths_to_delete {
94106 let file_path = get_absolute_path ( & path) ;
95107 if file_path. exists ( ) {
96108 if let Err ( e) = fs:: remove_file ( file_path) {
97- error ! ( "删除文件失败: {:#}" , e) ;
109+ error ! ( "删除文件失败: {:#}" , e) ;
98110 }
99111 }
100112 }
You can’t perform that action at this time.
0 commit comments