fix(note):优化笔记内容更新逻辑
- 修改查询笔记内容 UUID 的注释表述 - 当笔记内容为空时,删除对应的 K-V 存储 - 若从无内容更新为有内容,重新生成内容 UUID - 调用 K-V 服务保存或删除笔记内容 - 更新失败时抛出业务异常以回滚事务
This commit is contained in:
@@ -369,14 +369,14 @@ public class NoteServiceImpl extends ServiceImpl<NoteDOMapper, NoteDO> implement
|
||||
LOCAL_CACHE.invalidate(noteId);
|
||||
|
||||
// 笔记内容更新
|
||||
// 查询笔记内容对应的UUID
|
||||
// 查询此篇笔记内容对应的 UUID
|
||||
NoteDO noteDO1 = this.getById(noteId);
|
||||
String contentUuid = noteDO1.getContentUuid();
|
||||
|
||||
// 笔记内容是否更新成功
|
||||
boolean isUpdateContentSuccess = false;
|
||||
if (StringUtils.isNotBlank(contentUuid)){
|
||||
// 若笔记内容为空则删除kv存储
|
||||
if (StringUtils.isBlank(content)) {
|
||||
// 若笔记内容为空,则删除 K-V 存储
|
||||
isUpdateContentSuccess = keyValueRpcService.deleteNoteContent(contentUuid);
|
||||
} else {
|
||||
// 若将无内容的笔记,更新为了有内容的笔记,需要重新生成 UUID
|
||||
@@ -384,9 +384,12 @@ public class NoteServiceImpl extends ServiceImpl<NoteDOMapper, NoteDO> implement
|
||||
// 调用 K-V 更新短文本
|
||||
isUpdateContentSuccess = keyValueRpcService.saveNoteContent(contentUuid, content);
|
||||
}
|
||||
|
||||
// 如果更新失败,抛出业务异常,回滚事务
|
||||
if (!isUpdateContentSuccess) {
|
||||
throw new ApiException(ResponseCodeEnum.NOTE_UPDATE_FAIL);
|
||||
}
|
||||
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user