Commit 5eb5472dec6314e5aaaf1a5361b153ebd16bcaf2
1 parent
b77b6322
🔧 简化 notice 模块的 VO
Showing
9 changed files
with
58 additions
and
101 deletions
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; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | 8 | import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; | |
| 9 | 9 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; |
| 10 | 10 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeRespVO; |
| 11 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; | |
| 12 | -import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; | |
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; | |
| 13 | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 14 | 13 | import cn.iocoder.yudao.module.system.service.notice.NoticeService; |
| 15 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 16 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 17 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 18 | 17 | import org.springframework.security.access.prepost.PreAuthorize; |
| 19 | 18 | import org.springframework.validation.annotation.Validated; |
| 20 | 19 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -39,16 +38,16 @@ public class NoticeController { |
| 39 | 38 | @PostMapping("/create") |
| 40 | 39 | @Operation(summary = "创建通知公告") |
| 41 | 40 | @PreAuthorize("@ss.hasPermission('system:notice:create')") |
| 42 | - public CommonResult<Long> createNotice(@Valid @RequestBody NoticeCreateReqVO reqVO) { | |
| 43 | - Long noticeId = noticeService.createNotice(reqVO); | |
| 41 | + public CommonResult<Long> createNotice(@Valid @RequestBody NoticeSaveReqVO createReqVO) { | |
| 42 | + Long noticeId = noticeService.createNotice(createReqVO); | |
| 44 | 43 | return success(noticeId); |
| 45 | 44 | } |
| 46 | 45 | |
| 47 | 46 | @PutMapping("/update") |
| 48 | 47 | @Operation(summary = "修改通知公告") |
| 49 | 48 | @PreAuthorize("@ss.hasPermission('system:notice:update')") |
| 50 | - public CommonResult<Boolean> updateNotice(@Valid @RequestBody NoticeUpdateReqVO reqVO) { | |
| 51 | - noticeService.updateNotice(reqVO); | |
| 49 | + public CommonResult<Boolean> updateNotice(@Valid @RequestBody NoticeSaveReqVO updateReqVO) { | |
| 50 | + noticeService.updateNotice(updateReqVO); | |
| 52 | 51 | return success(true); |
| 53 | 52 | } |
| 54 | 53 | |
| ... | ... | @@ -64,8 +63,9 @@ public class NoticeController { |
| 64 | 63 | @GetMapping("/page") |
| 65 | 64 | @Operation(summary = "获取通知公告列表") |
| 66 | 65 | @PreAuthorize("@ss.hasPermission('system:notice:query')") |
| 67 | - public CommonResult<PageResult<NoticeRespVO>> getNoticePage(@Validated NoticePageReqVO reqVO) { | |
| 68 | - return success(NoticeConvert.INSTANCE.convertPage(noticeService.getNoticePage(reqVO))); | |
| 66 | + public CommonResult<PageResult<NoticeRespVO>> getNoticePage(@Validated NoticePageReqVO pageReqVO) { | |
| 67 | + PageResult<NoticeDO> pageResult = noticeService.getNoticePage(pageReqVO); | |
| 68 | + return success(BeanUtils.toBean(pageResult, NoticeRespVO.class)); | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | @GetMapping("/get") |
| ... | ... | @@ -73,7 +73,8 @@ public class NoticeController { |
| 73 | 73 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 74 | 74 | @PreAuthorize("@ss.hasPermission('system:notice:query')") |
| 75 | 75 | public CommonResult<NoticeRespVO> getNotice(@RequestParam("id") Long id) { |
| 76 | - return success(NoticeConvert.INSTANCE.convert(noticeService.getNotice(id))); | |
| 76 | + NoticeDO notice = noticeService.getNotice(id); | |
| 77 | + return success(BeanUtils.toBean(notice, NoticeRespVO.class)); | |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | @PostMapping("/push") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.notice.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | - | |
| 7 | -@Schema(description = "管理后台 - 通知公告创建 Request VO") | |
| 8 | -@Data | |
| 9 | -@EqualsAndHashCode(callSuper = true) | |
| 10 | -public class NoticeCreateReqVO extends NoticeBaseVO { | |
| 11 | -} |
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; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | 5 | |
| 7 | 6 | import java.time.LocalDateTime; |
| 8 | 7 | |
| 9 | 8 | @Schema(description = "管理后台 - 通知公告信息 Response VO") |
| 10 | 9 | @Data |
| 11 | -@EqualsAndHashCode(callSuper = true) | |
| 12 | -public class NoticeRespVO extends NoticeBaseVO { | |
| 10 | +public class NoticeRespVO { | |
| 13 | 11 | |
| 14 | 12 | @Schema(description = "通知公告序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 15 | 13 | private Long id; |
| 16 | 14 | |
| 15 | + @Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") | |
| 16 | + private String title; | |
| 17 | + | |
| 18 | + @Schema(description = "公告类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") | |
| 19 | + private Integer type; | |
| 20 | + | |
| 21 | + @Schema(description = "公告内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "半生编码") | |
| 22 | + private String content; | |
| 23 | + | |
| 24 | + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 25 | + private Integer status; | |
| 26 | + | |
| 17 | 27 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") |
| 18 | 28 | private LocalDateTime createTime; |
| 19 | 29 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeBaseVO.java renamed to 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; |
| 7 | 7 | import javax.validation.constraints.NotNull; |
| 8 | 8 | import javax.validation.constraints.Size; |
| 9 | 9 | |
| 10 | -/** | |
| 11 | - * 通知公告 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 12 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 13 | - */ | |
| 10 | +@Schema(description = "管理后台 - 通知公告创建/修改 Request VO") | |
| 14 | 11 | @Data |
| 15 | -public class NoticeBaseVO { | |
| 12 | +public class NoticeSaveReqVO { | |
| 13 | + | |
| 14 | + @Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 15 | + @NotNull(message = "岗位公告编号不能为空") | |
| 16 | + private Long id; | |
| 16 | 17 | |
| 17 | 18 | @Schema(description = "公告标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") |
| 18 | 19 | @NotBlank(message = "公告标题不能为空") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notice/vo/NoticeUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.notice.vo; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | - | |
| 7 | -import javax.validation.constraints.NotNull; | |
| 8 | - | |
| 9 | -@Schema(description = "管理后台 - 岗位公告更新 Request VO") | |
| 10 | -@Data | |
| 11 | -@EqualsAndHashCode(callSuper = true) | |
| 12 | -public class NoticeUpdateReqVO extends NoticeBaseVO { | |
| 13 | - | |
| 14 | - @Schema(description = "岗位公告编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 15 | - @NotNull(message = "岗位公告编号不能为空") | |
| 16 | - private Long id; | |
| 17 | - | |
| 18 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/notice/NoticeConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.notice; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeRespVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; | |
| 8 | -import org.mapstruct.Mapper; | |
| 9 | -import org.mapstruct.factory.Mappers; | |
| 10 | - | |
| 11 | -@Mapper | |
| 12 | -public interface NoticeConvert { | |
| 13 | - | |
| 14 | - NoticeConvert INSTANCE = Mappers.getMapper(NoticeConvert.class); | |
| 15 | - | |
| 16 | - PageResult<NoticeRespVO> convertPage(PageResult<NoticeDO> page); | |
| 17 | - | |
| 18 | - NoticeRespVO convert(NoticeDO bean); | |
| 19 | - | |
| 20 | - NoticeDO convert(NoticeUpdateReqVO bean); | |
| 21 | - | |
| 22 | - NoticeDO convert(NoticeCreateReqVO bean); | |
| 23 | - | |
| 24 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeService.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.notice; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; | |
| 5 | 4 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 8 | 7 | |
| 9 | 8 | /** |
| ... | ... | @@ -12,29 +11,29 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 12 | 11 | public interface NoticeService { |
| 13 | 12 | |
| 14 | 13 | /** |
| 15 | - * 创建岗位公告公告 | |
| 14 | + * 创建通知公告 | |
| 16 | 15 | * |
| 17 | - * @param reqVO 岗位公告公告信息 | |
| 18 | - * @return 岗位公告公告编号 | |
| 16 | + * @param createReqVO 通知公告 | |
| 17 | + * @return 编号 | |
| 19 | 18 | */ |
| 20 | - Long createNotice(NoticeCreateReqVO reqVO); | |
| 19 | + Long createNotice(NoticeSaveReqVO createReqVO); | |
| 21 | 20 | |
| 22 | 21 | /** |
| 23 | - * 更新岗位公告公告 | |
| 22 | + * 更新通知公告 | |
| 24 | 23 | * |
| 25 | - * @param reqVO 岗位公告公告信息 | |
| 24 | + * @param reqVO 通知公告 | |
| 26 | 25 | */ |
| 27 | - void updateNotice(NoticeUpdateReqVO reqVO); | |
| 26 | + void updateNotice(NoticeSaveReqVO reqVO); | |
| 28 | 27 | |
| 29 | 28 | /** |
| 30 | - * 删除岗位公告公告信息 | |
| 29 | + * 删除通知公告 | |
| 31 | 30 | * |
| 32 | - * @param id 岗位公告公告编号 | |
| 31 | + * @param id 编号 | |
| 33 | 32 | */ |
| 34 | 33 | void deleteNotice(Long id); |
| 35 | 34 | |
| 36 | 35 | /** |
| 37 | - * 获得岗位公告公告分页列表 | |
| 36 | + * 获得通知公告分页列表 | |
| 38 | 37 | * |
| 39 | 38 | * @param reqVO 分页条件 |
| 40 | 39 | * @return 部门分页列表 |
| ... | ... | @@ -42,10 +41,10 @@ public interface NoticeService { |
| 42 | 41 | PageResult<NoticeDO> getNoticePage(NoticePageReqVO reqVO); |
| 43 | 42 | |
| 44 | 43 | /** |
| 45 | - * 获得岗位公告公告信息 | |
| 44 | + * 获得通知公告 | |
| 46 | 45 | * |
| 47 | - * @param id 岗位公告公告编号 | |
| 48 | - * @return 岗位公告公告信息 | |
| 46 | + * @param id 编号 | |
| 47 | + * @return 通知公告 | |
| 49 | 48 | */ |
| 50 | 49 | NoticeDO getNotice(Long id); |
| 51 | 50 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.notice; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | 5 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.convert.notice.NoticeConvert; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; | |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; |
| 10 | 9 | import com.google.common.annotations.VisibleForTesting; |
| ... | ... | @@ -27,18 +26,18 @@ public class NoticeServiceImpl implements NoticeService { |
| 27 | 26 | private NoticeMapper noticeMapper; |
| 28 | 27 | |
| 29 | 28 | @Override |
| 30 | - public Long createNotice(NoticeCreateReqVO reqVO) { | |
| 31 | - NoticeDO notice = NoticeConvert.INSTANCE.convert(reqVO); | |
| 29 | + public Long createNotice(NoticeSaveReqVO createReqVO) { | |
| 30 | + NoticeDO notice = BeanUtils.toBean(createReqVO, NoticeDO.class); | |
| 32 | 31 | noticeMapper.insert(notice); |
| 33 | 32 | return notice.getId(); |
| 34 | 33 | } |
| 35 | 34 | |
| 36 | 35 | @Override |
| 37 | - public void updateNotice(NoticeUpdateReqVO reqVO) { | |
| 36 | + public void updateNotice(NoticeSaveReqVO updateReqVO) { | |
| 38 | 37 | // 校验是否存在 |
| 39 | - validateNoticeExists(reqVO.getId()); | |
| 38 | + validateNoticeExists(updateReqVO.getId()); | |
| 40 | 39 | // 更新通知公告 |
| 41 | - NoticeDO updateObj = NoticeConvert.INSTANCE.convert(reqVO); | |
| 40 | + NoticeDO updateObj = BeanUtils.toBean(updateReqVO, NoticeDO.class); | |
| 42 | 41 | noticeMapper.updateById(updateObj); |
| 43 | 42 | } |
| 44 | 43 | ... | ... |
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; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeCreateReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticePageReqVO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeUpdateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.system.controller.admin.notice.vo.NoticeSaveReqVO; | |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.notice.NoticeDO; |
| 10 | 9 | import cn.iocoder.yudao.module.system.dal.mysql.notice.NoticeMapper; |
| 11 | 10 | import org.junit.jupiter.api.Test; |
| ... | ... | @@ -72,14 +71,15 @@ class NoticeServiceImplTest extends BaseDbUnitTest { |
| 72 | 71 | @Test |
| 73 | 72 | public void testCreateNotice_success() { |
| 74 | 73 | // 准备参数 |
| 75 | - NoticeCreateReqVO reqVO = randomPojo(NoticeCreateReqVO.class); | |
| 74 | + NoticeSaveReqVO reqVO = randomPojo(NoticeSaveReqVO.class) | |
| 75 | + .setId(null); // 避免 id 被赋值 | |
| 76 | 76 | |
| 77 | 77 | // 调用 |
| 78 | 78 | Long noticeId = noticeService.createNotice(reqVO); |
| 79 | 79 | // 校验插入属性是否正确 |
| 80 | 80 | assertNotNull(noticeId); |
| 81 | 81 | NoticeDO notice = noticeMapper.selectById(noticeId); |
| 82 | - assertPojoEquals(reqVO, notice); | |
| 82 | + assertPojoEquals(reqVO, notice, "id"); | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | @Test |
| ... | ... | @@ -89,7 +89,7 @@ class NoticeServiceImplTest extends BaseDbUnitTest { |
| 89 | 89 | noticeMapper.insert(dbNoticeDO); |
| 90 | 90 | |
| 91 | 91 | // 准备更新参数 |
| 92 | - NoticeUpdateReqVO reqVO = randomPojo(NoticeUpdateReqVO.class, o -> o.setId(dbNoticeDO.getId())); | |
| 92 | + NoticeSaveReqVO reqVO = randomPojo(NoticeSaveReqVO.class, o -> o.setId(dbNoticeDO.getId())); | |
| 93 | 93 | |
| 94 | 94 | // 更新 |
| 95 | 95 | noticeService.updateNotice(reqVO); | ... | ... |