本文最后更新于 2026年5月29日 下午
发布通知接口的实现
发布通知接口的需求
检查通知是否存在
已发布的通知无需重复发布
更新通知状态并写入发布时间
代码实现
在 NoticeController 中添加接口
1 2 3 4 5 6 7 8 9
| @PutMapping("/{id}/publish") @PreAuthorize("@ps.hasPermission('sys:notice:publish')") @SystemLog(businessName = "发布通知") @ApiOperation(value = "发布通知接口", notes = "发布通知", response = String.class) @ApiImplicitParam(name = "id", value = "通知ID", dataType = "long", paramType = "path", required = true) public ResponseResult publishNotice(@PathVariable Long id) { return sysNoticeService.publishNotice(id); }
|
给发布通知接口放行
在 NoticeServiceImpl 中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| @Override public ResponseResult publishNotice(Long id) { SysNotice oldNotice = sysNoticeService.getById(id); if (oldNotice == null) { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "该通知不存在!"); }
if (SystemConstants.NOTICE_STATUS_PUBLISHED.equals(oldNotice.getStatus())) { return ResponseResult.okResult(); }
SysNotice notice = new SysNotice(); notice.setId(id); notice.setStatus(SystemConstants.NOTICE_STATUS_PUBLISHED); notice.setPublishTime(new Date());
boolean updated = sysNoticeService.updateById(notice); if (!updated) { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "发布通知失败"); }
return ResponseResult.okResult(); }
|
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/