From d00933caadb062b911b45016ebc16f02f88567ce Mon Sep 17 00:00:00 2001 From: Hanserwei Date: Thu, 9 Oct 2025 16:21:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(note):=E4=BC=98=E5=8C=96=E7=AC=94=E8=AE=B0?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改查询笔记内容 UUID 的注释表述 - 当笔记内容为空时,删除对应的 K-V 存储 - 若从无内容更新为有内容,重新生成内容 UUID - 调用 K-V 服务保存或删除笔记内容 - 更新失败时抛出业务异常以回滚事务 --- .../note/biz/service/impl/NoteServiceImpl.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/impl/NoteServiceImpl.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/impl/NoteServiceImpl.java index cc6e3d5..2bb6ea8 100644 --- a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/impl/NoteServiceImpl.java +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/impl/NoteServiceImpl.java @@ -369,24 +369,27 @@ public class NoteServiceImpl extends ServiceImpl 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 { + } else { // 若将无内容的笔记,更新为了有内容的笔记,需要重新生成 UUID contentUuid = StringUtils.isBlank(contentUuid) ? UUID.randomUUID().toString() : contentUuid; // 调用 K-V 更新短文本 isUpdateContentSuccess = keyValueRpcService.saveNoteContent(contentUuid, content); } - if (!isUpdateContentSuccess){ + + // 如果更新失败,抛出业务异常,回滚事务 + if (!isUpdateContentSuccess) { throw new ApiException(ResponseCodeEnum.NOTE_UPDATE_FAIL); } + return Response.success(); }