笔记修改功能

This commit is contained in:
wxl 2025-01-08 00:36:42 +08:00
parent b4663e0b88
commit 6d78d5d672
3 changed files with 51 additions and 0 deletions

View File

@ -51,6 +51,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -507,6 +508,46 @@ public class AuthApi {
return ResultBean.success();
}
@ApiOperation(value = "创建笔记")
@ApiOperationSupport(order = 1)
@PostMapping("/api/auth/updateNote")
@OperLog(operModule = "创建笔记",operType = OperType.ADD,operDesc = "创建笔记")
@Transactional
public ResultBean updateNote(@RequestBody NoteDto noteDto) {
String authorId = String.valueOf(request.getAttribute("authorId"));
Author author = authorService.getById(authorId);
Note note = BeanUtil.copyProperties(noteDto, Note.class);
note.setAuthorId(author.getAuthorId());
note.setAuthorName(author.getAuthorName());
note.setAuthorAvatar(author.getAvatarUrl());
note.setIpAddress(IPUtils.getIpAddr(request)); // 请求IP
note.setIpRealAddress(AddressUtils.getRealAddress(note.getIpAddress()));
noteService.updateById(note);
List<String> imgs = noteDto.getImgs();
List<NoteImg> noteImgList = new ArrayList<>();
for(int i=0;i<imgs.size();i++){
NoteImg noteImg = new NoteImg();
noteImg.setAuthorId(authorId);
noteImg.setNoteId(note.getNoteId());
noteImg.setImgSort(i);
File file = fileService.selectFileByFileId(imgs.get(i));
String serverName = request.getServerName();
System.out.println(serverName);
noteImg.setImgUrl("http://" + serverName + ":" + port + file.getFilePath());
noteImgList.add(noteImg);
}
noteImgService.deleteNoteImgByNoteId(note.getNoteId());
noteImgService.saveBatch(noteImgList);
Note updateNote = noteService.getById(note.getNoteId());
updateNote.setFirstPicture(noteImgList.get(0).getImgUrl());
noteService.updateById(updateNote);
return ResultBean.success();
}
//外层倒叙 回复正序
@ApiOperation(value = "获取笔记评论")
@ApiOperationSupport(order = 1)

View File

@ -23,4 +23,5 @@ public interface NoteImgService extends IService<NoteImg> {
//笔记包含的图片-列表
List<NoteImgVo> selectNoteImgList(NoteImgDto noteImgDto);
Integer deleteNoteImgByNoteId(String noteId);
}

View File

@ -1,5 +1,7 @@
package com.dd.admin.business.noteImg.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.admin.common.model.PageFactory;
@ -33,4 +35,11 @@ public class NoteImgServiceImpl extends ServiceImpl<NoteImgMapper, NoteImg> impl
public List<NoteImgVo> selectNoteImgList(NoteImgDto noteImgDto) {
return baseMapper.selectNoteImgList(noteImgDto);
}
@Override
public Integer deleteNoteImgByNoteId(String noteId) {
LambdaUpdateWrapper<NoteImg> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(NoteImg::getNoteId, noteId);
return baseMapper.delete(updateWrapper);
}
}