feat(qianduan): 优化笔记功能和图片处理
- 新增批量删除图片接口和功能- 实现笔记中图片的上传和删除 - 优化笔记保存时的图片处理逻辑 -调整分组展示和Markdown文件加载方式
This commit is contained in:
@@ -5,8 +5,28 @@ import com.test.bijihoudaun.entity.Grouping;
|
||||
import java.util.List;
|
||||
|
||||
public interface GroupingService {
|
||||
/**
|
||||
* 创建分组
|
||||
* @param grouping
|
||||
* @return
|
||||
*/
|
||||
Grouping createGrouping(Grouping grouping);
|
||||
List<Grouping> getAllGroupings();
|
||||
|
||||
/**
|
||||
* 获取所有分组
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
List<Grouping> getAllGroupings(Long parentId);
|
||||
/**
|
||||
* 更新分组名称
|
||||
* @param grouping
|
||||
* @return
|
||||
*/
|
||||
Grouping updateGrouping(Grouping grouping);
|
||||
/**
|
||||
* 删除分组
|
||||
* @param id
|
||||
*/
|
||||
void deleteGrouping(Long id);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,11 @@ import java.util.List;
|
||||
public interface ImageService extends IService<Image> {
|
||||
/**
|
||||
* 上传图片
|
||||
* @param markdownId Markdown文件ID(可选)
|
||||
* @param file 图片文件
|
||||
* @return 上传的图片对象
|
||||
* @throws IOException 文件操作异常
|
||||
*/
|
||||
Image uploadImage(Long markdownId, MultipartFile file) throws IOException;
|
||||
Image uploadImage(MultipartFile file) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
@@ -24,14 +23,6 @@ public interface ImageService extends IService<Image> {
|
||||
*/
|
||||
boolean deleteImage(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Markdown文件关联的图片
|
||||
* @param markdownId Markdown文件ID
|
||||
* @return 图片列表
|
||||
*/
|
||||
List<Image> getMarkdownImages(Long markdownId);
|
||||
|
||||
/**
|
||||
* 根据URL删除图片
|
||||
* @param url
|
||||
@@ -40,10 +31,9 @@ public interface ImageService extends IService<Image> {
|
||||
boolean deleteImageByUrl(String url);
|
||||
|
||||
/**
|
||||
* 根据URL批量更新图片ID
|
||||
* @param list
|
||||
* @param markdownId
|
||||
* 根据URL批量删除图片
|
||||
* @param urls
|
||||
* @return
|
||||
*/
|
||||
boolean updateImageId(List<String> list, Long markdownId);
|
||||
boolean deleteImageByUrls(List<String> urls);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.test.bijihoudaun.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.entity.Grouping;
|
||||
import com.test.bijihoudaun.mapper.GroupingMapper;
|
||||
import com.test.bijihoudaun.service.GroupingService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@@ -13,6 +15,10 @@ public class GroupingServiceImpl
|
||||
extends ServiceImpl<GroupingMapper, Grouping>
|
||||
implements GroupingService {
|
||||
|
||||
@Resource
|
||||
private GroupingMapper groupingMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Grouping createGrouping(Grouping grouping) {
|
||||
this.save(grouping);
|
||||
@@ -20,8 +26,10 @@ public class GroupingServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Grouping> getAllGroupings() {
|
||||
return this.list();
|
||||
public List<Grouping> getAllGroupings(Long parentId) {
|
||||
// return groupingMapper.selectList(new LambdaQueryWrapper<Grouping>()
|
||||
// .eq(Grouping::getParentId, parentId));
|
||||
return groupingMapper.selectList(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ImageServiceImpl
|
||||
private ImageMapper imageMapper;
|
||||
|
||||
@Override
|
||||
public Image uploadImage(Long markdownId, MultipartFile file) throws IOException {
|
||||
public Image uploadImage( MultipartFile file) throws IOException {
|
||||
// 创建上传目录
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
if (!Files.exists(uploadPath)) {
|
||||
@@ -51,7 +51,6 @@ public class ImageServiceImpl
|
||||
|
||||
// 创建图片实体
|
||||
Image image = new Image();
|
||||
image.setMarkdownId(markdownId);
|
||||
image.setOriginalName(originalFilename);
|
||||
image.setStoredName(storedName);
|
||||
image.setUrl("/uploads/" + storedName);
|
||||
@@ -82,14 +81,6 @@ public class ImageServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Image> getMarkdownImages(Long markdownId) {
|
||||
QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("markdown_id", markdownId)
|
||||
.orderByDesc("created_at");
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteImageByUrl(String url) {
|
||||
Image image = imageMapper.selectOne(new QueryWrapper<Image>().eq("url", url));
|
||||
@@ -108,17 +99,15 @@ public class ImageServiceImpl
|
||||
throw new RuntimeException("删除图片失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateImageId(List<String> list, Long markdownId) {
|
||||
if (CollUtil.isEmpty( list)) {
|
||||
public boolean deleteImageByUrls(List<String> urls) {
|
||||
if (CollUtil.isEmpty(urls)) {
|
||||
return false;
|
||||
}
|
||||
for (String url : list) {
|
||||
for (String url : urls) {
|
||||
Image image = imageMapper.selectOne(new QueryWrapper<Image>().eq("url", url));
|
||||
if (image != null) {
|
||||
image.setMarkdownId(markdownId);
|
||||
this.updateById(image);
|
||||
this.deleteImageByUrl(url);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user