Commit a9c8f6c8e9ae5aadce720373a66582cbf5e56ad7
1 parent
a5c59c60
🔧 简化 post 和 dept 模块的 VO
Showing
14 changed files
with
86 additions
and
134 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.api.dept; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 3 | 4 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| 4 | -import cn.iocoder.yudao.module.system.convert.dept.DeptConvert; | |
| 5 | 5 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 6 | 6 | import cn.iocoder.yudao.module.system.service.dept.DeptService; |
| 7 | 7 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -24,13 +24,13 @@ public class DeptApiImpl implements DeptApi { |
| 24 | 24 | @Override |
| 25 | 25 | public DeptRespDTO getDept(Long id) { |
| 26 | 26 | DeptDO dept = deptService.getDept(id); |
| 27 | - return DeptConvert.INSTANCE.convert03(dept); | |
| 27 | + return BeanUtils.toBean(dept, DeptRespDTO.class); | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | @Override |
| 31 | 31 | public List<DeptRespDTO> getDeptList(Collection<Long> ids) { |
| 32 | 32 | List<DeptDO> depts = deptService.getDeptList(ids); |
| 33 | - return DeptConvert.INSTANCE.convertList03(depts); | |
| 33 | + return BeanUtils.toBean(depts, DeptRespDTO.class); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | @Override | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/captcha/CaptchaController.java
| ... | ... | @@ -17,11 +17,6 @@ import javax.annotation.Resource; |
| 17 | 17 | import javax.annotation.security.PermitAll; |
| 18 | 18 | import javax.servlet.http.HttpServletRequest; |
| 19 | 19 | |
| 20 | -/** | |
| 21 | - * 验证码 | |
| 22 | - * | |
| 23 | - * @author 芋道源码 | |
| 24 | - */ | |
| 25 | 20 | @Tag(name = "管理后台 - 验证码") |
| 26 | 21 | @RestController("adminCaptchaController") |
| 27 | 22 | @RequestMapping("/system/captcha") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java
| ... | ... | @@ -2,20 +2,22 @@ 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.module.system.controller.admin.dept.vo.dept.*; | |
| 6 | -import cn.iocoder.yudao.module.system.convert.dept.DeptConvert; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; | |
| 7 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; | |
| 7 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 8 | 11 | import cn.iocoder.yudao.module.system.service.dept.DeptService; |
| 9 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 10 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| 13 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 14 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | 15 | import org.springframework.security.access.prepost.PreAuthorize; |
| 13 | 16 | import org.springframework.validation.annotation.Validated; |
| 14 | 17 | import org.springframework.web.bind.annotation.*; |
| 15 | 18 | |
| 16 | 19 | import javax.annotation.Resource; |
| 17 | 20 | import javax.validation.Valid; |
| 18 | -import java.util.Comparator; | |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| 21 | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| ... | ... | @@ -32,16 +34,16 @@ public class DeptController { |
| 32 | 34 | @PostMapping("create") |
| 33 | 35 | @Operation(summary = "创建部门") |
| 34 | 36 | @PreAuthorize("@ss.hasPermission('system:dept:create')") |
| 35 | - public CommonResult<Long> createDept(@Valid @RequestBody DeptCreateReqVO reqVO) { | |
| 36 | - Long deptId = deptService.createDept(reqVO); | |
| 37 | + public CommonResult<Long> createDept(@Valid @RequestBody DeptSaveReqVO createReqVO) { | |
| 38 | + Long deptId = deptService.createDept(createReqVO); | |
| 37 | 39 | return success(deptId); |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | @PutMapping("update") |
| 41 | 43 | @Operation(summary = "更新部门") |
| 42 | 44 | @PreAuthorize("@ss.hasPermission('system:dept:update')") |
| 43 | - public CommonResult<Boolean> updateDept(@Valid @RequestBody DeptUpdateReqVO reqVO) { | |
| 44 | - deptService.updateDept(reqVO); | |
| 45 | + public CommonResult<Boolean> updateDept(@Valid @RequestBody DeptSaveReqVO updateReqVO) { | |
| 46 | + deptService.updateDept(updateReqVO); | |
| 45 | 47 | return success(true); |
| 46 | 48 | } |
| 47 | 49 | |
| ... | ... | @@ -59,20 +61,15 @@ public class DeptController { |
| 59 | 61 | @PreAuthorize("@ss.hasPermission('system:dept:query')") |
| 60 | 62 | public CommonResult<List<DeptRespVO>> getDeptList(DeptListReqVO reqVO) { |
| 61 | 63 | List<DeptDO> list = deptService.getDeptList(reqVO); |
| 62 | - list.sort(Comparator.comparing(DeptDO::getSort)); | |
| 63 | - return success(DeptConvert.INSTANCE.convertList(list)); | |
| 64 | + return success(BeanUtils.toBean(list, DeptRespVO.class)); | |
| 64 | 65 | } |
| 65 | 66 | |
| 66 | - @GetMapping("/list-all-simple") | |
| 67 | + @GetMapping(value = {"/list-all-simple", "/simple-list"}) | |
| 67 | 68 | @Operation(summary = "获取部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项") |
| 68 | 69 | public CommonResult<List<DeptSimpleRespVO>> getSimpleDeptList() { |
| 69 | - // 获得部门列表,只要开启状态的 | |
| 70 | - DeptListReqVO reqVO = new DeptListReqVO(); | |
| 71 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 72 | - List<DeptDO> list = deptService.getDeptList(reqVO); | |
| 73 | - // 排序后,返回给前端 | |
| 74 | - list.sort(Comparator.comparing(DeptDO::getSort)); | |
| 75 | - return success(DeptConvert.INSTANCE.convertList02(list)); | |
| 70 | + List<DeptDO> list = deptService.getDeptList( | |
| 71 | + new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); | |
| 72 | + return success(BeanUtils.toBean(list, DeptSimpleRespVO.class)); | |
| 76 | 73 | } |
| 77 | 74 | |
| 78 | 75 | @GetMapping("/get") |
| ... | ... | @@ -80,7 +77,8 @@ public class DeptController { |
| 80 | 77 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 81 | 78 | @PreAuthorize("@ss.hasPermission('system:dept:query')") |
| 82 | 79 | public CommonResult<DeptRespVO> getDept(@RequestParam("id") Long id) { |
| 83 | - return success(DeptConvert.INSTANCE.convert(deptService.getDept(id))); | |
| 80 | + DeptDO dept = deptService.getDept(id); | |
| 81 | + return success(BeanUtils.toBean(dept, DeptRespVO.class)); | |
| 84 | 82 | } |
| 85 | 83 | |
| 86 | 84 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/PostController.java
| ... | ... | @@ -73,7 +73,7 @@ public class PostController { |
| 73 | 73 | return success(BeanUtils.toBean(post, PostRespVO.class)); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - @GetMapping("/list-all-simple") | |
| 76 | + @GetMapping(value = {"/list-all-simple", "simple-list"}) | |
| 77 | 77 | @Operation(summary = "获取岗位全列表", description = "只包含被开启的岗位,主要用于前端的下拉选项") |
| 78 | 78 | public CommonResult<List<PostSimpleRespVO>> getSimplePostList() { |
| 79 | 79 | // 获得岗位列表,只要开启状态的 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; | |
| 2 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 3 | -import lombok.Data; | |
| 4 | -import lombok.EqualsAndHashCode; | |
| 5 | -import lombok.ToString; | |
| 6 | - | |
| 7 | -@Schema(description = "管理后台 - 部门创建 Request VO") | |
| 8 | -@Data | |
| 9 | -@EqualsAndHashCode(callSuper = true) | |
| 10 | -@ToString(callSuper = true) | |
| 11 | -public class DeptCreateReqVO extends DeptBaseVO { | |
| 12 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptRespVO.java
| ... | ... | @@ -2,19 +2,35 @@ package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 4 | import lombok.Data; |
| 5 | -import lombok.EqualsAndHashCode; | |
| 6 | 5 | |
| 7 | 6 | import java.time.LocalDateTime; |
| 8 | 7 | |
| 9 | 8 | @Schema(description = "管理后台 - 部门信息 Response VO") |
| 10 | 9 | @Data |
| 11 | -@EqualsAndHashCode(callSuper = true) | |
| 12 | -public class DeptRespVO extends DeptBaseVO { | |
| 10 | +public class DeptRespVO { | |
| 13 | 11 | |
| 14 | - @Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 12 | + @Schema(description = "部门编号", example = "1024") | |
| 15 | 13 | private Long id; |
| 16 | 14 | |
| 17 | - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 15 | + @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") | |
| 16 | + private String name; | |
| 17 | + | |
| 18 | + @Schema(description = "父部门 ID", example = "1024") | |
| 19 | + private Long parentId; | |
| 20 | + | |
| 21 | + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 22 | + private Integer sort; | |
| 23 | + | |
| 24 | + @Schema(description = "负责人的用户编号", example = "2048") | |
| 25 | + private Long leaderUserId; | |
| 26 | + | |
| 27 | + @Schema(description = "联系电话", example = "15601691000") | |
| 28 | + private String phone; | |
| 29 | + | |
| 30 | + @Schema(description = "邮箱", example = "yudao@iocoder.cn") | |
| 31 | + private String email; | |
| 32 | + | |
| 33 | + @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 18 | 34 | private Integer status; |
| 19 | 35 | |
| 20 | 36 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 6 | import lombok.Data; |
| 5 | 7 | |
| ... | ... | @@ -8,19 +10,19 @@ import javax.validation.constraints.NotBlank; |
| 8 | 10 | import javax.validation.constraints.NotNull; |
| 9 | 11 | import javax.validation.constraints.Size; |
| 10 | 12 | |
| 11 | -/** | |
| 12 | - * 部门 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 13 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 14 | - */ | |
| 13 | +@Schema(description = "管理后台 - 部门创建/修改 Request VO") | |
| 15 | 14 | @Data |
| 16 | -public class DeptBaseVO { | |
| 15 | +public class DeptSaveReqVO { | |
| 17 | 16 | |
| 18 | - @Schema(description = "菜单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") | |
| 17 | + @Schema(description = "部门编号", example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") | |
| 19 | 21 | @NotBlank(message = "部门名称不能为空") |
| 20 | - @Size(max = 30, message = "部门名称长度不能超过30个字符") | |
| 22 | + @Size(max = 30, message = "部门名称长度不能超过 30 个字符") | |
| 21 | 23 | private String name; |
| 22 | 24 | |
| 23 | - @Schema(description = "父菜单 ID", example = "1024") | |
| 25 | + @Schema(description = "父部门 ID", example = "1024") | |
| 24 | 26 | private Long parentId; |
| 25 | 27 | |
| 26 | 28 | @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| ... | ... | @@ -36,12 +38,12 @@ public class DeptBaseVO { |
| 36 | 38 | |
| 37 | 39 | @Schema(description = "邮箱", example = "yudao@iocoder.cn") |
| 38 | 40 | @Email(message = "邮箱格式不正确") |
| 39 | - @Size(max = 50, message = "邮箱长度不能超过50个字符") | |
| 41 | + @Size(max = 50, message = "邮箱长度不能超过 50 个字符") | |
| 40 | 42 | private String email; |
| 41 | 43 | |
| 42 | 44 | @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 43 | 45 | @NotNull(message = "状态不能为空") |
| 44 | -// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") | |
| 46 | + @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") | |
| 45 | 47 | private Integer status; |
| 46 | 48 | |
| 47 | 49 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/vo/dept/DeptUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept; | |
| 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 DeptUpdateReqVO extends DeptBaseVO { | |
| 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/controller/admin/dept/vo/post/PostRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.dept.vo.post; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 4 | 5 | import cn.iocoder.yudao.module.system.enums.DictTypeConstants; |
| 6 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 5 | 7 | import com.alibaba.excel.annotation.ExcelProperty; |
| 6 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 7 | 9 | import lombok.Data; |
| ... | ... | @@ -10,6 +12,7 @@ import java.time.LocalDateTime; |
| 10 | 12 | |
| 11 | 13 | @Schema(description = "管理后台 - 岗位信息 Response VO") |
| 12 | 14 | @Data |
| 15 | +@ExcelIgnoreUnannotated | |
| 13 | 16 | public class PostRespVO { |
| 14 | 17 | |
| 15 | 18 | @Schema(description = "岗位序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| ... | ... | @@ -29,6 +32,7 @@ public class PostRespVO { |
| 29 | 32 | private Integer sort; |
| 30 | 33 | |
| 31 | 34 | @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 35 | + @ExcelProperty(value = "状态", converter = DictConvert.class) | |
| 32 | 36 | @DictFormat(DictTypeConstants.COMMON_STATUS) |
| 33 | 37 | private Integer status; |
| 34 | 38 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dept/DeptConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.dept; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; | |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; | |
| 8 | -import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; | |
| 9 | -import org.mapstruct.Mapper; | |
| 10 | -import org.mapstruct.factory.Mappers; | |
| 11 | - | |
| 12 | -import java.util.List; | |
| 13 | -import java.util.Map; | |
| 14 | - | |
| 15 | -@Mapper | |
| 16 | -public interface DeptConvert { | |
| 17 | - | |
| 18 | - DeptConvert INSTANCE = Mappers.getMapper(DeptConvert.class); | |
| 19 | - | |
| 20 | - List<DeptRespVO> convertList(List<DeptDO> list); | |
| 21 | - | |
| 22 | - List<DeptSimpleRespVO> convertList02(List<DeptDO> list); | |
| 23 | - | |
| 24 | - DeptRespVO convert(DeptDO bean); | |
| 25 | - | |
| 26 | - DeptDO convert(DeptCreateReqVO bean); | |
| 27 | - | |
| 28 | - DeptDO convert(DeptUpdateReqVO bean); | |
| 29 | - | |
| 30 | - List<DeptRespDTO> convertList03(List<DeptDO> list); | |
| 31 | - | |
| 32 | - DeptRespDTO convert03(DeptDO bean); | |
| 33 | - | |
| 34 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptService.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.dept; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.collection.CollUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; | |
| 6 | 4 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; | |
| 8 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 9 | 7 | |
| 10 | -import java.util.*; | |
| 8 | +import java.util.Collection; | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Map; | |
| 11 | +import java.util.Set; | |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * 部门 Service 接口 |
| ... | ... | @@ -19,17 +20,17 @@ public interface DeptService { |
| 19 | 20 | /** |
| 20 | 21 | * 创建部门 |
| 21 | 22 | * |
| 22 | - * @param reqVO 部门信息 | |
| 23 | + * @param createReqVO 部门信息 | |
| 23 | 24 | * @return 部门编号 |
| 24 | 25 | */ |
| 25 | - Long createDept(DeptCreateReqVO reqVO); | |
| 26 | + Long createDept(DeptSaveReqVO createReqVO); | |
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | 29 | * 更新部门 |
| 29 | 30 | * |
| 30 | - * @param reqVO 部门信息 | |
| 31 | + * @param updateReqVO 部门信息 | |
| 31 | 32 | */ |
| 32 | - void updateDept(DeptUpdateReqVO reqVO); | |
| 33 | + void updateDept(DeptSaveReqVO updateReqVO); | |
| 33 | 34 | |
| 34 | 35 | /** |
| 35 | 36 | * 删除部门 |
| ... | ... | @@ -69,9 +70,6 @@ public interface DeptService { |
| 69 | 70 | * @return 部门 Map |
| 70 | 71 | */ |
| 71 | 72 | default Map<Long, DeptDO> getDeptMap(Collection<Long> ids) { |
| 72 | - if (CollUtil.isEmpty(ids)) { | |
| 73 | - return Collections.emptyMap(); | |
| 74 | - } | |
| 75 | 73 | List<DeptDO> list = getDeptList(ids); |
| 76 | 74 | return CollectionUtils.convertMap(list, DeptDO::getId); |
| 77 | 75 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java
| ... | ... | @@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.system.service.dept; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; | |
| 8 | 8 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; | |
| 10 | -import cn.iocoder.yudao.module.system.convert.dept.DeptConvert; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; | |
| 11 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 12 | 11 | import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; |
| 13 | 12 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| ... | ... | @@ -41,7 +40,7 @@ public class DeptServiceImpl implements DeptService { |
| 41 | 40 | @Override |
| 42 | 41 | @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, |
| 43 | 42 | allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 |
| 44 | - public Long createDept(DeptCreateReqVO createReqVO) { | |
| 43 | + public Long createDept(DeptSaveReqVO createReqVO) { | |
| 45 | 44 | if (createReqVO.getParentId() == null) { |
| 46 | 45 | createReqVO.setParentId(DeptDO.PARENT_ID_ROOT); |
| 47 | 46 | } |
| ... | ... | @@ -51,7 +50,7 @@ public class DeptServiceImpl implements DeptService { |
| 51 | 50 | validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); |
| 52 | 51 | |
| 53 | 52 | // 插入部门 |
| 54 | - DeptDO dept = DeptConvert.INSTANCE.convert(createReqVO); | |
| 53 | + DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class); | |
| 55 | 54 | deptMapper.insert(dept); |
| 56 | 55 | return dept.getId(); |
| 57 | 56 | } |
| ... | ... | @@ -59,7 +58,7 @@ public class DeptServiceImpl implements DeptService { |
| 59 | 58 | @Override |
| 60 | 59 | @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, |
| 61 | 60 | allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 |
| 62 | - public void updateDept(DeptUpdateReqVO updateReqVO) { | |
| 61 | + public void updateDept(DeptSaveReqVO updateReqVO) { | |
| 63 | 62 | if (updateReqVO.getParentId() == null) { |
| 64 | 63 | updateReqVO.setParentId(DeptDO.PARENT_ID_ROOT); |
| 65 | 64 | } |
| ... | ... | @@ -71,7 +70,7 @@ public class DeptServiceImpl implements DeptService { |
| 71 | 70 | validateDeptNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); |
| 72 | 71 | |
| 73 | 72 | // 更新部门 |
| 74 | - DeptDO updateObj = DeptConvert.INSTANCE.convert(updateReqVO); | |
| 73 | + DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class); | |
| 75 | 74 | deptMapper.updateById(updateObj); |
| 76 | 75 | } |
| 77 | 76 | |
| ... | ... | @@ -165,7 +164,9 @@ public class DeptServiceImpl implements DeptService { |
| 165 | 164 | |
| 166 | 165 | @Override |
| 167 | 166 | public List<DeptDO> getDeptList(DeptListReqVO reqVO) { |
| 168 | - return deptMapper.selectList(reqVO); | |
| 167 | + List<DeptDO> list = deptMapper.selectList(reqVO); | |
| 168 | + list.sort(Comparator.comparing(DeptDO::getSort)); | |
| 169 | + return list; | |
| 169 | 170 | } |
| 170 | 171 | |
| 171 | 172 | @Override | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImplTest.java
| ... | ... | @@ -3,9 +3,8 @@ package cn.iocoder.yudao.module.system.service.dept; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 5 | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; | |
| 7 | 6 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; | |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| 10 | 9 | import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; |
| 11 | 10 | import org.junit.jupiter.api.Test; |
| ... | ... | @@ -39,7 +38,8 @@ public class DeptServiceImplTest extends BaseDbUnitTest { |
| 39 | 38 | @Test |
| 40 | 39 | public void testCreateDept() { |
| 41 | 40 | // 准备参数 |
| 42 | - DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> { | |
| 41 | + DeptSaveReqVO reqVO = randomPojo(DeptSaveReqVO.class, o -> { | |
| 42 | + o.setId(null); // 防止 id 被设置 | |
| 43 | 43 | o.setParentId(DeptDO.PARENT_ID_ROOT); |
| 44 | 44 | o.setStatus(randomCommonStatus()); |
| 45 | 45 | }); |
| ... | ... | @@ -50,7 +50,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest { |
| 50 | 50 | assertNotNull(deptId); |
| 51 | 51 | // 校验记录的属性是否正确 |
| 52 | 52 | DeptDO deptDO = deptMapper.selectById(deptId); |
| 53 | - assertPojoEquals(reqVO, deptDO); | |
| 53 | + assertPojoEquals(reqVO, deptDO, "id"); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | @Test |
| ... | ... | @@ -59,7 +59,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest { |
| 59 | 59 | DeptDO dbDeptDO = randomPojo(DeptDO.class, o -> o.setStatus(randomCommonStatus())); |
| 60 | 60 | deptMapper.insert(dbDeptDO);// @Sql: 先插入出一条存在的数据 |
| 61 | 61 | // 准备参数 |
| 62 | - DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> { | |
| 62 | + DeptSaveReqVO reqVO = randomPojo(DeptSaveReqVO.class, o -> { | |
| 63 | 63 | // 设置更新的 ID |
| 64 | 64 | o.setParentId(DeptDO.PARENT_ID_ROOT); |
| 65 | 65 | o.setId(dbDeptDO.getId()); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImplTest.java
| ... | ... | @@ -43,7 +43,8 @@ public class PostServiceImplTest extends BaseDbUnitTest { |
| 43 | 43 | public void testCreatePost_success() { |
| 44 | 44 | // 准备参数 |
| 45 | 45 | PostSaveReqVO reqVO = randomPojo(PostSaveReqVO.class, |
| 46 | - o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())); | |
| 46 | + o -> o.setStatus(randomEle(CommonStatusEnum.values()).getStatus())) | |
| 47 | + .setId(null); // 防止 id 被设置 | |
| 47 | 48 | // 调用 |
| 48 | 49 | Long postId = postService.createPost(reqVO); |
| 49 | 50 | |
| ... | ... | @@ -51,7 +52,7 @@ public class PostServiceImplTest extends BaseDbUnitTest { |
| 51 | 52 | assertNotNull(postId); |
| 52 | 53 | // 校验记录的属性是否正确 |
| 53 | 54 | PostDO post = postMapper.selectById(postId); |
| 54 | - assertPojoEquals(reqVO, post); | |
| 55 | + assertPojoEquals(reqVO, post, "id"); | |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | @Test |
| ... | ... | @@ -225,4 +226,5 @@ public class PostServiceImplTest extends BaseDbUnitTest { |
| 225 | 226 | }; |
| 226 | 227 | return randomPojo(PostDO.class, ArrayUtils.append(consumer, consumers)); |
| 227 | 228 | } |
| 229 | + | |
| 228 | 230 | } | ... | ... |