From 27710435b2585e92bc9ae5325902f5ee9160acdd Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 2 Dec 2023 20:07:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=E7=AE=80=E5=8C=96=20notice=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=20VO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/notice/NoticeController.java | 25 ++++++++-------- .../admin/notice/vo/NoticeCreateReqVO.java | 11 ------- .../admin/notice/vo/NoticeRespVO.java | 16 ++++++++-- ...NoticeBaseVO.java => NoticeSaveReqVO.java} | 11 +++---- .../admin/notice/vo/NoticeUpdateReqVO.java | 18 ------------ .../system/convert/notice/NoticeConvert.java | 24 --------------- .../system/service/notice/NoticeService.java | 29 +++++++++---------- .../service/notice/NoticeServiceImpl.java | 15 +++++----- .../service/notice/NoticeServiceImplTest.java | 10 +++---- 9 files changed, 58 insertions(+), 101 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/{NoticeBaseVO.java => NoticeSaveReqVO.java} (77%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java index 5a566702f..138f2d9ae 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/NoticeController.java @@ -4,17 +4,16 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; import cn.iocoder.yudao.module.system.service.notice.NoticeService; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -39,16 +38,16 @@ public class NoticeController { @PostMapping("/create") @Operation(summary = "创建通知公告") @PreAuthorize("@ss.hasPermission('system:notice:create')") - public CommonResult createNotice(@Valid @RequestBody NoticeCreateReqVO reqVO) { - Long noticeId = noticeService.createNotice(reqVO); + public CommonResult createNotice(@Valid @RequestBody NoticeSaveReqVO createReqVO) { + Long noticeId = noticeService.createNotice(createReqVO); return success(noticeId); } @PutMapping("/update") @Operation(summary = "修改通知公告") @PreAuthorize("@ss.hasPermission('system:notice:update')") - public CommonResult updateNotice(@Valid @RequestBody NoticeUpdateReqVO reqVO) { - noticeService.updateNotice(reqVO); + public CommonResult updateNotice(@Valid @RequestBody NoticeSaveReqVO updateReqVO) { + noticeService.updateNotice(updateReqVO); return success(true); } @@ -64,8 +63,9 @@ public class NoticeController { @GetMapping("/page") @Operation(summary = "获取通知公告列表") @PreAuthorize("@ss.hasPermission('system:notice:query')") - public CommonResult> getNoticePage(@Validated NoticePageReqVO reqVO) { - return success(NoticeConvert.INSTANCE.convertPage(noticeService.getNoticePage(reqVO))); + public CommonResult> getNoticePage(@Validated NoticePageReqVO pageReqVO) { + PageResult pageResult = noticeService.getNoticePage(pageReqVO); + return success(BeanUtils.toBean(pageResult, NoticeRespVO.class)); } @GetMapping("/get") @@ -73,7 +73,8 @@ public class NoticeController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:notice:query')") public CommonResult getNotice(@RequestParam("id") Long id) { - return success(NoticeConvert.INSTANCE.convert(noticeService.getNotice(id))); + NoticeDO notice = noticeService.getNotice(id); + return success(BeanUtils.toBean(notice, NoticeRespVO.class)); } @PostMapping("/push") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java deleted file mode 100644 index 211f4f0cf..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notice.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Schema(description = "管理后台 - 通知公告创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class NoticeCreateReqVO extends NoticeBaseVO { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java index 621c1d301..543f5881e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeRespVO.java @@ -2,18 +2,28 @@ package cn.iocoder.yudao.module.system.controller.admin.notice.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import java.time.LocalDateTime; @Schema(description = "管理后台 - 通知公告信息 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -public class NoticeRespVO extends NoticeBaseVO { +public class NoticeRespVO { @Schema(description = "通知公告序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") + private String title; + + @Schema(description = "公告类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") + private Integer type; + + @Schema(description = "公告内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "半生编码") + private String content; + + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeSaveReqVO.java similarity index 77% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeSaveReqVO.java index efac4df73..4d7e6c872 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeSaveReqVO.java @@ -7,12 +7,13 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -/** - * 通知公告 Base VO,提供给添加、修改、详细的子 VO 使用 - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 - */ +@Schema(description = "管理后台 - 通知公告创建/修改 Request VO") @Data -public class NoticeBaseVO { +public class NoticeSaveReqVO { + + @Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "岗位公告编号不能为空") + private Long id; @Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") @NotBlank(message = "公告标题不能为空") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java deleted file mode 100644 index 695bd2863..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.notice.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 岗位公告更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class NoticeUpdateReqVO extends NoticeBaseVO { - - @Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "岗位公告编号不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java deleted file mode 100644 index ad2bedec7..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.notice; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeRespVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; -import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface NoticeConvert { - - NoticeConvert INSTANCE = Mappers.getMapper(NoticeConvert.class); - - PageResult convertPage(PageResult page); - - NoticeRespVO convert(NoticeDO bean); - - NoticeDO convert(NoticeUpdateReqVO bean); - - NoticeDO convert(NoticeCreateReqVO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java index 432fe876e..c935c49b2 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java @@ -1,9 +1,8 @@ package cn.iocoder.yudao.module.system.service.notice; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; /** @@ -12,29 +11,29 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; public interface NoticeService { /** - * 创建岗位公告公告 + * 创建通知公告 * - * @param reqVO 岗位公告公告信息 - * @return 岗位公告公告编号 + * @param createReqVO 通知公告 + * @return 编号 */ - Long createNotice(NoticeCreateReqVO reqVO); + Long createNotice(NoticeSaveReqVO createReqVO); /** - * 更新岗位公告公告 + * 更新通知公告 * - * @param reqVO 岗位公告公告信息 + * @param reqVO 通知公告 */ - void updateNotice(NoticeUpdateReqVO reqVO); + void updateNotice(NoticeSaveReqVO reqVO); /** - * 删除岗位公告公告信息 + * 删除通知公告 * - * @param id 岗位公告公告编号 + * @param id 编号 */ void deleteNotice(Long id); /** - * 获得岗位公告公告分页列表 + * 获得通知公告分页列表 * * @param reqVO 分页条件 * @return 部门分页列表 @@ -42,10 +41,10 @@ public interface NoticeService { PageResult getNoticePage(NoticePageReqVO reqVO); /** - * 获得岗位公告公告信息 + * 获得通知公告 * - * @param id 岗位公告公告编号 - * @return 岗位公告公告信息 + * @param id 编号 + * @return 通知公告 */ NoticeDO getNotice(Long id); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java index 1930e64c1..f0204c3cf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java @@ -1,10 +1,9 @@ package cn.iocoder.yudao.module.system.service.notice; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; -import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; import com.google.common.annotations.VisibleForTesting; @@ -27,18 +26,18 @@ public class NoticeServiceImpl implements NoticeService { private NoticeMapper noticeMapper; @Override - public Long createNotice(NoticeCreateReqVO reqVO) { - NoticeDO notice = NoticeConvert.INSTANCE.convert(reqVO); + public Long createNotice(NoticeSaveReqVO createReqVO) { + NoticeDO notice = BeanUtils.toBean(createReqVO, NoticeDO.class); noticeMapper.insert(notice); return notice.getId(); } @Override - public void updateNotice(NoticeUpdateReqVO reqVO) { + public void updateNotice(NoticeSaveReqVO updateReqVO) { // 校验是否存在 - validateNoticeExists(reqVO.getId()); + validateNoticeExists(updateReqVO.getId()); // 更新通知公告 - NoticeDO updateObj = NoticeConvert.INSTANCE.convert(reqVO); + NoticeDO updateObj = BeanUtils.toBean(updateReqVO, NoticeDO.class); noticeMapper.updateById(updateObj); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java index b4727096a..dfde83538 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImplTest.java @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.notice; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; import org.junit.jupiter.api.Test; @@ -72,14 +71,15 @@ class NoticeServiceImplTest extends BaseDbUnitTest { @Test public void testCreateNotice_success() { // 准备参数 - NoticeCreateReqVO reqVO = randomPojo(NoticeCreateReqVO.class); + NoticeSaveReqVO reqVO = randomPojo(NoticeSaveReqVO.class) + .setId(null); // 避免 id 被赋值 // 调用 Long noticeId = noticeService.createNotice(reqVO); // 校验插入属性是否正确 assertNotNull(noticeId); NoticeDO notice = noticeMapper.selectById(noticeId); - assertPojoEquals(reqVO, notice); + assertPojoEquals(reqVO, notice, "id"); } @Test @@ -89,7 +89,7 @@ class NoticeServiceImplTest extends BaseDbUnitTest { noticeMapper.insert(dbNoticeDO); // 准备更新参数 - NoticeUpdateReqVO reqVO = randomPojo(NoticeUpdateReqVO.class, o -> o.setId(dbNoticeDO.getId())); + NoticeSaveReqVO reqVO = randomPojo(NoticeSaveReqVO.class, o -> o.setId(dbNoticeDO.getId())); // 更新 noticeService.updateNotice(reqVO);