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