From ddb5bce0a20cb94c9449c9b7db0b9589d15bac86 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 14 Nov 2023 22:37:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?vo=20=E7=AE=80=E5=8C=96=EF=BC=9Apost=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/pojo/PageParam.java | 7 +++++ .../mybatis/core/mapper/BaseMapperX.java | 6 ++++ .../controller/admin/dept/PostController.java | 24 +++++++------- .../admin/dept/vo/post/PostCreateReqVO.java | 11 ------- .../admin/dept/vo/post/PostExcelVO.java | 31 ------------------- .../admin/dept/vo/post/PostExportReqVO.java | 19 ------------ .../admin/dept/vo/post/PostListReqVO.java | 18 ----------- .../post/{PostBaseVO.java => PostReqVO.java} | 22 +++++++------ .../admin/dept/vo/post/PostRespVO.java | 29 ++++++++++++++--- .../admin/dept/vo/post/PostSimpleRespVO.java | 20 ------------ .../admin/dept/vo/post/PostUpdateReqVO.java | 18 ----------- .../system/convert/dept/PostConvert.java | 10 ++---- .../system/dal/mysql/dept/PostMapper.java | 8 ----- .../system/service/dept/PostService.java | 20 +++--------- .../system/service/dept/PostServiceImpl.java | 21 +++++-------- .../service/dept/PostServiceImplTest.java | 6 ++-- 16 files changed, 82 insertions(+), 188 deletions(-) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostCreateReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExcelVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExportReqVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostListReqVO.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/{PostBaseVO.java => PostReqVO.java} (64%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSimpleRespVO.java delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostUpdateReqVO.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java index 5738ded67..97819f993 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java @@ -15,6 +15,13 @@ public class PageParam implements Serializable { private static final Integer PAGE_NO = 1; private static final Integer PAGE_SIZE = 10; + /** + * 每页条数 - 不分页 + * + * 例如说,导出接口,可以设置 {@link #pageSize} 为 -1 不分页,查询所有数据。 + */ + public static final Integer PAGE_SIZE_NONE = -1; + @Schema(description = "页码,从 1 开始", requiredMode = Schema.RequiredMode.REQUIRED,example = "1") @NotNull(message = "页码不能为空") @Min(value = 1, message = "页码最小值为 1") diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index d70c21626..fc916cf97 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -26,6 +26,12 @@ import java.util.List; public interface BaseMapperX extends MPJBaseMapper { default PageResult selectPage(PageParam pageParam, @Param("ew") Wrapper queryWrapper) { + // 特殊:不分页,直接查询全部 + if (PageParam.PAGE_SIZE_NONE.equals(pageParam.getPageNo())) { + List list = selectList(queryWrapper); + return new PageResult<>(list, (long) list.size()); + } + // MyBatis Plus 查询 IPage mpPage = MyBatisUtils.buildPage(pageParam); selectPage(mpPage, queryWrapper); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java index 70e2d8639..e678a62c7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.system.controller.admin.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; @@ -39,16 +40,16 @@ public class PostController { @PostMapping("/create") @Operation(summary = "创建岗位") @PreAuthorize("@ss.hasPermission('system:post:create')") - public CommonResult createPost(@Valid @RequestBody PostCreateReqVO reqVO) { - Long postId = postService.createPost(reqVO); + public CommonResult createPost(@Valid @RequestBody PostReqVO createReqVO) { + Long postId = postService.createPost(createReqVO); return success(postId); } @PutMapping("/update") @Operation(summary = "修改岗位") @PreAuthorize("@ss.hasPermission('system:post:update')") - public CommonResult updatePost(@Valid @RequestBody PostUpdateReqVO reqVO) { - postService.updatePost(reqVO); + public CommonResult updatePost(@Valid @RequestBody PostReqVO updateReqVO) { + postService.updatePost(updateReqVO); return success(true); } @@ -69,13 +70,13 @@ public class PostController { } @GetMapping("/list-all-simple") - @Operation(summary = "获取岗位精简信息列表", description = "只包含被开启的岗位,主要用于前端的下拉选项") - public CommonResult> getSimplePostList() { + @Operation(summary = "获取岗位全列表", description = "只包含被开启的岗位,主要用于前端的下拉选项") + public CommonResult> getSimplePostList() { // 获得岗位列表,只要开启状态的 List list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); // 排序后,返回给前端 list.sort(Comparator.comparing(PostDO::getSort)); - return success(PostConvert.INSTANCE.convertList02(list)); + return success(PostConvert.INSTANCE.convertList(list)); } @GetMapping("/page") @@ -89,11 +90,12 @@ public class PostController { @Operation(summary = "岗位管理") @PreAuthorize("@ss.hasPermission('system:post:export')") @OperateLog(type = EXPORT) - public void export(HttpServletResponse response, @Validated PostExportReqVO reqVO) throws IOException { - List posts = postService.getPostList(reqVO); - List data = PostConvert.INSTANCE.convertList03(posts); + public void export(HttpServletResponse response, @Validated PostPageReqVO reqVO) throws IOException { + reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + PageResult pageResult = postService.getPostPage(reqVO); // 输出 - ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostExcelVO.class, data); + PageResult list = PostConvert.INSTANCE.convertPage(pageResult); + ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostRespVO.class, list.getList()); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostCreateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostCreateReqVO.java deleted file mode 100644 index b2e52e174..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostCreateReqVO.java +++ /dev/null @@ -1,11 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Schema(description = "管理后台 - 岗位创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class PostCreateReqVO extends PostBaseVO { -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExcelVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExcelVO.java deleted file mode 100644 index 0053a7895..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExcelVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; - -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import cn.iocoder.yudao.module.system.enums.DictTypeConstants; -import com.alibaba.excel.annotation.ExcelProperty; -import lombok.Data; - -/** - * 岗位 Excel 导出响应 VO - */ -@Data -public class PostExcelVO { - - @ExcelProperty("岗位序号") - private Long id; - - @ExcelProperty("岗位编码") - private String code; - - @ExcelProperty("岗位名称") - private String name; - - @ExcelProperty("岗位排序") - private Integer sort; - - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private String status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExportReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExportReqVO.java deleted file mode 100644 index 48043969a..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExportReqVO.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "管理后台 - 岗位导出 Request VO,参数和 PostExcelVO 是一致的") -@Data -public class PostExportReqVO { - - @Schema(description = "岗位编码,模糊匹配", example = "yudao") - private String code; - - @Schema(description = "岗位名称,模糊匹配", example = "芋道") - private String name; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostListReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostListReqVO.java deleted file mode 100644 index 57993c4e7..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostListReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Schema(description = "管理后台 - 岗位列表 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -public class PostListReqVO extends PostBaseVO { - - @Schema(description = "岗位名称,模糊匹配", example = "芋道") - private String name; - - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") - private Integer status; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostReqVO.java similarity index 64% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostBaseVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostReqVO.java index 974f5202d..ac8204a24 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostReqVO.java @@ -1,4 +1,7 @@ package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -6,16 +9,16 @@ 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 PostBaseVO { +public class PostReqVO { - @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主") + @Schema(description = "岗位编号", example = "1024") + private Long id; + + @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小土豆") @NotBlank(message = "岗位名称不能为空") - @Size(max = 50, message = "岗位名称长度不能超过50个字符") + @Size(max = 50, message = "岗位名称长度不能超过 50 个字符") private String name; @Schema(description = "岗位编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") @@ -27,10 +30,11 @@ public class PostBaseVO { @NotNull(message = "显示顺序不能为空") private Integer sort; - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(CommonStatusEnum.class) private Integer status; @Schema(description = "备注", example = "快乐的备注") private String remark; -} +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java index db39fff88..d4c659786 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java @@ -1,20 +1,41 @@ package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; +import com.alibaba.excel.annotation.ExcelProperty; 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 PostRespVO extends PostBaseVO { +public class PostRespVO { @Schema(description = "岗位序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("岗位序号") private Long id; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") + @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小土豆") + @ExcelProperty("岗位名称") + private String name; + + @Schema(description = "岗位编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao") + @ExcelProperty("岗位编码") + private String code; + + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("岗位排序") + private Integer sort; + + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @DictFormat(DictTypeConstants.COMMON_STATUS) + private Integer status; + + @Schema(description = "备注", example = "快乐的备注") + private String remark; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSimpleRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSimpleRespVO.java deleted file mode 100644 index a4698df16..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSimpleRespVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Schema(description = "管理后台 - 岗位精简信息 Response VO") -@Data -@NoArgsConstructor -@AllArgsConstructor -public class PostSimpleRespVO { - - @Schema(description = "岗位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - - @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - private String name; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostUpdateReqVO.java deleted file mode 100644 index c17685a71..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostUpdateReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; - -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 PostUpdateReqVO extends PostBaseVO { - - @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/dept/PostConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java index 86a548edb..8b6c28f1b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java @@ -13,16 +13,12 @@ public interface PostConvert { PostConvert INSTANCE = Mappers.getMapper(PostConvert.class); - List convertList02(List list); + List convertList(List list); PageResult convertPage(PageResult page); - PostRespVO convert(PostDO id); + PostRespVO convert(PostDO bean); - PostDO convert(PostCreateReqVO bean); - - PostDO convert(PostUpdateReqVO reqVO); - - List convertList03(List list); + PostDO convert(PostReqVO bean); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java index ba062a2c0..e05c38c7e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import org.apache.ibatis.annotations.Mapper; @@ -28,13 +27,6 @@ public interface PostMapper extends BaseMapperX { .orderByDesc(PostDO::getId)); } - default List selectList(PostExportReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(PostDO::getCode, reqVO.getCode()) - .likeIfPresent(PostDO::getName, reqVO.getName()) - .eqIfPresent(PostDO::getStatus, reqVO.getStatus())); - } - default PostDO selectByName(String name) { return selectOne(PostDO::getName, name); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java index c1b84c011..88c8b0fbd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java @@ -2,10 +2,8 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import org.springframework.lang.Nullable; @@ -24,17 +22,17 @@ public interface PostService { /** * 创建岗位 * - * @param reqVO 岗位信息 + * @param createReqVO 岗位信息 * @return 岗位编号 */ - Long createPost(PostCreateReqVO reqVO); + Long createPost(PostReqVO createReqVO); /** * 更新岗位 * - * @param reqVO 岗位信息 + * @param updateReqVO 岗位信息 */ - void updatePost(PostUpdateReqVO reqVO); + void updatePost(PostReqVO updateReqVO); /** * 删除岗位信息 @@ -70,14 +68,6 @@ public interface PostService { */ PageResult getPostPage(PostPageReqVO reqVO); - /** - * 获得岗位列表 - * - * @param reqVO 查询条件 - * @return 部门列表 - */ - List getPostList(PostExportReqVO reqVO); - /** * 获得岗位信息 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java index 3266a0c92..44031ac3c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java @@ -3,10 +3,8 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; import cn.iocoder.yudao.module.system.convert.dept.PostConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; @@ -35,23 +33,23 @@ public class PostServiceImpl implements PostService { private PostMapper postMapper; @Override - public Long createPost(PostCreateReqVO reqVO) { + public Long createPost(PostReqVO createReqVO) { // 校验正确性 - validatePostForCreateOrUpdate(null, reqVO.getName(), reqVO.getCode()); + validatePostForCreateOrUpdate(null, createReqVO.getName(), createReqVO.getCode()); // 插入岗位 - PostDO post = PostConvert.INSTANCE.convert(reqVO); + PostDO post = PostConvert.INSTANCE.convert(createReqVO); postMapper.insert(post); return post.getId(); } @Override - public void updatePost(PostUpdateReqVO reqVO) { + public void updatePost(PostReqVO updateReqVO) { // 校验正确性 - validatePostForCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode()); + validatePostForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getName(), updateReqVO.getCode()); // 更新岗位 - PostDO updateObj = PostConvert.INSTANCE.convert(reqVO); + PostDO updateObj = PostConvert.INSTANCE.convert(updateReqVO); postMapper.updateById(updateObj); } @@ -119,11 +117,6 @@ public class PostServiceImpl implements PostService { return postMapper.selectPage(reqVO); } - @Override - public List getPostList(PostExportReqVO reqVO) { - return postMapper.selectList(reqVO); - } - @Override public PostDO getPost(Long id) { return postMapper.selectById(id); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java index 87c44b346..6e497585b 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO; @@ -44,7 +44,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { @Test public void testCreatePost_success() { // 准备参数 - PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class, + PostReqVO reqVO = randomPojo(PostReqVO.class, o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); // 调用 Long postId = postService.createPost(reqVO); @@ -103,7 +103,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { PostDO postDO = randomPostDO(); postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 // 准备参数 - PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class, + PostReqVO reqVO = randomPojo(PostReqVO.class, // 模拟 name 重复 o -> o.setName(postDO.getName())); assertServiceException(() -> postService.createPost(reqVO), POST_NAME_DUPLICATE); From 5e6e02e4f4900d5be2415e5875905475c98c7466 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 15 Nov 2023 09:19:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?vo=20=E7=AE=80=E5=8C=96=EF=BC=9A=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20BeanUtils=20=E6=9B=BF=E4=BB=A3=20mapstruct=20?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/object/BeanUtils.java | 37 +++++++++++++++++++ .../controller/admin/dept/PostController.java | 30 ++++++++------- .../{PostReqVO.java => PostSaveReqVO.java} | 2 +- .../system/convert/dept/PostConvert.java | 24 ------------ .../system/service/dept/PostService.java | 6 +-- .../system/service/dept/PostServiceImpl.java | 12 +++--- .../service/dept/PostServiceImplTest.java | 36 +++--------------- 7 files changed, 69 insertions(+), 78 deletions(-) create mode 100644 yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/object/BeanUtils.java rename yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/{PostReqVO.java => PostSaveReqVO.java} (98%) delete mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/object/BeanUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/object/BeanUtils.java new file mode 100644 index 000000000..e14572a7f --- /dev/null +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/object/BeanUtils.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.framework.common.util.object; + +import cn.hutool.core.bean.BeanUtil; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; + +import java.util.List; + +/** + * Bean 工具类 + * + * 1. 默认使用 {@link cn.hutool.core.bean.BeanUtil} 作为实现类,虽然不同 bean 工具的性能有差别,但是对绝大多数同学的项目,不用在意这点性能 + * 2. 针对复杂的对象转换,可以搜参考 AuthConvert 实现,通过 mapstruct + default 配合实现 + * + * @author 芋道源码 + */ +public class BeanUtils { + + public static T toBean(Object source, Class targetClass) { + return BeanUtil.toBean(source, targetClass); + } + + public static List toBean(List source, Class targetType) { + if (source == null) { + return null; + } + return CollectionUtils.convertList(source, s -> toBean(s, targetType)); + } + + public static PageResult toBean(PageResult source, Class targetType) { + if (source == null) { + return null; + } + return new PageResult<>(toBean(source.getList(), targetType), source.getTotal()); + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java index e678a62c7..0f22fda4f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java @@ -4,15 +4,17 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.*; -import cn.iocoder.yudao.module.system.convert.dept.PostConvert; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import cn.iocoder.yudao.module.system.service.dept.PostService; -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.*; @@ -40,7 +42,7 @@ public class PostController { @PostMapping("/create") @Operation(summary = "创建岗位") @PreAuthorize("@ss.hasPermission('system:post:create')") - public CommonResult createPost(@Valid @RequestBody PostReqVO createReqVO) { + public CommonResult createPost(@Valid @RequestBody PostSaveReqVO createReqVO) { Long postId = postService.createPost(createReqVO); return success(postId); } @@ -48,7 +50,7 @@ public class PostController { @PutMapping("/update") @Operation(summary = "修改岗位") @PreAuthorize("@ss.hasPermission('system:post:update')") - public CommonResult updatePost(@Valid @RequestBody PostReqVO updateReqVO) { + public CommonResult updatePost(@Valid @RequestBody PostSaveReqVO updateReqVO) { postService.updatePost(updateReqVO); return success(true); } @@ -66,7 +68,8 @@ public class PostController { @Parameter(name = "id", description = "岗位编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:post:query')") public CommonResult getPost(@RequestParam("id") Long id) { - return success(PostConvert.INSTANCE.convert(postService.getPost(id))); + PostDO post = postService.getPost(id); + return success(BeanUtils.toBean(post, PostRespVO.class)); } @GetMapping("/list-all-simple") @@ -76,14 +79,15 @@ public class PostController { List list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); // 排序后,返回给前端 list.sort(Comparator.comparing(PostDO::getSort)); - return success(PostConvert.INSTANCE.convertList(list)); + return success(BeanUtils.toBean(list, PostRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得岗位分页列表") @PreAuthorize("@ss.hasPermission('system:post:query')") - public CommonResult> getPostPage(@Validated PostPageReqVO reqVO) { - return success(PostConvert.INSTANCE.convertPage(postService.getPostPage(reqVO))); + public CommonResult> getPostPage(@Validated PostPageReqVO pageReqVO) { + PageResult pageResult = postService.getPostPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, PostRespVO.class)); } @GetMapping("/export") @@ -92,10 +96,10 @@ public class PostController { @OperateLog(type = EXPORT) public void export(HttpServletResponse response, @Validated PostPageReqVO reqVO) throws IOException { reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - PageResult pageResult = postService.getPostPage(reqVO); + List list = postService.getPostPage(reqVO).getList(); // 输出 - PageResult list = PostConvert.INSTANCE.convertPage(pageResult); - ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostRespVO.class, list.getList()); + ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostRespVO.class, + BeanUtils.toBean(list, PostRespVO.class)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSaveReqVO.java similarity index 98% rename from yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostReqVO.java rename to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSaveReqVO.java index ac8204a24..b8d3c24cd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSaveReqVO.java @@ -11,7 +11,7 @@ import javax.validation.constraints.Size; @Schema(description = "管理后台 - 岗位创建/修改 Request VO") @Data -public class PostReqVO { +public class PostSaveReqVO { @Schema(description = "岗位编号", example = "1024") private Long id; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java deleted file mode 100644 index 8b6c28f1b..000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.system.convert.dept; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.*; -import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -import java.util.List; - -@Mapper -public interface PostConvert { - - PostConvert INSTANCE = Mappers.getMapper(PostConvert.class); - - List convertList(List list); - - PageResult convertPage(PageResult page); - - PostRespVO convert(PostDO bean); - - PostDO convert(PostReqVO bean); - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java index 88c8b0fbd..73068e234 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import org.springframework.lang.Nullable; @@ -25,14 +25,14 @@ public interface PostService { * @param createReqVO 岗位信息 * @return 岗位编号 */ - Long createPost(PostReqVO createReqVO); + Long createPost(PostSaveReqVO createReqVO); /** * 更新岗位 * * @param updateReqVO 岗位信息 */ - void updatePost(PostReqVO updateReqVO); + void updatePost(PostSaveReqVO updateReqVO); /** * 删除岗位信息 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java index 44031ac3c..560a8bc8f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java @@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.system.service.dept; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; -import cn.iocoder.yudao.module.system.convert.dept.PostConvert; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; import org.springframework.stereotype.Service; @@ -33,23 +33,23 @@ public class PostServiceImpl implements PostService { private PostMapper postMapper; @Override - public Long createPost(PostReqVO createReqVO) { + public Long createPost(PostSaveReqVO createReqVO) { // 校验正确性 validatePostForCreateOrUpdate(null, createReqVO.getName(), createReqVO.getCode()); // 插入岗位 - PostDO post = PostConvert.INSTANCE.convert(createReqVO); + PostDO post = BeanUtils.toBean(createReqVO, PostDO.class); postMapper.insert(post); return post.getId(); } @Override - public void updatePost(PostReqVO updateReqVO) { + public void updatePost(PostSaveReqVO updateReqVO) { // 校验正确性 validatePostForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getName(), updateReqVO.getCode()); // 更新岗位 - PostDO updateObj = PostConvert.INSTANCE.convert(updateReqVO); + PostDO updateObj = BeanUtils.toBean(updateReqVO, PostDO.class); postMapper.updateById(updateObj); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java index 6e497585b..6d117fddc 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO; +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; import org.junit.jupiter.api.Test; @@ -44,7 +42,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { @Test public void testCreatePost_success() { // 准备参数 - PostReqVO reqVO = randomPojo(PostReqVO.class, + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); // 调用 Long postId = postService.createPost(reqVO); @@ -62,7 +60,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { PostDO postDO = randomPostDO(); postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 // 准备参数 - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> { + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, o -> { // 设置更新的 ID o.setId(postDO.getId()); o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); @@ -103,7 +101,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { PostDO postDO = randomPostDO(); postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 // 准备参数 - PostReqVO reqVO = randomPojo(PostReqVO.class, + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, // 模拟 name 重复 o -> o.setName(postDO.getName())); assertServiceException(() -> postService.createPost(reqVO), POST_NAME_DUPLICATE); @@ -118,7 +116,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { PostDO codePostDO = randomPostDO(); postMapper.insert(codePostDO); // 准备参数 - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> { + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, o -> { // 设置更新的 ID o.setId(postDO.getId()); // 模拟 code 重复 @@ -154,30 +152,6 @@ public class PostServiceImplTest extends BaseDbUnitTest { assertPojoEquals(postDO, pageResult.getList().get(0)); } - @Test - public void testGetPostList_export() { - // mock 数据 - PostDO postDO = randomPojo(PostDO.class, o -> { - o.setName("码仔"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - }); - postMapper.insert(postDO); - // 测试 name 不匹配 - postMapper.insert(cloneIgnoreId(postDO, o -> o.setName("程序员"))); - // 测试 status 不匹配 - postMapper.insert(cloneIgnoreId(postDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 准备参数 - PostExportReqVO reqVO = new PostExportReqVO(); - reqVO.setName("码"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - - // 调用 - List list = postService.getPostList(reqVO); - // 断言 - assertEquals(1, list.size()); - assertPojoEquals(postDO, list.get(0)); - } - @Test public void testGetPostList() { // mock 数据