feat: 优化分类选择器与笔记移动功能

This commit is contained in:
ikmkj
2026-03-03 16:57:10 +08:00
parent 392cc52fd2
commit a99696ff7a
10 changed files with 366 additions and 52 deletions

View File

@@ -23,6 +23,7 @@ public class MarkdownFile implements Serializable {
private Long id;
@Schema(description = "分组表id",implementation = Long.class)
@JsonFormat(shape = JsonFormat.Shape.STRING)
@TableField("grouping_id")
private Long groupingId;

View File

@@ -9,4 +9,7 @@ import lombok.EqualsAndHashCode;
public class MarkdownFileVO extends MarkdownFile {
@TableField(exist = false)
private String groupingName;
@TableField(exist = false)
private Long groupingId;
}

View File

@@ -15,7 +15,7 @@ import org.apache.ibatis.annotations.Update;
@Mapper
public interface MarkdownFileMapper extends BaseMapper<MarkdownFile> {
@Select("SELECT mf.id, mf.grouping_id, mf.`title`, mf.file_name, mf.`content`, mf.created_at, mf.updated_at, mf.is_deleted, mf.deleted_at, mf.deleted_by, mf.is_private, g.`grouping` as groupingName " +
@Select("SELECT mf.id, mf.grouping_id as groupingId, mf.`title`, mf.file_name, mf.`content`, mf.created_at, mf.updated_at, mf.is_deleted, mf.deleted_at, mf.deleted_by, mf.is_private, g.`grouping` as groupingName " +
"FROM `markdown_file` mf " +
"LEFT JOIN `grouping` g ON mf.grouping_id = g.id " +
"WHERE mf.is_deleted = 0 " +
@@ -23,7 +23,7 @@ public interface MarkdownFileMapper extends BaseMapper<MarkdownFile> {
"LIMIT #{limit}")
List<MarkdownFileVO> selectRecentWithGrouping(@Param("limit") int limit);
@Select("SELECT mf.id, mf.grouping_id, mf.`title`, mf.file_name, mf.`content`, mf.created_at, mf.updated_at, mf.is_deleted, mf.deleted_at, mf.deleted_by, mf.is_private, g.`grouping` as groupingName " +
@Select("SELECT mf.id, mf.grouping_id as groupingId, mf.`title`, mf.file_name, mf.`content`, mf.created_at, mf.updated_at, mf.is_deleted, mf.deleted_at, mf.deleted_by, mf.is_private, g.`grouping` as groupingName " +
"FROM `markdown_file` mf " +
"LEFT JOIN `grouping` g ON mf.grouping_id = g.id " +
"WHERE mf.grouping_id = #{groupingId} AND mf.is_deleted = 0 " +
@@ -51,7 +51,7 @@ public interface MarkdownFileMapper extends BaseMapper<MarkdownFile> {
@Select("SELECT id, grouping_id, `title`, file_name, `content`, created_at, updated_at, is_deleted, deleted_at, deleted_by, is_private FROM `markdown_file` WHERE is_deleted = 0")
List<Integer> findAllIds();
@Select("SELECT mf.id, mf.grouping_id, mf.`title`, mf.file_name, mf.`content`, mf.created_at, mf.updated_at, mf.is_deleted, mf.deleted_at, mf.deleted_by, mf.is_private, g.`grouping` as groupingName " +
@Select("SELECT mf.id, mf.grouping_id as groupingId, mf.`title`, mf.file_name, mf.`content`, mf.created_at, mf.updated_at, mf.is_deleted, mf.deleted_at, mf.deleted_by, mf.is_private, g.`grouping` as groupingName " +
"FROM `markdown_file` mf " +
"LEFT JOIN `grouping` g ON mf.grouping_id = g.id " +
"WHERE mf.id = #{id} AND mf.is_deleted = 0")

View File

@@ -47,7 +47,32 @@ public class MarkdownFileServiceImpl
this.save(markdownFile);
id=l;
} else {
this.updateById(markdownFile);
MarkdownFile existingFile = this.getById(markdownFile.getId());
if (existingFile != null) {
LambdaUpdateWrapper<MarkdownFile> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(MarkdownFile::getId, markdownFile.getId())
.set(MarkdownFile::getUpdatedAt, new Date());
if (markdownFile.getTitle() != null) {
updateWrapper.set(MarkdownFile::getTitle, markdownFile.getTitle());
}
if (markdownFile.getContent() != null) {
updateWrapper.set(MarkdownFile::getContent, markdownFile.getContent());
}
if (markdownFile.getGroupingId() != null) {
updateWrapper.set(MarkdownFile::getGroupingId, markdownFile.getGroupingId());
}
if (markdownFile.getFileName() != null) {
updateWrapper.set(MarkdownFile::getFileName, markdownFile.getFileName());
}
if (markdownFile.getIsPrivate() != null) {
updateWrapper.set(MarkdownFile::getIsPrivate, markdownFile.getIsPrivate());
}
this.update(updateWrapper);
} else {
this.updateById(markdownFile);
}
id=markdownFile.getId();
}
@@ -56,6 +81,10 @@ public class MarkdownFileServiceImpl
MarkdownFileVO result = markdownFileMapper.selectByIdWithGrouping(id);
if (result != null) {
// 确保 groupingId 被正确设置
if (result.getGroupingId() == null && markdownFile.getGroupingId() != null) {
result.setGroupingId(markdownFile.getGroupingId());
}
return result;
}
return markdownFile;