feat(service): 增加 Markdown 文件分组名称字段
- 在 MarkdownFileVO 类中添加 groupingName 字段 - 修改 getFilesByGroupingId 和 getRecentFiles 方法返回 MarkdownFileVO 列表- 在前端 HomePage 组件中显示分组名称 - 优化后端 SQL 查询,减少不必要的查询次数
This commit is contained in:
@@ -2,6 +2,7 @@ package com.test.bijihoudaun.controller;
|
||||
|
||||
import com.test.bijihoudaun.common.response.R;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.entity.MarkdownFileVO;
|
||||
import com.test.bijihoudaun.service.MarkdownFileService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -71,8 +72,8 @@ public class MarkdownController {
|
||||
|
||||
@Operation(summary = "根据分组ID获取Markdown文件")
|
||||
@GetMapping("/grouping/{groupingId}")
|
||||
public R<List<MarkdownFile>> getFilesByGroupingId(@PathVariable String groupingId) {
|
||||
List<MarkdownFile> files = markdownFileService.getFilesByGroupingId(groupingId);
|
||||
public R<List<MarkdownFileVO>> getFilesByGroupingId(@PathVariable String groupingId) {
|
||||
List<MarkdownFileVO> files = markdownFileService.getFilesByGroupingId(groupingId);
|
||||
return R.success(files);
|
||||
}
|
||||
|
||||
@@ -97,8 +98,8 @@ public class MarkdownController {
|
||||
|
||||
@Operation(summary = "获取最近更新的笔记")
|
||||
@GetMapping("/recent")
|
||||
public R<List<MarkdownFile>> getRecentFiles() {
|
||||
List<MarkdownFile> files = markdownFileService.getRecentFiles(12);
|
||||
public R<List<MarkdownFileVO>> getRecentFiles() {
|
||||
List<MarkdownFileVO> files = markdownFileService.getRecentFiles(12);
|
||||
return R.success(files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.test.bijihoudaun.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MarkdownFileVO extends MarkdownFile {
|
||||
private String groupingName;
|
||||
}
|
||||
@@ -2,10 +2,27 @@ package com.test.bijihoudaun.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.entity.MarkdownFileVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface MarkdownFileMapper extends BaseMapper<MarkdownFile> {
|
||||
// 自定义方法:根据用户ID获取文件列表
|
||||
// List<MarkdownFile> findByUserId(Integer userId);
|
||||
|
||||
@Select("SELECT mf.*, g.grouping as groupingName " +
|
||||
"FROM markdown_file mf " +
|
||||
"LEFT JOIN grouping g ON mf.grouping_id = g.id " +
|
||||
"ORDER BY mf.updated_at DESC " +
|
||||
"LIMIT #{limit}")
|
||||
List<MarkdownFileVO> selectRecentWithGrouping(@Param("limit") int limit);
|
||||
|
||||
@Select("SELECT mf.*, g.grouping as groupingName " +
|
||||
"FROM markdown_file mf " +
|
||||
"LEFT JOIN grouping g ON mf.grouping_id = g.id " +
|
||||
"WHERE mf.grouping_id = #{groupingId} " +
|
||||
"ORDER BY mf.updated_at DESC")
|
||||
List<MarkdownFileVO> selectByGroupingIdWithGrouping(@Param("groupingId") String groupingId);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.test.bijihoudaun.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.entity.MarkdownFileVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,7 +27,7 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
* @param groupingId 分组ID
|
||||
* @return 文件列表
|
||||
*/
|
||||
List<MarkdownFile> getFilesByGroupingId(String groupingId);
|
||||
List<MarkdownFileVO> getFilesByGroupingId(String groupingId);
|
||||
|
||||
/**
|
||||
* 删除Markdown文件
|
||||
@@ -63,5 +64,5 @@ public interface MarkdownFileService extends IService<MarkdownFile> {
|
||||
* @param limit 数量
|
||||
* @return 文件列表
|
||||
*/
|
||||
List<MarkdownFile> getRecentFiles(int limit);
|
||||
List<MarkdownFileVO> getRecentFiles(int limit);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.test.bijihoudaun.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||
import com.test.bijihoudaun.entity.MarkdownFileVO;
|
||||
import com.test.bijihoudaun.mapper.MarkdownFileMapper;
|
||||
import com.test.bijihoudaun.service.MarkdownFileService;
|
||||
import com.test.bijihoudaun.util.SnowflakeIdGenerator;
|
||||
@@ -46,11 +46,8 @@ public class MarkdownFileServiceImpl
|
||||
|
||||
|
||||
@Override
|
||||
public List<MarkdownFile> getFilesByGroupingId(String groupingId) {
|
||||
QueryWrapper<MarkdownFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("grouping_id", groupingId)
|
||||
.orderByDesc("updated_at");
|
||||
return this.list(queryWrapper);
|
||||
public List<MarkdownFileVO> getFilesByGroupingId(String groupingId) {
|
||||
return markdownFileMapper.selectByGroupingIdWithGrouping(groupingId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,10 +85,7 @@ public class MarkdownFileServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkdownFile> getRecentFiles(int limit) {
|
||||
Page<MarkdownFile> page = new Page<>(1, limit);
|
||||
QueryWrapper<MarkdownFile> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.orderByDesc("updated_at");
|
||||
return this.page(page, queryWrapper).getRecords();
|
||||
public List<MarkdownFileVO> getRecentFiles(int limit) {
|
||||
return markdownFileMapper.selectRecentWithGrouping(limit);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user