diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/entity/TrashItemVo.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/entity/TrashItemVo.java index 91c8ad7..425f408 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/entity/TrashItemVo.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/entity/TrashItemVo.java @@ -1,5 +1,6 @@ package com.test.bijihoudaun.entity; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -19,6 +20,7 @@ public class TrashItemVo { private String type; @Schema(description = "删除时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date deletedAt; @Schema(description = "删除者ID") diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/GroupingMapper.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/GroupingMapper.java index ee642fe..a1a6837 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/GroupingMapper.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/GroupingMapper.java @@ -2,8 +2,13 @@ package com.test.bijihoudaun.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.test.bijihoudaun.entity.Grouping; +import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; import java.util.List; @@ -12,4 +17,10 @@ public interface GroupingMapper extends BaseMapper { @Select("SELECT * FROM grouping WHERE is_deleted = 1") List selectDeleted(); + + @Delete("DELETE FROM grouping WHERE id = #{id}") + void physicalDeleteById(@Param("id") Long id); + + @Update("UPDATE grouping SET is_deleted = 0, deleted_at = NULL, deleted_by = NULL WHERE id = #{id}") + void restoreById(@Param("id") Long id); } diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/MarkdownFileMapper.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/MarkdownFileMapper.java index 32efec9..0c86114 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/MarkdownFileMapper.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/mapper/MarkdownFileMapper.java @@ -9,6 +9,9 @@ import org.apache.ibatis.annotations.Select; import java.util.List; +import org.apache.ibatis.annotations.Delete; +import org.apache.ibatis.annotations.Update; + @Mapper public interface MarkdownFileMapper extends BaseMapper { @@ -29,4 +32,13 @@ public interface MarkdownFileMapper extends BaseMapper { @Select("SELECT * FROM markdown_file WHERE is_deleted = 1") List selectDeleted(); + + @Delete("DELETE FROM markdown_file WHERE id = #{id}") + void physicalDeleteById(@Param("id") Long id); + + @Delete("DELETE FROM markdown_file WHERE grouping_id = #{groupingId}") + void physicalDeleteByGroupingId(@Param("groupingId") Long groupingId); + + @Update("UPDATE markdown_file SET is_deleted = 0, deleted_at = NULL, deleted_by = NULL WHERE id = #{id}") + void restoreById(@Param("id") Long id); } diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/TrashServiceImpl.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/TrashServiceImpl.java index 06ef803..2abb930 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/TrashServiceImpl.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/TrashServiceImpl.java @@ -1,6 +1,7 @@ package com.test.bijihoudaun.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.test.bijihoudaun.entity.Grouping; import com.test.bijihoudaun.entity.MarkdownFile; import com.test.bijihoudaun.entity.TrashItemVo; @@ -62,19 +63,9 @@ public class TrashServiceImpl implements TrashService { @Transactional public void restoreItem(String id, String type) { if ("note".equals(type)) { - MarkdownFile file = new MarkdownFile(); - file.setId(Long.parseLong(id)); - file.setIsDeleted(0); - file.setDeletedAt(null); - file.setDeletedBy(null); - markdownFileMapper.updateById(file); + markdownFileMapper.restoreById(Long.parseLong(id)); } else if ("group".equals(type)) { - Grouping group = new Grouping(); - group.setId(Long.parseLong(id)); - group.setIsDeleted(0); - group.setDeletedAt(null); - group.setDeletedBy(null); - groupingMapper.updateById(group); + groupingMapper.restoreById(Long.parseLong(id)); } } @@ -82,11 +73,11 @@ public class TrashServiceImpl implements TrashService { @Transactional public void permanentlyDeleteItem(String id, String type) { if ("note".equals(type)) { - markdownFileMapper.deleteById(Long.parseLong(id)); + markdownFileMapper.physicalDeleteById(Long.parseLong(id)); } else if ("group".equals(type)) { - // 删除分组时,也删除其下的所有笔记 - groupingMapper.deleteById(Long.parseLong(id)); - markdownFileMapper.delete(new QueryWrapper().eq("grouping_id", id)); + // 永久删除分组时,也永久删除其下的所有笔记 + groupingMapper.physicalDeleteById(Long.parseLong(id)); + markdownFileMapper.physicalDeleteByGroupingId(Long.parseLong(id)); } } diff --git a/biji-qianduan/src/components/HomePage.vue b/biji-qianduan/src/components/HomePage.vue index 8d973a6..89a889a 100644 --- a/biji-qianduan/src/components/HomePage.vue +++ b/biji-qianduan/src/components/HomePage.vue @@ -639,12 +639,9 @@ const handleDeleteGroup = (group) => { try { await apiDeleteGrouping(group.id); ElMessage.success('分类已删除'); + // 删除分类后,刷新分组树并回到主视图 await fetchGroupings(); - await fetchMarkdownFiles(); - if (activeMenu.value.startsWith('group-') && activeMenu.value.endsWith(group.id)) { - activeMenu.value = 'all'; - groupMarkdownFiles.value = markdownFiles.value; - } + await resetToHomeView(); } catch (error) { ElMessage.error('删除分类失败: ' + error.message); } @@ -666,13 +663,10 @@ const deleteNote = (file) => { try { await deleteMarkdown(file.id); ElMessage.success('笔记已删除'); - selectedFile.value = null; - await fetchMarkdownFiles(); - // Optionally, refresh the current group's file list - if (activeMenu.value.startsWith('group-')) { - const groupId = activeMenu.value.split('-'); - await selectFile({ id: groupId }); - } + selectedFile.value = null; // 关闭预览 + // 刷新分组和主视图 + await fetchGroupings(); + await resetToHomeView(); } catch (error) { ElMessage.error('删除笔记失败: ' + error.message); } diff --git a/mydatabase.db b/mydatabase.db index 69dd3fd..2c30f18 100644 Binary files a/mydatabase.db and b/mydatabase.db differ