Commit 5e6e02e4f4900d5be2415e5875905475c98c7466
1 parent
ddb5bce0
vo 简化:使用 BeanUtils 替代 mapstruct 转换
Showing
7 changed files
with
69 additions
and
78 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/object/BeanUtils.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.common.util.object; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.bean.BeanUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Bean 工具类 | ||
| 11 | + * | ||
| 12 | + * 1. 默认使用 {@link cn.hutool.core.bean.BeanUtil} 作为实现类,虽然不同 bean 工具的性能有差别,但是对绝大多数同学的项目,不用在意这点性能 | ||
| 13 | + * 2. 针对复杂的对象转换,可以搜参考 AuthConvert 实现,通过 mapstruct + default 配合实现 | ||
| 14 | + * | ||
| 15 | + * @author 芋道源码 | ||
| 16 | + */ | ||
| 17 | +public class BeanUtils { | ||
| 18 | + | ||
| 19 | + public static <T> T toBean(Object source, Class<T> targetClass) { | ||
| 20 | + return BeanUtil.toBean(source, targetClass); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public static <S, T> List<T> toBean(List<S> source, Class<T> targetType) { | ||
| 24 | + if (source == null) { | ||
| 25 | + return null; | ||
| 26 | + } | ||
| 27 | + return CollectionUtils.convertList(source, s -> toBean(s, targetType)); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public static <S, T> PageResult<T> toBean(PageResult<S> source, Class<T> targetType) { | ||
| 31 | + if (source == null) { | ||
| 32 | + return null; | ||
| 33 | + } | ||
| 34 | + return new PageResult<>(toBean(source.getList(), targetType), source.getTotal()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | +} | ||
| 0 | \ No newline at end of file | 38 | \ No newline at end of file |
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; | @@ -4,15 +4,17 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 7 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 8 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 9 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.*; | ||
| 10 | -import cn.iocoder.yudao.module.system.convert.dept.PostConvert; | 10 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; | ||
| 12 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostRespVO; | ||
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 12 | import cn.iocoder.yudao.module.system.service.dept.PostService; | 14 | import cn.iocoder.yudao.module.system.service.dept.PostService; |
| 13 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 14 | -import io.swagger.v3.oas.annotations.Parameter; | ||
| 15 | import io.swagger.v3.oas.annotations.Operation; | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 17 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 18 | import org.springframework.web.bind.annotation.*; | 20 | import org.springframework.web.bind.annotation.*; |
| @@ -40,7 +42,7 @@ public class PostController { | @@ -40,7 +42,7 @@ public class PostController { | ||
| 40 | @PostMapping("/create") | 42 | @PostMapping("/create") |
| 41 | @Operation(summary = "创建岗位") | 43 | @Operation(summary = "创建岗位") |
| 42 | @PreAuthorize("@ss.hasPermission('system:post:create')") | 44 | @PreAuthorize("@ss.hasPermission('system:post:create')") |
| 43 | - public CommonResult<Long> createPost(@Valid @RequestBody PostReqVO createReqVO) { | 45 | + public CommonResult<Long> createPost(@Valid @RequestBody PostSaveReqVO createReqVO) { |
| 44 | Long postId = postService.createPost(createReqVO); | 46 | Long postId = postService.createPost(createReqVO); |
| 45 | return success(postId); | 47 | return success(postId); |
| 46 | } | 48 | } |
| @@ -48,7 +50,7 @@ public class PostController { | @@ -48,7 +50,7 @@ public class PostController { | ||
| 48 | @PutMapping("/update") | 50 | @PutMapping("/update") |
| 49 | @Operation(summary = "修改岗位") | 51 | @Operation(summary = "修改岗位") |
| 50 | @PreAuthorize("@ss.hasPermission('system:post:update')") | 52 | @PreAuthorize("@ss.hasPermission('system:post:update')") |
| 51 | - public CommonResult<Boolean> updatePost(@Valid @RequestBody PostReqVO updateReqVO) { | 53 | + public CommonResult<Boolean> updatePost(@Valid @RequestBody PostSaveReqVO updateReqVO) { |
| 52 | postService.updatePost(updateReqVO); | 54 | postService.updatePost(updateReqVO); |
| 53 | return success(true); | 55 | return success(true); |
| 54 | } | 56 | } |
| @@ -66,7 +68,8 @@ public class PostController { | @@ -66,7 +68,8 @@ public class PostController { | ||
| 66 | @Parameter(name = "id", description = "岗位编号", required = true, example = "1024") | 68 | @Parameter(name = "id", description = "岗位编号", required = true, example = "1024") |
| 67 | @PreAuthorize("@ss.hasPermission('system:post:query')") | 69 | @PreAuthorize("@ss.hasPermission('system:post:query')") |
| 68 | public CommonResult<PostRespVO> getPost(@RequestParam("id") Long id) { | 70 | public CommonResult<PostRespVO> getPost(@RequestParam("id") Long id) { |
| 69 | - return success(PostConvert.INSTANCE.convert(postService.getPost(id))); | 71 | + PostDO post = postService.getPost(id); |
| 72 | + return success(BeanUtils.toBean(post, PostRespVO.class)); | ||
| 70 | } | 73 | } |
| 71 | 74 | ||
| 72 | @GetMapping("/list-all-simple") | 75 | @GetMapping("/list-all-simple") |
| @@ -76,14 +79,15 @@ public class PostController { | @@ -76,14 +79,15 @@ public class PostController { | ||
| 76 | List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); | 79 | List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus())); |
| 77 | // 排序后,返回给前端 | 80 | // 排序后,返回给前端 |
| 78 | list.sort(Comparator.comparing(PostDO::getSort)); | 81 | list.sort(Comparator.comparing(PostDO::getSort)); |
| 79 | - return success(PostConvert.INSTANCE.convertList(list)); | 82 | + return success(BeanUtils.toBean(list, PostRespVO.class)); |
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | @GetMapping("/page") | 85 | @GetMapping("/page") |
| 83 | @Operation(summary = "获得岗位分页列表") | 86 | @Operation(summary = "获得岗位分页列表") |
| 84 | @PreAuthorize("@ss.hasPermission('system:post:query')") | 87 | @PreAuthorize("@ss.hasPermission('system:post:query')") |
| 85 | - public CommonResult<PageResult<PostRespVO>> getPostPage(@Validated PostPageReqVO reqVO) { | ||
| 86 | - return success(PostConvert.INSTANCE.convertPage(postService.getPostPage(reqVO))); | 88 | + public CommonResult<PageResult<PostRespVO>> getPostPage(@Validated PostPageReqVO pageReqVO) { |
| 89 | + PageResult<PostDO> pageResult = postService.getPostPage(pageReqVO); | ||
| 90 | + return success(BeanUtils.toBean(pageResult, PostRespVO.class)); | ||
| 87 | } | 91 | } |
| 88 | 92 | ||
| 89 | @GetMapping("/export") | 93 | @GetMapping("/export") |
| @@ -92,10 +96,10 @@ public class PostController { | @@ -92,10 +96,10 @@ public class PostController { | ||
| 92 | @OperateLog(type = EXPORT) | 96 | @OperateLog(type = EXPORT) |
| 93 | public void export(HttpServletResponse response, @Validated PostPageReqVO reqVO) throws IOException { | 97 | public void export(HttpServletResponse response, @Validated PostPageReqVO reqVO) throws IOException { |
| 94 | reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | 98 | reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| 95 | - PageResult<PostDO> pageResult = postService.getPostPage(reqVO); | 99 | + List<PostDO> list = postService.getPostPage(reqVO).getList(); |
| 96 | // 输出 | 100 | // 输出 |
| 97 | - PageResult<PostRespVO> list = PostConvert.INSTANCE.convertPage(pageResult); | ||
| 98 | - ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostRespVO.class, list.getList()); | 101 | + ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostRespVO.class, |
| 102 | + BeanUtils.toBean(list, PostRespVO.class)); | ||
| 99 | } | 103 | } |
| 100 | 104 | ||
| 101 | } | 105 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostReqVO.java renamed to 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; | @@ -11,7 +11,7 @@ import javax.validation.constraints.Size; | ||
| 11 | 11 | ||
| 12 | @Schema(description = "管理后台 - 岗位创建/修改 Request VO") | 12 | @Schema(description = "管理后台 - 岗位创建/修改 Request VO") |
| 13 | @Data | 13 | @Data |
| 14 | -public class PostReqVO { | 14 | +public class PostSaveReqVO { |
| 15 | 15 | ||
| 16 | @Schema(description = "岗位编号", example = "1024") | 16 | @Schema(description = "岗位编号", example = "1024") |
| 17 | private Long id; | 17 | private Long id; |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/PostConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.dept; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.*; | ||
| 5 | -import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | ||
| 6 | -import org.mapstruct.Mapper; | ||
| 7 | -import org.mapstruct.factory.Mappers; | ||
| 8 | - | ||
| 9 | -import java.util.List; | ||
| 10 | - | ||
| 11 | -@Mapper | ||
| 12 | -public interface PostConvert { | ||
| 13 | - | ||
| 14 | - PostConvert INSTANCE = Mappers.getMapper(PostConvert.class); | ||
| 15 | - | ||
| 16 | - List<PostRespVO> convertList(List<PostDO> list); | ||
| 17 | - | ||
| 18 | - PageResult<PostRespVO> convertPage(PageResult<PostDO> page); | ||
| 19 | - | ||
| 20 | - PostRespVO convert(PostDO bean); | ||
| 21 | - | ||
| 22 | - PostDO convert(PostReqVO bean); | ||
| 23 | - | ||
| 24 | -} |
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; | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.system.service.dept; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; | 6 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
| 7 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 8 | import org.springframework.lang.Nullable; | 8 | import org.springframework.lang.Nullable; |
| 9 | 9 | ||
| @@ -25,14 +25,14 @@ public interface PostService { | @@ -25,14 +25,14 @@ public interface PostService { | ||
| 25 | * @param createReqVO 岗位信息 | 25 | * @param createReqVO 岗位信息 |
| 26 | * @return 岗位编号 | 26 | * @return 岗位编号 |
| 27 | */ | 27 | */ |
| 28 | - Long createPost(PostReqVO createReqVO); | 28 | + Long createPost(PostSaveReqVO createReqVO); |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| 31 | * 更新岗位 | 31 | * 更新岗位 |
| 32 | * | 32 | * |
| 33 | * @param updateReqVO 岗位信息 | 33 | * @param updateReqVO 岗位信息 |
| 34 | */ | 34 | */ |
| 35 | - void updatePost(PostReqVO updateReqVO); | 35 | + void updatePost(PostSaveReqVO updateReqVO); |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | * 删除岗位信息 | 38 | * 删除岗位信息 |
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; | @@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.system.service.dept; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 6 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.system.convert.dept.PostConvert; | 8 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 10 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; |
| 11 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| @@ -33,23 +33,23 @@ public class PostServiceImpl implements PostService { | @@ -33,23 +33,23 @@ public class PostServiceImpl implements PostService { | ||
| 33 | private PostMapper postMapper; | 33 | private PostMapper postMapper; |
| 34 | 34 | ||
| 35 | @Override | 35 | @Override |
| 36 | - public Long createPost(PostReqVO createReqVO) { | 36 | + public Long createPost(PostSaveReqVO createReqVO) { |
| 37 | // 校验正确性 | 37 | // 校验正确性 |
| 38 | validatePostForCreateOrUpdate(null, createReqVO.getName(), createReqVO.getCode()); | 38 | validatePostForCreateOrUpdate(null, createReqVO.getName(), createReqVO.getCode()); |
| 39 | 39 | ||
| 40 | // 插入岗位 | 40 | // 插入岗位 |
| 41 | - PostDO post = PostConvert.INSTANCE.convert(createReqVO); | 41 | + PostDO post = BeanUtils.toBean(createReqVO, PostDO.class); |
| 42 | postMapper.insert(post); | 42 | postMapper.insert(post); |
| 43 | return post.getId(); | 43 | return post.getId(); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | @Override | 46 | @Override |
| 47 | - public void updatePost(PostReqVO updateReqVO) { | 47 | + public void updatePost(PostSaveReqVO updateReqVO) { |
| 48 | // 校验正确性 | 48 | // 校验正确性 |
| 49 | validatePostForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getName(), updateReqVO.getCode()); | 49 | validatePostForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getName(), updateReqVO.getCode()); |
| 50 | 50 | ||
| 51 | // 更新岗位 | 51 | // 更新岗位 |
| 52 | - PostDO updateObj = PostConvert.INSTANCE.convert(updateReqVO); | 52 | + PostDO updateObj = BeanUtils.toBean(updateReqVO, PostDO.class); |
| 53 | postMapper.updateById(updateObj); | 53 | postMapper.updateById(updateObj); |
| 54 | } | 54 | } |
| 55 | 55 |
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; | @@ -4,10 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; | ||
| 9 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; | 7 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO; | 8 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO; |
| 11 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; |
| 12 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; | 10 | import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper; |
| 13 | import org.junit.jupiter.api.Test; | 11 | import org.junit.jupiter.api.Test; |
| @@ -44,7 +42,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | @@ -44,7 +42,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | ||
| 44 | @Test | 42 | @Test |
| 45 | public void testCreatePost_success() { | 43 | public void testCreatePost_success() { |
| 46 | // 准备参数 | 44 | // 准备参数 |
| 47 | - PostReqVO reqVO = randomPojo(PostReqVO.class, | 45 | + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, |
| 48 | o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); | 46 | o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); |
| 49 | // 调用 | 47 | // 调用 |
| 50 | Long postId = postService.createPost(reqVO); | 48 | Long postId = postService.createPost(reqVO); |
| @@ -62,7 +60,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | @@ -62,7 +60,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | ||
| 62 | PostDO postDO = randomPostDO(); | 60 | PostDO postDO = randomPostDO(); |
| 63 | postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 | 61 | postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 |
| 64 | // 准备参数 | 62 | // 准备参数 |
| 65 | - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> { | 63 | + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, o -> { |
| 66 | // 设置更新的 ID | 64 | // 设置更新的 ID |
| 67 | o.setId(postDO.getId()); | 65 | o.setId(postDO.getId()); |
| 68 | o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); | 66 | o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); |
| @@ -103,7 +101,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | @@ -103,7 +101,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | ||
| 103 | PostDO postDO = randomPostDO(); | 101 | PostDO postDO = randomPostDO(); |
| 104 | postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 | 102 | postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据 |
| 105 | // 准备参数 | 103 | // 准备参数 |
| 106 | - PostReqVO reqVO = randomPojo(PostReqVO.class, | 104 | + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, |
| 107 | // 模拟 name 重复 | 105 | // 模拟 name 重复 |
| 108 | o -> o.setName(postDO.getName())); | 106 | o -> o.setName(postDO.getName())); |
| 109 | assertServiceException(() -> postService.createPost(reqVO), POST_NAME_DUPLICATE); | 107 | assertServiceException(() -> postService.createPost(reqVO), POST_NAME_DUPLICATE); |
| @@ -118,7 +116,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | @@ -118,7 +116,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { | ||
| 118 | PostDO codePostDO = randomPostDO(); | 116 | PostDO codePostDO = randomPostDO(); |
| 119 | postMapper.insert(codePostDO); | 117 | postMapper.insert(codePostDO); |
| 120 | // 准备参数 | 118 | // 准备参数 |
| 121 | - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> { | 119 | + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, o -> { |
| 122 | // 设置更新的 ID | 120 | // 设置更新的 ID |
| 123 | o.setId(postDO.getId()); | 121 | o.setId(postDO.getId()); |
| 124 | // 模拟 code 重复 | 122 | // 模拟 code 重复 |
| @@ -155,30 +153,6 @@ public class PostServiceImplTest extends BaseDbUnitTest { | @@ -155,30 +153,6 @@ public class PostServiceImplTest extends BaseDbUnitTest { | ||
| 155 | } | 153 | } |
| 156 | 154 | ||
| 157 | @Test | 155 | @Test |
| 158 | - public void testGetPostList_export() { | ||
| 159 | - // mock 数据 | ||
| 160 | - PostDO postDO = randomPojo(PostDO.class, o -> { | ||
| 161 | - o.setName("码仔"); | ||
| 162 | - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 163 | - }); | ||
| 164 | - postMapper.insert(postDO); | ||
| 165 | - // 测试 name 不匹配 | ||
| 166 | - postMapper.insert(cloneIgnoreId(postDO, o -> o.setName("程序员"))); | ||
| 167 | - // 测试 status 不匹配 | ||
| 168 | - postMapper.insert(cloneIgnoreId(postDO, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); | ||
| 169 | - // 准备参数 | ||
| 170 | - PostExportReqVO reqVO = new PostExportReqVO(); | ||
| 171 | - reqVO.setName("码"); | ||
| 172 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | ||
| 173 | - | ||
| 174 | - // 调用 | ||
| 175 | - List<PostDO> list = postService.getPostList(reqVO); | ||
| 176 | - // 断言 | ||
| 177 | - assertEquals(1, list.size()); | ||
| 178 | - assertPojoEquals(postDO, list.get(0)); | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - @Test | ||
| 182 | public void testGetPostList() { | 156 | public void testGetPostList() { |
| 183 | // mock 数据 | 157 | // mock 数据 |
| 184 | PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); | 158 | PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); |