From cede5282e8e9a1da232c20b3292c6ba400cb4a67 Mon Sep 17 00:00:00 2001 From: Hanserwei Date: Fri, 10 Oct 2025 18:57:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(note):=20=E6=96=B0=E5=A2=9E=E7=AC=94?= =?UTF-8?q?=E8=AE=B0=E5=8F=AF=E8=A7=81=E6=80=A7=E4=B8=8E=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加笔记仅对自己可见接口及实现逻辑 - 添加笔记置顶/取消置顶接口及实现逻辑 - 引入新的请求参数类 UpdateNoteVisibleOnlyMeReqVO 和 TopNoteReqVO - 扩展响应码枚举以支持新功能的异常处理 - 使用通配符导入优化代码结构 - 更新服务层接口定义,增加对应方法声明 --- .../note/biz/controller/NoteController.java | 17 +++-- .../note/biz/enums/ResponseCodeEnum.java | 4 +- .../note/biz/model/vo/TopNoteReqVO.java | 20 ++++++ .../vo/UpdateNoteVisibleOnlyMeReqVO.java | 18 +++++ .../hannote/note/biz/service/NoteService.java | 19 ++++-- .../biz/service/impl/NoteServiceImpl.java | 68 ++++++++++++++++--- 6 files changed, 128 insertions(+), 18 deletions(-) create mode 100644 han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/TopNoteReqVO.java create mode 100644 han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/UpdateNoteVisibleOnlyMeReqVO.java diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/controller/NoteController.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/controller/NoteController.java index 09c99d2..26741df 100644 --- a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/controller/NoteController.java +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/controller/NoteController.java @@ -2,10 +2,7 @@ package com.hanserwei.hannote.note.biz.controller; import com.hanserwei.framework.biz.operationlog.aspect.ApiOperationLog; import com.hanserwei.framework.common.response.Response; -import com.hanserwei.hannote.note.biz.model.vo.FindNoteDetailReqVO; -import com.hanserwei.hannote.note.biz.model.vo.FindNoteDetailRspVO; -import com.hanserwei.hannote.note.biz.model.vo.PublishNoteReqVO; -import com.hanserwei.hannote.note.biz.model.vo.UpdateNoteReqVO; +import com.hanserwei.hannote.note.biz.model.vo.*; import com.hanserwei.hannote.note.biz.service.NoteService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -41,4 +38,16 @@ public class NoteController { return noteService.updateNote(updateNoteReqVO); } + @PostMapping(value = "/visible/onlyme") + @ApiOperationLog(description = "笔记仅对自己可见") + public Response visibleOnlyMe(@Validated @RequestBody UpdateNoteVisibleOnlyMeReqVO updateNoteVisibleOnlyMeReqVO) { + return noteService.visibleOnlyMe(updateNoteVisibleOnlyMeReqVO); + } + + @PostMapping(value = "/top") + @ApiOperationLog(description = "置顶/取消置顶笔记") + public Response topNote(@Validated @RequestBody TopNoteReqVO topNoteReqVO) { + return noteService.topNote(topNoteReqVO); + } + } diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/ResponseCodeEnum.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/ResponseCodeEnum.java index c9b0544..0127d8e 100644 --- a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/ResponseCodeEnum.java +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/enums/ResponseCodeEnum.java @@ -18,7 +18,9 @@ public enum ResponseCodeEnum implements BaseExceptionInterface { NOTE_NOT_FOUND("NOTE-20002", "笔记不存在"), NOTE_PRIVATE("NOTE-20003", "作者已将该笔记设置为仅自己可见"), NOTE_UPDATE_FAIL("NOTE-20004", "笔记更新失败"), - TOPIC_NOT_FOUND("NOTE-20005", "话题不存在") + TOPIC_NOT_FOUND("NOTE-20005", "话题不存在"), + NOTE_CANT_VISIBLE_ONLY_ME("NOTE-20006", "此笔记无法修改为仅自己可见"), + NOTE_CANT_OPERATE("NOTE-20007", "您无法操作该笔记"), ; // 异常码 diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/TopNoteReqVO.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/TopNoteReqVO.java new file mode 100644 index 0000000..b82edb5 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/TopNoteReqVO.java @@ -0,0 +1,20 @@ +package com.hanserwei.hannote.note.biz.model.vo; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TopNoteReqVO { + + @NotNull(message = "笔记 ID 不能为空") + private Long id; + + @NotNull(message = "置顶状态不能为空") + private Boolean isTop; +} diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/UpdateNoteVisibleOnlyMeReqVO.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/UpdateNoteVisibleOnlyMeReqVO.java new file mode 100644 index 0000000..a991177 --- /dev/null +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/model/vo/UpdateNoteVisibleOnlyMeReqVO.java @@ -0,0 +1,18 @@ +package com.hanserwei.hannote.note.biz.model.vo; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class UpdateNoteVisibleOnlyMeReqVO { + + @NotNull(message = "笔记 ID 不能为空") + private Long id; + +} \ No newline at end of file diff --git a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/NoteService.java b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/NoteService.java index ca546bd..519301a 100644 --- a/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/NoteService.java +++ b/han-note-note/han-note-note-biz/src/main/java/com/hanserwei/hannote/note/biz/service/NoteService.java @@ -3,10 +3,7 @@ package com.hanserwei.hannote.note.biz.service; import com.baomidou.mybatisplus.extension.service.IService; import com.hanserwei.framework.common.response.Response; import com.hanserwei.hannote.note.biz.domain.dataobject.NoteDO; -import com.hanserwei.hannote.note.biz.model.vo.FindNoteDetailReqVO; -import com.hanserwei.hannote.note.biz.model.vo.FindNoteDetailRspVO; -import com.hanserwei.hannote.note.biz.model.vo.PublishNoteReqVO; -import com.hanserwei.hannote.note.biz.model.vo.UpdateNoteReqVO; +import com.hanserwei.hannote.note.biz.model.vo.*; public interface NoteService extends IService { @@ -31,4 +28,18 @@ public interface NoteService extends IService { */ Response updateNote(UpdateNoteReqVO updateNoteReqVO); + /** + * 笔记仅对自己可见 + * @param updateNoteVisibleOnlyMeReqVO 笔记仅对自己可见请求 + * @return 笔记仅对自己可见结果 + */ + Response visibleOnlyMe(UpdateNoteVisibleOnlyMeReqVO updateNoteVisibleOnlyMeReqVO); + + /** + * 笔记置顶 / 取消置顶 + * @param topNoteReqVO 笔记置顶 / 取消置顶请求 + * @return 笔记置顶 / 取消置顶结果 + */ + Response topNote(TopNoteReqVO topNoteReqVO); + } \ No newline at end of file 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 41d97ac..c6bdac1 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 @@ -20,10 +20,7 @@ import com.hanserwei.hannote.note.biz.enums.NoteStatusEnum; import com.hanserwei.hannote.note.biz.enums.NoteTypeEnum; import com.hanserwei.hannote.note.biz.enums.NoteVisibleEnum; import com.hanserwei.hannote.note.biz.enums.ResponseCodeEnum; -import com.hanserwei.hannote.note.biz.model.vo.FindNoteDetailReqVO; -import com.hanserwei.hannote.note.biz.model.vo.FindNoteDetailRspVO; -import com.hanserwei.hannote.note.biz.model.vo.PublishNoteReqVO; -import com.hanserwei.hannote.note.biz.model.vo.UpdateNoteReqVO; +import com.hanserwei.hannote.note.biz.model.vo.*; import com.hanserwei.hannote.note.biz.rpc.DistributedIdGeneratorRpcService; import com.hanserwei.hannote.note.biz.rpc.KeyValueRpcService; import com.hanserwei.hannote.note.biz.rpc.UserRpcService; @@ -312,7 +309,7 @@ public class NoteServiceImpl extends ServiceImpl implement NoteTypeEnum noteTypeEnum = NoteTypeEnum.valueOf(type); // 判断笔记类型,如果非图文、视频笔记,则抛出异常 - if (Objects.isNull(noteTypeEnum)){ + if (Objects.isNull(noteTypeEnum)) { throw new ApiException(ResponseCodeEnum.NOTE_TYPE_ERROR); } String imgUris = null; @@ -340,14 +337,14 @@ public class NoteServiceImpl extends ServiceImpl implement // 话题 Long topicId = updateNoteReqVO.getTopicId(); String topicName = null; - if (Objects.nonNull(topicId)){ + if (Objects.nonNull(topicId)) { TopicDO topicDO = topicDOService.getById(topicId); - if (Objects.isNull(topicDO)){ + if (Objects.isNull(topicDO)) { throw new ApiException(ResponseCodeEnum.TOPIC_NOT_FOUND); } topicName = topicDO.getName(); // 判断提交的话题是否真实存在 - if (StringUtils.isBlank(topicName)){ + if (StringUtils.isBlank(topicName)) { throw new ApiException(ResponseCodeEnum.TOPIC_NOT_FOUND); } } @@ -370,7 +367,7 @@ public class NoteServiceImpl extends ServiceImpl implement .videoUri(videoUri) .build(); boolean updateResult = this.updateById(noteDO); - if (!updateResult){ + if (!updateResult) { throw new ApiException(ResponseCodeEnum.NOTE_UPDATE_FAIL); } @@ -431,6 +428,59 @@ public class NoteServiceImpl extends ServiceImpl implement return Response.success(); } + @Override + public Response visibleOnlyMe(UpdateNoteVisibleOnlyMeReqVO updateNoteVisibleOnlyMeReqVO) { + // 笔记 ID + Long noteId = updateNoteVisibleOnlyMeReqVO.getId(); + + // 构建更新的实体类 + NoteDO noteDO = NoteDO.builder() + .id(noteId) + .visible(NoteVisibleEnum.PRIVATE.getCode()) + .updateTime(LocalDateTime.now()) + .build(); + + // 仅仅更新status为1的数据 + boolean updateResult = this.update(noteDO, new LambdaQueryWrapper<>(NoteDO.class).eq(NoteDO::getStatus, NoteStatusEnum.NORMAL.getCode())); + if (!updateResult) { + throw new ApiException(ResponseCodeEnum.NOTE_UPDATE_FAIL); + } + // 删除Redis缓存 + String noteDetailRedisKey = RedisKeyConstants.buildNoteDetailKey(noteId); + redisTemplate.delete(noteDetailRedisKey); + // 同步广播模式 MQ,将所有实例中的本地缓存都删除掉 + rocketMQTemplate.syncSend(MQConstants.TOPIC_DELETE_NOTE_LOCAL_CACHE, noteId); + log.info("====> MQ:笔记更新,本地缓存发送成功..."); + return Response.success(); + } + + @Override + public Response topNote(TopNoteReqVO topNoteReqVO) { + Long noteId = topNoteReqVO.getId(); + boolean isTop = topNoteReqVO.getIsTop(); + + //当前用户ID + Long currUserId = LoginUserContextHolder.getUserId(); + NoteDO noteDO = NoteDO.builder() + .id(noteId) + .isTop(isTop) + .updateTime(LocalDateTime.now()) + .creatorId(currUserId) // 只有笔记所有者,才能置顶/取消置顶笔记 + .build(); + boolean isUpdated = this.update(noteDO, new LambdaQueryWrapper<>(NoteDO.class).eq(NoteDO::getId, noteId).eq(NoteDO::getCreatorId, currUserId)); + if (!isUpdated) { + throw new ApiException(ResponseCodeEnum.NOTE_UPDATE_FAIL); + } + // 删除Redis缓存 + String noteDetailRedisKey = RedisKeyConstants.buildNoteDetailKey(noteId); + redisTemplate.delete(noteDetailRedisKey); + + // 同步广播模式 MQ,将所有实例中的本地缓存都删除掉 + rocketMQTemplate.syncSend(MQConstants.TOPIC_DELETE_NOTE_LOCAL_CACHE, noteId); + log.info("====> 笔记置顶更新,本地缓存发送成功..."); + return Response.success(); + } + /** * 校验笔记的可见性 *