Commit 7e6b084f77c5217db899a5d5fa3401b2598214b8

Authored by zhijiantianya@gmail.com
2 parents b47c4fbd 5e6e02e4

Merge branch 'feature/vo-optimize' of https://gitee.com/zhijiantianya/ruoyi-vue-…

…pro into feature/sub-table
Showing 17 changed files with 130 additions and 245 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageParam.java
... ... @@ -15,6 +15,13 @@ public class PageParam implements Serializable {
15 15 private static final Integer PAGE_NO = 1;
16 16 private static final Integer PAGE_SIZE = 10;
17 17  
  18 + /**
  19 + * 每页条数 - 不分页
  20 + *
  21 + * 例如说,导出接口,可以设置 {@link #pageSize} 为 -1 不分页,查询所有数据。
  22 + */
  23 + public static final Integer PAGE_SIZE_NONE = -1;
  24 +
18 25 @Schema(description = "页码,从 1 开始", requiredMode = Schema.RequiredMode.REQUIRED,example = "1")
19 26 @NotNull(message = "页码不能为空")
20 27 @Min(value = 1, message = "页码最小值为 1")
... ...
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 38 \ No newline at end of file
... ...
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;
26 26 public interface BaseMapperX<T> extends MPJBaseMapper<T> {
27 27  
28 28 default PageResult<T> selectPage(PageParam pageParam, @Param("ew") Wrapper<T> queryWrapper) {
  29 + // 特殊:不分页,直接查询全部
  30 + if (PageParam.PAGE_SIZE_NONE.equals(pageParam.getPageNo())) {
  31 + List<T> list = selectList(queryWrapper);
  32 + return new PageResult<>(list, (long) list.size());
  33 + }
  34 +
29 35 // MyBatis Plus 查询
30 36 IPage<T> mpPage = MyBatisUtils.buildPage(pageParam);
31 37 selectPage(mpPage, queryWrapper);
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java
... ... @@ -2,16 +2,19 @@ package cn.iocoder.yudao.module.system.controller.admin.dept;
2 2  
3 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  7 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
7 9 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
8   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.*;
9   -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;
10 13 import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
11 14 import cn.iocoder.yudao.module.system.service.dept.PostService;
12   -import io.swagger.v3.oas.annotations.tags.Tag;
13   -import io.swagger.v3.oas.annotations.Parameter;
14 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;
15 18 import org.springframework.security.access.prepost.PreAuthorize;
16 19 import org.springframework.validation.annotation.Validated;
17 20 import org.springframework.web.bind.annotation.*;
... ... @@ -39,16 +42,16 @@ public class PostController {
39 42 @PostMapping("/create")
40 43 @Operation(summary = "创建岗位")
41 44 @PreAuthorize("@ss.hasPermission('system:post:create')")
42   - public CommonResult<Long> createPost(@Valid @RequestBody PostCreateReqVO reqVO) {
43   - Long postId = postService.createPost(reqVO);
  45 + public CommonResult<Long> createPost(@Valid @RequestBody PostSaveReqVO createReqVO) {
  46 + Long postId = postService.createPost(createReqVO);
44 47 return success(postId);
45 48 }
46 49  
47 50 @PutMapping("/update")
48 51 @Operation(summary = "修改岗位")
49 52 @PreAuthorize("@ss.hasPermission('system:post:update')")
50   - public CommonResult<Boolean> updatePost(@Valid @RequestBody PostUpdateReqVO reqVO) {
51   - postService.updatePost(reqVO);
  53 + public CommonResult<Boolean> updatePost(@Valid @RequestBody PostSaveReqVO updateReqVO) {
  54 + postService.updatePost(updateReqVO);
52 55 return success(true);
53 56 }
54 57  
... ... @@ -65,35 +68,38 @@ public class PostController {
65 68 @Parameter(name = "id", description = "岗位编号", required = true, example = "1024")
66 69 @PreAuthorize("@ss.hasPermission('system:post:query')")
67 70 public CommonResult<PostRespVO> getPost(@RequestParam("id") Long id) {
68   - return success(PostConvert.INSTANCE.convert(postService.getPost(id)));
  71 + PostDO post = postService.getPost(id);
  72 + return success(BeanUtils.toBean(post, PostRespVO.class));
69 73 }
70 74  
71 75 @GetMapping("/list-all-simple")
72   - @Operation(summary = "获取岗位精简信息列表", description = "只包含被开启的岗位,主要用于前端的下拉选项")
73   - public CommonResult<List<PostSimpleRespVO>> getSimplePostList() {
  76 + @Operation(summary = "获取岗位全列表", description = "只包含被开启的岗位,主要用于前端的下拉选项")
  77 + public CommonResult<List<PostRespVO>> getSimplePostList() {
74 78 // 获得岗位列表,只要开启状态的
75 79 List<PostDO> list = postService.getPostList(null, Collections.singleton(CommonStatusEnum.ENABLE.getStatus()));
76 80 // 排序后,返回给前端
77 81 list.sort(Comparator.comparing(PostDO::getSort));
78   - return success(PostConvert.INSTANCE.convertList02(list));
  82 + return success(BeanUtils.toBean(list, PostRespVO.class));
79 83 }
80 84  
81 85 @GetMapping("/page")
82 86 @Operation(summary = "获得岗位分页列表")
83 87 @PreAuthorize("@ss.hasPermission('system:post:query')")
84   - public CommonResult<PageResult<PostRespVO>> getPostPage(@Validated PostPageReqVO reqVO) {
85   - 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));
86 91 }
87 92  
88 93 @GetMapping("/export")
89 94 @Operation(summary = "岗位管理")
90 95 @PreAuthorize("@ss.hasPermission('system:post:export')")
91 96 @OperateLog(type = EXPORT)
92   - public void export(HttpServletResponse response, @Validated PostExportReqVO reqVO) throws IOException {
93   - List<PostDO> posts = postService.getPostList(reqVO);
94   - List<PostExcelVO> data = PostConvert.INSTANCE.convertList03(posts);
  97 + public void export(HttpServletResponse response, @Validated PostPageReqVO reqVO) throws IOException {
  98 + reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  99 + List<PostDO> list = postService.getPostPage(reqVO).getList();
95 100 // 输出
96   - ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostExcelVO.class, data);
  101 + ExcelUtils.write(response, "岗位数据.xls", "岗位列表", PostRespVO.class,
  102 + BeanUtils.toBean(list, PostRespVO.class));
97 103 }
98 104  
99 105 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostCreateReqVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
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 PostCreateReqVO extends PostBaseVO {
11   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExcelVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
2   -
3   -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
4   -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
5   -import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
6   -import com.alibaba.excel.annotation.ExcelProperty;
7   -import lombok.Data;
8   -
9   -/**
10   - * 岗位 Excel 导出响应 VO
11   - */
12   -@Data
13   -public class PostExcelVO {
14   -
15   - @ExcelProperty("岗位序号")
16   - private Long id;
17   -
18   - @ExcelProperty("岗位编码")
19   - private String code;
20   -
21   - @ExcelProperty("岗位名称")
22   - private String name;
23   -
24   - @ExcelProperty("岗位排序")
25   - private Integer sort;
26   -
27   - @ExcelProperty(value = "状态", converter = DictConvert.class)
28   - @DictFormat(DictTypeConstants.COMMON_STATUS)
29   - private String status;
30   -
31   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostExportReqVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -
6   -@Schema(description = "管理后台 - 岗位导出 Request VO,参数和 PostExcelVO 是一致的")
7   -@Data
8   -public class PostExportReqVO {
9   -
10   - @Schema(description = "岗位编码,模糊匹配", example = "yudao")
11   - private String code;
12   -
13   - @Schema(description = "岗位名称,模糊匹配", example = "芋道")
14   - private String name;
15   -
16   - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
17   - private Integer status;
18   -
19   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostListReqVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
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 PostListReqVO extends PostBaseVO {
11   -
12   - @Schema(description = "岗位名称,模糊匹配", example = "芋道")
13   - private String name;
14   -
15   - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
16   - private Integer status;
17   -
18   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostRespVO.java
1 1 package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
2 2  
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
  5 +import com.alibaba.excel.annotation.ExcelProperty;
3 6 import io.swagger.v3.oas.annotations.media.Schema;
4 7 import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6 8  
7 9 import java.time.LocalDateTime;
8 10  
9 11 @Schema(description = "管理后台 - 岗位信息 Response VO")
10 12 @Data
11   -@EqualsAndHashCode(callSuper = true)
12   -public class PostRespVO extends PostBaseVO {
  13 +public class PostRespVO {
13 14  
14 15 @Schema(description = "岗位序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  16 + @ExcelProperty("岗位序号")
15 17 private Long id;
16 18  
17   - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
  19 + @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小土豆")
  20 + @ExcelProperty("岗位名称")
  21 + private String name;
  22 +
  23 + @Schema(description = "岗位编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
  24 + @ExcelProperty("岗位编码")
  25 + private String code;
  26 +
  27 + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  28 + @ExcelProperty("岗位排序")
  29 + private Integer sort;
  30 +
  31 + @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  32 + @DictFormat(DictTypeConstants.COMMON_STATUS)
  33 + private Integer status;
  34 +
  35 + @Schema(description = "备注", example = "快乐的备注")
  36 + private String remark;
  37 +
  38 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
18 39 private LocalDateTime createTime;
19 40  
20 41 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostBaseVO.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
1 1 package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
2 5 import io.swagger.v3.oas.annotations.media.Schema;
3 6 import lombok.Data;
4 7  
... ... @@ -6,16 +9,16 @@ import javax.validation.constraints.NotBlank;
6 9 import javax.validation.constraints.NotNull;
7 10 import javax.validation.constraints.Size;
8 11  
9   -/**
10   - * 岗位 Base VO,提供给添加、修改、详细的子 VO 使用
11   - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
12   - */
  12 +@Schema(description = "管理后台 - 岗位创建/修改 Request VO")
13 13 @Data
14   -public class PostBaseVO {
  14 +public class PostSaveReqVO {
  15 +
  16 + @Schema(description = "岗位编号", example = "1024")
  17 + private Long id;
15 18  
16   - @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小博主")
  19 + @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小土豆")
17 20 @NotBlank(message = "岗位名称不能为空")
18   - @Size(max = 50, message = "岗位名称长度不能超过50个字符")
  21 + @Size(max = 50, message = "岗位名称长度不能超过 50 个字符")
19 22 private String name;
20 23  
21 24 @Schema(description = "岗位编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
... ... @@ -27,10 +30,11 @@ public class PostBaseVO {
27 30 @NotNull(message = "显示顺序不能为空")
28 31 private Integer sort;
29 32  
30   - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  33 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  34 + @InEnum(CommonStatusEnum.class)
31 35 private Integer status;
32 36  
33 37 @Schema(description = "备注", example = "快乐的备注")
34 38 private String remark;
35 39  
36 40 -}
  41 +}
37 42 \ No newline at end of file
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostSimpleRespVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.AllArgsConstructor;
5   -import lombok.Data;
6   -import lombok.NoArgsConstructor;
7   -
8   -@Schema(description = "管理后台 - 岗位精简信息 Response VO")
9   -@Data
10   -@NoArgsConstructor
11   -@AllArgsConstructor
12   -public class PostSimpleRespVO {
13   -
14   - @Schema(description = "岗位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
15   - private Long id;
16   -
17   - @Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
18   - private String name;
19   -
20   -}
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/post/PostUpdateReqVO.java deleted
1   -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post;
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 PostUpdateReqVO extends PostBaseVO {
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/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<PostSimpleRespVO> convertList02(List<PostDO> list);
17   -
18   - PageResult<PostRespVO> convertPage(PageResult<PostDO> page);
19   -
20   - PostRespVO convert(PostDO id);
21   -
22   - PostDO convert(PostCreateReqVO bean);
23   -
24   - PostDO convert(PostUpdateReqVO reqVO);
25   -
26   - List<PostExcelVO> convertList03(List<PostDO> list);
27   -
28   -}
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;
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO;
7 6 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
8 7 import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
9 8 import org.apache.ibatis.annotations.Mapper;
... ... @@ -28,13 +27,6 @@ public interface PostMapper extends BaseMapperX&lt;PostDO&gt; {
28 27 .orderByDesc(PostDO::getId));
29 28 }
30 29  
31   - default List<PostDO> selectList(PostExportReqVO reqVO) {
32   - return selectList(new LambdaQueryWrapperX<PostDO>()
33   - .likeIfPresent(PostDO::getCode, reqVO.getCode())
34   - .likeIfPresent(PostDO::getName, reqVO.getName())
35   - .eqIfPresent(PostDO::getStatus, reqVO.getStatus()));
36   - }
37   -
38 30 default PostDO selectByName(String name) {
39 31 return selectOne(PostDO::getName, name);
40 32 }
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO;
6   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO;
7 5 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
8   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO;
  6 +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO;
9 7 import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
10 8 import org.springframework.lang.Nullable;
11 9  
... ... @@ -24,17 +22,17 @@ public interface PostService {
24 22 /**
25 23 * 创建岗位
26 24 *
27   - * @param reqVO 岗位信息
  25 + * @param createReqVO 岗位信息
28 26 * @return 岗位编号
29 27 */
30   - Long createPost(PostCreateReqVO reqVO);
  28 + Long createPost(PostSaveReqVO createReqVO);
31 29  
32 30 /**
33 31 * 更新岗位
34 32 *
35   - * @param reqVO 岗位信息
  33 + * @param updateReqVO 岗位信息
36 34 */
37   - void updatePost(PostUpdateReqVO reqVO);
  35 + void updatePost(PostSaveReqVO updateReqVO);
38 36  
39 37 /**
40 38 * 删除岗位信息
... ... @@ -71,14 +69,6 @@ public interface PostService {
71 69 PageResult<PostDO> getPostPage(PostPageReqVO reqVO);
72 70  
73 71 /**
74   - * 获得岗位列表
75   - *
76   - * @param reqVO 查询条件
77   - * @return 部门列表
78   - */
79   - List<PostDO> getPostList(PostExportReqVO reqVO);
80   -
81   - /**
82 72 * 获得岗位信息
83 73 *
84 74 * @param id 岗位编号
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
... ... @@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.system.service.dept;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO;
7   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
8 7 import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO;
9   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostUpdateReqVO;
10   -import cn.iocoder.yudao.module.system.convert.dept.PostConvert;
  8 +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO;
11 9 import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
12 10 import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper;
13 11 import org.springframework.stereotype.Service;
... ... @@ -35,23 +33,23 @@ public class PostServiceImpl implements PostService {
35 33 private PostMapper postMapper;
36 34  
37 35 @Override
38   - public Long createPost(PostCreateReqVO reqVO) {
  36 + public Long createPost(PostSaveReqVO createReqVO) {
39 37 // 校验正确性
40   - validatePostForCreateOrUpdate(null, reqVO.getName(), reqVO.getCode());
  38 + validatePostForCreateOrUpdate(null, createReqVO.getName(), createReqVO.getCode());
41 39  
42 40 // 插入岗位
43   - PostDO post = PostConvert.INSTANCE.convert(reqVO);
  41 + PostDO post = BeanUtils.toBean(createReqVO, PostDO.class);
44 42 postMapper.insert(post);
45 43 return post.getId();
46 44 }
47 45  
48 46 @Override
49   - public void updatePost(PostUpdateReqVO reqVO) {
  47 + public void updatePost(PostSaveReqVO updateReqVO) {
50 48 // 校验正确性
51   - validatePostForCreateOrUpdate(reqVO.getId(), reqVO.getName(), reqVO.getCode());
  49 + validatePostForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getName(), updateReqVO.getCode());
52 50  
53 51 // 更新岗位
54   - PostDO updateObj = PostConvert.INSTANCE.convert(reqVO);
  52 + PostDO updateObj = BeanUtils.toBean(updateReqVO, PostDO.class);
55 53 postMapper.updateById(updateObj);
56 54 }
57 55  
... ... @@ -120,11 +118,6 @@ public class PostServiceImpl implements PostService {
120 118 }
121 119  
122 120 @Override
123   - public List<PostDO> getPostList(PostExportReqVO reqVO) {
124   - return postMapper.selectList(reqVO);
125   - }
126   -
127   - @Override
128 121 public PostDO getPost(Long id) {
129 122 return postMapper.selectById(id);
130 123 }
... ...
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 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 5 import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils;
6 6 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
7   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostCreateReqVO;
8   -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO;
9 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 9 import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
12 10 import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper;
13 11 import org.junit.jupiter.api.Test;
... ... @@ -44,7 +42,7 @@ public class PostServiceImplTest extends BaseDbUnitTest {
44 42 @Test
45 43 public void testCreatePost_success() {
46 44 // 准备参数
47   - PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class,
  45 + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class,
48 46 o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()));
49 47 // 调用
50 48 Long postId = postService.createPost(reqVO);
... ... @@ -62,7 +60,7 @@ public class PostServiceImplTest extends BaseDbUnitTest {
62 60 PostDO postDO = randomPostDO();
63 61 postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据
64 62 // 准备参数
65   - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> {
  63 + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, o -> {
66 64 // 设置更新的 ID
67 65 o.setId(postDO.getId());
68 66 o.setStatus(randomEle(CommonStatusEnum.values()).getStatus());
... ... @@ -103,7 +101,7 @@ public class PostServiceImplTest extends BaseDbUnitTest {
103 101 PostDO postDO = randomPostDO();
104 102 postMapper.insert(postDO);// @Sql: 先插入出一条存在的数据
105 103 // 准备参数
106   - PostCreateReqVO reqVO = randomPojo(PostCreateReqVO.class,
  104 + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class,
107 105 // 模拟 name 重复
108 106 o -> o.setName(postDO.getName()));
109 107 assertServiceException(() -> postService.createPost(reqVO), POST_NAME_DUPLICATE);
... ... @@ -118,7 +116,7 @@ public class PostServiceImplTest extends BaseDbUnitTest {
118 116 PostDO codePostDO = randomPostDO();
119 117 postMapper.insert(codePostDO);
120 118 // 准备参数
121   - PostUpdateReqVO reqVO = randomPojo(PostUpdateReqVO.class, o -> {
  119 + PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, o -> {
122 120 // 设置更新的 ID
123 121 o.setId(postDO.getId());
124 122 // 模拟 code 重复
... ... @@ -155,30 +153,6 @@ public class PostServiceImplTest extends BaseDbUnitTest {
155 153 }
156 154  
157 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 156 public void testGetPostList() {
183 157 // mock 数据
184 158 PostDO postDO01 = randomPojo(PostDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
... ...