Commit 2dd835893a6a5e14305d521606808d1ac287e784
1 parent
73d53dba
🔧 简化 permission 模块的 VO
Showing
27 changed files
with
193 additions
and
352 deletions
yudao-framework/yudao-spring-boot-starter-biz-operatelog/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/OperateLogFrameworkServiceImpl.java
| ... | ... | @@ -21,7 +21,7 @@ public class OperateLogFrameworkServiceImpl implements OperateLogFrameworkServic |
| 21 | 21 | @Override |
| 22 | 22 | @Async |
| 23 | 23 | public void createOperateLog(OperateLog operateLog) { |
| 24 | - OperateLogCreateReqDTO reqDTO = BeanUtil.copyProperties(operateLog, OperateLogCreateReqDTO.class); | |
| 24 | + OperateLogCreateReqDTO reqDTO = BeanUtil.toBean(operateLog, OperateLogCreateReqDTO.class); | |
| 25 | 25 | operateLogApi.createOperateLog(reqDTO); |
| 26 | 26 | } |
| 27 | 27 | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/permission/DataScopeEnum.java
| 1 | 1 | package cn.iocoder.yudao.module.system.enums.permission; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | |
| 3 | 4 | import lombok.AllArgsConstructor; |
| 4 | 5 | import lombok.Getter; |
| 5 | 6 | |
| 7 | +import java.util.Arrays; | |
| 8 | + | |
| 6 | 9 | /** |
| 7 | 10 | * 数据范围枚举类 |
| 8 | 11 | * |
| ... | ... | @@ -12,7 +15,7 @@ import lombok.Getter; |
| 12 | 15 | */ |
| 13 | 16 | @Getter |
| 14 | 17 | @AllArgsConstructor |
| 15 | -public enum DataScopeEnum { | |
| 18 | +public enum DataScopeEnum implements IntArrayValuable { | |
| 16 | 19 | |
| 17 | 20 | ALL(1), // 全部数据权限 |
| 18 | 21 | |
| ... | ... | @@ -27,4 +30,11 @@ public enum DataScopeEnum { |
| 27 | 30 | */ |
| 28 | 31 | private final Integer scope; |
| 29 | 32 | |
| 33 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DataScopeEnum::getScope).toArray(); | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public int[] array() { | |
| 37 | + return ARRAYS; | |
| 38 | + } | |
| 39 | + | |
| 30 | 40 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/MenuController.java
| ... | ... | @@ -2,13 +2,16 @@ package cn.iocoder.yudao.module.system.controller.admin.permission; |
| 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.permission.vo.menu.*; | |
| 6 | -import cn.iocoder.yudao.module.system.convert.permission.MenuConvert; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; | |
| 7 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuRespVO; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO; | |
| 7 | 10 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 8 | 11 | import cn.iocoder.yudao.module.system.service.permission.MenuService; |
| 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.*; |
| ... | ... | @@ -32,16 +35,16 @@ public class MenuController { |
| 32 | 35 | @PostMapping("/create") |
| 33 | 36 | @Operation(summary = "创建菜单") |
| 34 | 37 | @PreAuthorize("@ss.hasPermission('system:menu:create')") |
| 35 | - public CommonResult<Long> createMenu(@Valid @RequestBody MenuCreateReqVO reqVO) { | |
| 36 | - Long menuId = menuService.createMenu(reqVO); | |
| 38 | + public CommonResult<Long> createMenu(@Valid @RequestBody MenuSaveVO createReqVO) { | |
| 39 | + Long menuId = menuService.createMenu(createReqVO); | |
| 37 | 40 | return success(menuId); |
| 38 | 41 | } |
| 39 | 42 | |
| 40 | 43 | @PutMapping("/update") |
| 41 | 44 | @Operation(summary = "修改菜单") |
| 42 | 45 | @PreAuthorize("@ss.hasPermission('system:menu:update')") |
| 43 | - public CommonResult<Boolean> updateMenu(@Valid @RequestBody MenuUpdateReqVO reqVO) { | |
| 44 | - menuService.updateMenu(reqVO); | |
| 46 | + public CommonResult<Boolean> updateMenu(@Valid @RequestBody MenuSaveVO updateReqVO) { | |
| 47 | + menuService.updateMenu(updateReqVO); | |
| 45 | 48 | return success(true); |
| 46 | 49 | } |
| 47 | 50 | |
| ... | ... | @@ -60,20 +63,17 @@ public class MenuController { |
| 60 | 63 | public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) { |
| 61 | 64 | List<MenuDO> list = menuService.getMenuList(reqVO); |
| 62 | 65 | list.sort(Comparator.comparing(MenuDO::getSort)); |
| 63 | - return success(MenuConvert.INSTANCE.convertList(list)); | |
| 66 | + return success(BeanUtils.toBean(list, MenuRespVO.class)); | |
| 64 | 67 | } |
| 65 | 68 | |
| 66 | - @GetMapping("/list-all-simple") | |
| 69 | + @GetMapping({"/list-all-simple", "simple-list"}) | |
| 67 | 70 | @Operation(summary = "获取菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" + |
| 68 | 71 | "在多租户的场景下,会只返回租户所在套餐有的菜单") |
| 69 | 72 | public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() { |
| 70 | - // 获得菜单列表,只要开启状态的 | |
| 71 | - MenuListReqVO reqVO = new MenuListReqVO(); | |
| 72 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 73 | - List<MenuDO> list = menuService.getMenuListByTenant(reqVO); | |
| 74 | - // 排序后,返回给前端 | |
| 73 | + List<MenuDO> list = menuService.getMenuListByTenant( | |
| 74 | + new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); | |
| 75 | 75 | list.sort(Comparator.comparing(MenuDO::getSort)); |
| 76 | - return success(MenuConvert.INSTANCE.convertList02(list)); | |
| 76 | + return success(BeanUtils.toBean(list, MenuSimpleRespVO.class)); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | @GetMapping("/get") |
| ... | ... | @@ -81,7 +81,7 @@ public class MenuController { |
| 81 | 81 | @PreAuthorize("@ss.hasPermission('system:menu:query')") |
| 82 | 82 | public CommonResult<MenuRespVO> getMenu(Long id) { |
| 83 | 83 | MenuDO menu = menuService.getMenu(id); |
| 84 | - return success(MenuConvert.INSTANCE.convert(menu)); | |
| 84 | + return success(BeanUtils.toBean(menu, MenuRespVO.class)); | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/RoleController.java
| ... | ... | @@ -2,16 +2,17 @@ package cn.iocoder.yudao.module.system.controller.admin.permission; |
| 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 | 10 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.*; |
| 9 | -import cn.iocoder.yudao.module.system.convert.permission.RoleConvert; | |
| 10 | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 11 | 12 | import cn.iocoder.yudao.module.system.service.permission.RoleService; |
| 12 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 14 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 14 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 15 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | 16 | import org.springframework.security.access.prepost.PreAuthorize; |
| 16 | 17 | import org.springframework.validation.annotation.Validated; |
| 17 | 18 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -39,15 +40,15 @@ public class RoleController { |
| 39 | 40 | @PostMapping("/create") |
| 40 | 41 | @Operation(summary = "创建角色") |
| 41 | 42 | @PreAuthorize("@ss.hasPermission('system:role:create')") |
| 42 | - public CommonResult<Long> createRole(@Valid @RequestBody RoleCreateReqVO reqVO) { | |
| 43 | - return success(roleService.createRole(reqVO, null)); | |
| 43 | + public CommonResult<Long> createRole(@Valid @RequestBody RoleSaveReqVO createReqVO) { | |
| 44 | + return success(roleService.createRole(createReqVO, null)); | |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | @PutMapping("/update") |
| 47 | 48 | @Operation(summary = "修改角色") |
| 48 | 49 | @PreAuthorize("@ss.hasPermission('system:role:update')") |
| 49 | - public CommonResult<Boolean> updateRole(@Valid @RequestBody RoleUpdateReqVO reqVO) { | |
| 50 | - roleService.updateRole(reqVO); | |
| 50 | + public CommonResult<Boolean> updateRole(@Valid @RequestBody RoleSaveReqVO updateReqVO) { | |
| 51 | + roleService.updateRole(updateReqVO); | |
| 51 | 52 | return success(true); |
| 52 | 53 | } |
| 53 | 54 | |
| ... | ... | @@ -73,34 +74,35 @@ public class RoleController { |
| 73 | 74 | @PreAuthorize("@ss.hasPermission('system:role:query')") |
| 74 | 75 | public CommonResult<RoleRespVO> getRole(@RequestParam("id") Long id) { |
| 75 | 76 | RoleDO role = roleService.getRole(id); |
| 76 | - return success(RoleConvert.INSTANCE.convert(role)); | |
| 77 | + return success(BeanUtils.toBean(role, RoleRespVO.class)); | |
| 77 | 78 | } |
| 78 | 79 | |
| 79 | 80 | @GetMapping("/page") |
| 80 | 81 | @Operation(summary = "获得角色分页") |
| 81 | 82 | @PreAuthorize("@ss.hasPermission('system:role:query')") |
| 82 | - public CommonResult<PageResult<RoleDO>> getRolePage(RolePageReqVO reqVO) { | |
| 83 | - return success(roleService.getRolePage(reqVO)); | |
| 83 | + public CommonResult<PageResult<RoleRespVO>> getRolePage(RolePageReqVO pageReqVO) { | |
| 84 | + PageResult<RoleDO> pageResult = roleService.getRolePage(pageReqVO); | |
| 85 | + return success(BeanUtils.toBean(pageResult, RoleRespVO.class)); | |
| 84 | 86 | } |
| 85 | 87 | |
| 86 | 88 | @GetMapping("/list-all-simple") |
| 87 | 89 | @Operation(summary = "获取角色精简信息列表", description = "只包含被开启的角色,主要用于前端的下拉选项") |
| 88 | 90 | public CommonResult<List<RoleSimpleRespVO>> getSimpleRoleList() { |
| 89 | - // 获得角色列表,只要开启状态的 | |
| 90 | 91 | List<RoleDO> list = roleService.getRoleListByStatus(singleton(CommonStatusEnum.ENABLE.getStatus())); |
| 91 | - // 排序后,返回给前端 | |
| 92 | 92 | list.sort(Comparator.comparing(RoleDO::getSort)); |
| 93 | - return success(RoleConvert.INSTANCE.convertList02(list)); | |
| 93 | + return success(BeanUtils.toBean(list, RoleSimpleRespVO.class)); | |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - @GetMapping("/export") | |
| 96 | + @GetMapping("/export-excel") | |
| 97 | + @Operation(summary = "导出角色 Excel") | |
| 97 | 98 | @OperateLog(type = EXPORT) |
| 98 | 99 | @PreAuthorize("@ss.hasPermission('system:role:export')") |
| 99 | - public void export(HttpServletResponse response, @Validated RoleExportReqVO reqVO) throws IOException { | |
| 100 | - List<RoleDO> list = roleService.getRoleList(reqVO); | |
| 101 | - List<RoleExcelVO> data = RoleConvert.INSTANCE.convertList03(list); | |
| 100 | + public void export(HttpServletResponse response, @Validated RolePageReqVO exportReqVO) throws IOException { | |
| 101 | + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 102 | + List<RoleDO> list = roleService.getRolePage(exportReqVO).getList(); | |
| 102 | 103 | // 输出 |
| 103 | - ExcelUtils.write(response, "角色数据.xls", "角色列表", RoleExcelVO.class, data); | |
| 104 | + ExcelUtils.write(response, "角色数据.xls", "数据", RoleRespVO.class, | |
| 105 | + BeanUtils.toBean(list, RoleRespVO.class)); | |
| 104 | 106 | } |
| 105 | 107 | |
| 106 | 108 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | - | |
| 6 | -@Schema(description = "管理后台 - 菜单创建 Request VO") | |
| 7 | -@Data | |
| 8 | -@EqualsAndHashCode(callSuper = true) | |
| 9 | -public class MenuCreateReqVO extends MenuBaseVO { | |
| 10 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuRespVO.java
| ... | ... | @@ -6,21 +6,66 @@ import lombok.Data; |
| 6 | 6 | import lombok.EqualsAndHashCode; |
| 7 | 7 | import lombok.NoArgsConstructor; |
| 8 | 8 | |
| 9 | +import javax.validation.constraints.NotBlank; | |
| 10 | +import javax.validation.constraints.NotNull; | |
| 11 | +import javax.validation.constraints.Size; | |
| 9 | 12 | import java.time.LocalDateTime; |
| 10 | 13 | |
| 11 | 14 | @Schema(description = "管理后台 - 菜单信息 Response VO") |
| 12 | 15 | @Data |
| 13 | -@NoArgsConstructor | |
| 14 | -@AllArgsConstructor | |
| 15 | -@EqualsAndHashCode(callSuper = true) | |
| 16 | -public class MenuRespVO extends MenuBaseVO { | |
| 16 | +public class MenuRespVO { | |
| 17 | 17 | |
| 18 | 18 | @Schema(description = "菜单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 19 | 19 | private Long id; |
| 20 | 20 | |
| 21 | - @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 21 | + @Schema(description = "菜单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") | |
| 22 | + @NotBlank(message = "菜单名称不能为空") | |
| 23 | + @Size(max = 50, message = "菜单名称长度不能超过50个字符") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "权限标识,仅菜单类型为按钮时,才需要传递", example = "sys:menu:add") | |
| 27 | + @Size(max = 100) | |
| 28 | + private String permission; | |
| 29 | + | |
| 30 | + @Schema(description = "类型,参见 MenuTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 31 | + @NotNull(message = "菜单类型不能为空") | |
| 32 | + private Integer type; | |
| 33 | + | |
| 34 | + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 35 | + @NotNull(message = "显示顺序不能为空") | |
| 36 | + private Integer sort; | |
| 37 | + | |
| 38 | + @Schema(description = "父菜单 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 39 | + @NotNull(message = "父菜单 ID 不能为空") | |
| 40 | + private Long parentId; | |
| 41 | + | |
| 42 | + @Schema(description = "路由地址,仅菜单类型为菜单或者目录时,才需要传", example = "post") | |
| 43 | + @Size(max = 200, message = "路由地址不能超过200个字符") | |
| 44 | + private String path; | |
| 45 | + | |
| 46 | + @Schema(description = "菜单图标,仅菜单类型为菜单或者目录时,才需要传", example = "/menu/list") | |
| 47 | + private String icon; | |
| 48 | + | |
| 49 | + @Schema(description = "组件路径,仅菜单类型为菜单时,才需要传", example = "system/post/index") | |
| 50 | + @Size(max = 200, message = "组件路径不能超过255个字符") | |
| 51 | + private String component; | |
| 52 | + | |
| 53 | + @Schema(description = "组件名", example = "SystemUser") | |
| 54 | + private String componentName; | |
| 55 | + | |
| 56 | + @Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 57 | + @NotNull(message = "状态不能为空") | |
| 22 | 58 | private Integer status; |
| 23 | 59 | |
| 60 | + @Schema(description = "是否可见", example = "false") | |
| 61 | + private Boolean visible; | |
| 62 | + | |
| 63 | + @Schema(description = "是否缓存", example = "false") | |
| 64 | + private Boolean keepAlive; | |
| 65 | + | |
| 66 | + @Schema(description = "是否总是显示", example = "false") | |
| 67 | + private Boolean alwaysShow; | |
| 68 | + | |
| 24 | 69 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") |
| 25 | 70 | private LocalDateTime createTime; |
| 26 | 71 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSaveVO.java
| ... | ... | @@ -7,12 +7,12 @@ import javax.validation.constraints.NotBlank; |
| 7 | 7 | import javax.validation.constraints.NotNull; |
| 8 | 8 | import javax.validation.constraints.Size; |
| 9 | 9 | |
| 10 | -/** | |
| 11 | - * 菜单 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 12 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 13 | - */ | |
| 10 | +@Schema(description = "管理后台 - 菜单创建/修改 Request VO") | |
| 14 | 11 | @Data |
| 15 | -public class MenuBaseVO { | |
| 12 | +public class MenuSaveVO { | |
| 13 | + | |
| 14 | + @Schema(description = "菜单编号", example = "1024") | |
| 15 | + private Long id; | |
| 16 | 16 | |
| 17 | 17 | @Schema(description = "菜单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
| 18 | 18 | @NotBlank(message = "菜单名称不能为空") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuSimpleRespVO.java
| ... | ... | @@ -9,8 +9,6 @@ import javax.validation.constraints.NotNull; |
| 9 | 9 | |
| 10 | 10 | @Schema(description = "管理后台 - 菜单精简信息 Response VO") |
| 11 | 11 | @Data |
| 12 | -@NoArgsConstructor | |
| 13 | -@AllArgsConstructor | |
| 14 | 12 | public class MenuSimpleRespVO { |
| 15 | 13 | |
| 16 | 14 | @Schema(description = "菜单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/menu/MenuUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.*; | |
| 5 | - | |
| 6 | -import javax.validation.constraints.NotNull; | |
| 7 | - | |
| 8 | -@Schema(description = "管理后台 - 菜单更新 Request VO") | |
| 9 | -@Data | |
| 10 | -@EqualsAndHashCode(callSuper = true) | |
| 11 | -public class MenuUpdateReqVO extends MenuBaseVO { | |
| 12 | - | |
| 13 | - @Schema(description = "菜单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | - @NotNull(message = "菜单编号不能为空") | |
| 15 | - private Long id; | |
| 16 | - | |
| 17 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/permission/PermissionAssignRoleDataScopeReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.permission.vo.permission; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 4 | +import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 6 | import lombok.Data; |
| 5 | 7 | |
| ... | ... | @@ -17,7 +19,7 @@ public class PermissionAssignRoleDataScopeReqVO { |
| 17 | 19 | |
| 18 | 20 | @Schema(description = "数据范围,参见 DataScopeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 19 | 21 | @NotNull(message = "数据范围不能为空") |
| 20 | -// TODO 这里要多一个枚举校验 | |
| 22 | + @InEnum(value = DataScopeEnum.class, message = "数据范围必须是 {value}") | |
| 21 | 23 | private Integer dataScope; |
| 22 | 24 | |
| 23 | 25 | @Schema(description = "部门编号列表,只有范围类型为 DEPT_CUSTOM 时,该字段才需要", example = "1,3,5") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; | |
| 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 RoleCreateReqVO extends RoleBaseVO { | |
| 11 | - | |
| 12 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; | |
| 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 RoleExcelVO { | |
| 14 | - | |
| 15 | - @ExcelProperty("角色序号") | |
| 16 | - private Long id; | |
| 17 | - | |
| 18 | - @ExcelProperty("角色名称") | |
| 19 | - private String name; | |
| 20 | - | |
| 21 | - @ExcelProperty("角色标志") | |
| 22 | - private String code; | |
| 23 | - | |
| 24 | - @ExcelProperty("角色排序") | |
| 25 | - private Integer sort; | |
| 26 | - | |
| 27 | - @ExcelProperty("数据范围") | |
| 28 | - private Integer dataScope; | |
| 29 | - | |
| 30 | - @ExcelProperty(value = "角色状态", converter = DictConvert.class) | |
| 31 | - @DictFormat(DictTypeConstants.COMMON_STATUS) | |
| 32 | - private String status; | |
| 33 | - | |
| 34 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleExportReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; | |
| 2 | - | |
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | -import lombok.Data; | |
| 5 | -import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | - | |
| 7 | -import java.time.LocalDateTime; | |
| 8 | - | |
| 9 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | - | |
| 11 | -@Schema(description = "管理后台 - 角色分页 Request VO") | |
| 12 | -@Data | |
| 13 | -public class RoleExportReqVO { | |
| 14 | - | |
| 15 | - @Schema(description = "角色名称,模糊匹配", example = "芋道") | |
| 16 | - private String name; | |
| 17 | - | |
| 18 | - @Schema(description = "角色标识,模糊匹配", example = "yudao") | |
| 19 | - private String code; | |
| 20 | - | |
| 21 | - @Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1") | |
| 22 | - private Integer status; | |
| 23 | - | |
| 24 | - @Schema(description = "开始时间", example = "[2022-07-01 00:00:00,2022-07-01 23:59:59]") | |
| 25 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 26 | - private LocalDateTime[] createTime; | |
| 27 | - | |
| 28 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleRespVO.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; |
| 2 | 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.ExcelIgnoreUnannotated; | |
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 3 | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.AllArgsConstructor; | |
| 5 | 9 | import lombok.Data; |
| 6 | -import lombok.EqualsAndHashCode; | |
| 7 | -import lombok.NoArgsConstructor; | |
| 8 | 10 | |
| 11 | +import javax.validation.constraints.NotBlank; | |
| 9 | 12 | import java.time.LocalDateTime; |
| 10 | 13 | import java.util.Set; |
| 11 | 14 | |
| 12 | 15 | @Schema(description = "管理后台 - 角色信息 Response VO") |
| 13 | 16 | @Data |
| 14 | -@NoArgsConstructor | |
| 15 | -@AllArgsConstructor | |
| 16 | -@EqualsAndHashCode(callSuper = true) | |
| 17 | -public class RoleRespVO extends RoleBaseVO { | |
| 17 | +@ExcelIgnoreUnannotated | |
| 18 | +public class RoleRespVO { | |
| 18 | 19 | |
| 19 | 20 | @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 21 | + @ExcelProperty("角色序号") | |
| 20 | 22 | private Long id; |
| 21 | 23 | |
| 22 | - @Schema(description = "数据范围,参见 DataScopeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 23 | - private Integer dataScope; | |
| 24 | + @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "管理员") | |
| 25 | + @ExcelProperty("角色名称") | |
| 26 | + private String name; | |
| 24 | 27 | |
| 25 | - @Schema(description = "数据范围(指定部门数组)", example = "1") | |
| 26 | - private Set<Long> dataScopeDeptIds; | |
| 28 | + @NotBlank(message = "角色标志不能为空") | |
| 29 | + @ExcelProperty("角色标志") | |
| 30 | + private String code; | |
| 31 | + | |
| 32 | + @Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 33 | + @ExcelProperty("角色排序") | |
| 34 | + private Integer sort; | |
| 27 | 35 | |
| 28 | 36 | @Schema(description = "状态,参见 CommonStatusEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 37 | + @ExcelProperty(value = "角色状态", converter = DictConvert.class) | |
| 38 | + @DictFormat(DictTypeConstants.COMMON_STATUS) | |
| 29 | 39 | private Integer status; |
| 30 | 40 | |
| 31 | 41 | @Schema(description = "角色类型,参见 RoleTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 32 | 42 | private Integer type; |
| 33 | 43 | |
| 44 | + @Schema(description = "备注", example = "我是一个角色") | |
| 45 | + private String remark; | |
| 46 | + | |
| 47 | + @Schema(description = "数据范围,参见 DataScopeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 48 | + @ExcelProperty("数据范围") | |
| 49 | + private Integer dataScope; | |
| 50 | + | |
| 51 | + @Schema(description = "数据范围(指定部门数组)", example = "1") | |
| 52 | + private Set<Long> dataScopeDeptIds; | |
| 53 | + | |
| 34 | 54 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式") |
| 35 | 55 | private LocalDateTime createTime; |
| 36 | 56 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleBaseVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSaveReqVO.java
| ... | ... | @@ -7,12 +7,12 @@ import javax.validation.constraints.NotBlank; |
| 7 | 7 | import javax.validation.constraints.NotNull; |
| 8 | 8 | import javax.validation.constraints.Size; |
| 9 | 9 | |
| 10 | -/** | |
| 11 | - * 角色 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 12 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 13 | - */ | |
| 10 | +@Schema(description = "管理后台 - 角色创建 Request VO") | |
| 14 | 11 | @Data |
| 15 | -public class RoleBaseVO { | |
| 12 | +public class RoleSaveReqVO { | |
| 13 | + | |
| 14 | + @Schema(description = "角色编号", example = "1") | |
| 15 | + private Long id; | |
| 16 | 16 | |
| 17 | 17 | @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "管理员") |
| 18 | 18 | @NotBlank(message = "角色名称不能为空") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleSimpleRespVO.java
| ... | ... | @@ -7,8 +7,6 @@ import lombok.NoArgsConstructor; |
| 7 | 7 | |
| 8 | 8 | @Schema(description = "管理后台 - 角色精简信息 Response VO") |
| 9 | 9 | @Data |
| 10 | -@NoArgsConstructor | |
| 11 | -@AllArgsConstructor | |
| 12 | 10 | public class RoleSimpleRespVO { |
| 13 | 11 | |
| 14 | 12 | @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/permission/vo/role/RoleUpdateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.permission.vo.role; | |
| 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 RoleUpdateReqVO extends RoleBaseVO { | |
| 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/permission/MenuConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.permission; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; | |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuRespVO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; | |
| 8 | -import org.mapstruct.Mapper; | |
| 9 | -import org.mapstruct.factory.Mappers; | |
| 10 | - | |
| 11 | -import java.util.List; | |
| 12 | - | |
| 13 | -@Mapper | |
| 14 | -public interface MenuConvert { | |
| 15 | - | |
| 16 | - MenuConvert INSTANCE = Mappers.getMapper(MenuConvert.class); | |
| 17 | - | |
| 18 | - List<MenuRespVO> convertList(List<MenuDO> list); | |
| 19 | - | |
| 20 | - MenuDO convert(MenuCreateReqVO bean); | |
| 21 | - | |
| 22 | - MenuDO convert(MenuUpdateReqVO bean); | |
| 23 | - | |
| 24 | - MenuRespVO convert(MenuDO bean); | |
| 25 | - | |
| 26 | - List<MenuSimpleRespVO> convertList02(List<MenuDO> list); | |
| 27 | - | |
| 28 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/permission/RoleConvert.java deleted
| 1 | -package cn.iocoder.yudao.module.system.convert.permission; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.*; | |
| 4 | -import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; | |
| 5 | -import cn.iocoder.yudao.module.system.service.permission.bo.RoleCreateReqBO; | |
| 6 | -import org.mapstruct.Mapper; | |
| 7 | -import org.mapstruct.factory.Mappers; | |
| 8 | - | |
| 9 | -import java.util.List; | |
| 10 | - | |
| 11 | -@Mapper | |
| 12 | -public interface RoleConvert { | |
| 13 | - | |
| 14 | - RoleConvert INSTANCE = Mappers.getMapper(RoleConvert.class); | |
| 15 | - | |
| 16 | - RoleDO convert(RoleUpdateReqVO bean); | |
| 17 | - | |
| 18 | - RoleRespVO convert(RoleDO bean); | |
| 19 | - | |
| 20 | - RoleDO convert(RoleCreateReqVO bean); | |
| 21 | - | |
| 22 | - List<RoleSimpleRespVO> convertList02(List<RoleDO> list); | |
| 23 | - | |
| 24 | - List<RoleExcelVO> convertList03(List<RoleDO> list); | |
| 25 | - | |
| 26 | - RoleDO convert(RoleCreateReqBO bean); | |
| 27 | - | |
| 28 | -} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMapper.java
| ... | ... | @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; | |
| 8 | 7 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 10 | 9 | import org.apache.ibatis.annotations.Mapper; |
| ... | ... | @@ -25,14 +24,6 @@ public interface RoleMapper extends BaseMapperX<RoleDO> { |
| 25 | 24 | .orderByDesc(RoleDO::getId)); |
| 26 | 25 | } |
| 27 | 26 | |
| 28 | - default List<RoleDO> selectList(RoleExportReqVO reqVO) { | |
| 29 | - return selectList(new LambdaQueryWrapperX<RoleDO>() | |
| 30 | - .likeIfPresent(RoleDO::getName, reqVO.getName()) | |
| 31 | - .likeIfPresent(RoleDO::getCode, reqVO.getCode()) | |
| 32 | - .eqIfPresent(RoleDO::getStatus, reqVO.getStatus()) | |
| 33 | - .betweenIfPresent(BaseDO::getCreateTime, reqVO.getCreateTime())); | |
| 34 | - } | |
| 35 | - | |
| 36 | 27 | default RoleDO selectByName(String name) { |
| 37 | 28 | return selectOne(RoleDO::getName, name); |
| 38 | 29 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuService.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.permission; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; | |
| 3 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; | |
| 4 | 4 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; | |
| 6 | 5 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 7 | 6 | |
| 8 | 7 | import java.util.Collection; |
| ... | ... | @@ -18,17 +17,17 @@ public interface MenuService { |
| 18 | 17 | /** |
| 19 | 18 | * 创建菜单 |
| 20 | 19 | * |
| 21 | - * @param reqVO 菜单信息 | |
| 20 | + * @param createReqVO 菜单信息 | |
| 22 | 21 | * @return 创建出来的菜单编号 |
| 23 | 22 | */ |
| 24 | - Long createMenu(MenuCreateReqVO reqVO); | |
| 23 | + Long createMenu(MenuSaveVO createReqVO); | |
| 25 | 24 | |
| 26 | 25 | /** |
| 27 | 26 | * 更新菜单 |
| 28 | 27 | * |
| 29 | - * @param reqVO 菜单信息 | |
| 28 | + * @param updateReqVO 菜单信息 | |
| 30 | 29 | */ |
| 31 | - void updateMenu(MenuUpdateReqVO reqVO); | |
| 30 | + void updateMenu(MenuSaveVO updateReqVO); | |
| 32 | 31 | |
| 33 | 32 | /** |
| 34 | 33 | * 删除菜单 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.permission; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; | |
| 5 | 6 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; | |
| 7 | -import cn.iocoder.yudao.module.system.convert.permission.MenuConvert; | |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper; |
| 10 | 9 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| ... | ... | @@ -45,16 +44,16 @@ public class MenuServiceImpl implements MenuService { |
| 45 | 44 | private TenantService tenantService; |
| 46 | 45 | |
| 47 | 46 | @Override |
| 48 | - @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#reqVO.permission", | |
| 49 | - condition = "#reqVO.permission != null") | |
| 50 | - public Long createMenu(MenuCreateReqVO reqVO) { | |
| 47 | + @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#createReqVO.permission", | |
| 48 | + condition = "#createReqVO.permission != null") | |
| 49 | + public Long createMenu(MenuSaveVO createReqVO) { | |
| 51 | 50 | // 校验父菜单存在 |
| 52 | - validateParentMenu(reqVO.getParentId(), null); | |
| 51 | + validateParentMenu(createReqVO.getParentId(), null); | |
| 53 | 52 | // 校验菜单(自己) |
| 54 | - validateMenu(reqVO.getParentId(), reqVO.getName(), null); | |
| 53 | + validateMenu(createReqVO.getParentId(), createReqVO.getName(), null); | |
| 55 | 54 | |
| 56 | 55 | // 插入数据库 |
| 57 | - MenuDO menu = MenuConvert.INSTANCE.convert(reqVO); | |
| 56 | + MenuDO menu = BeanUtils.toBean(createReqVO, MenuDO.class); | |
| 58 | 57 | initMenuProperty(menu); |
| 59 | 58 | menuMapper.insert(menu); |
| 60 | 59 | // 返回 |
| ... | ... | @@ -64,20 +63,20 @@ public class MenuServiceImpl implements MenuService { |
| 64 | 63 | @Override |
| 65 | 64 | @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, |
| 66 | 65 | allEntries = true) // allEntries 清空所有缓存,因为 permission 如果变更,涉及到新老两个 permission。直接清理,简单有效 |
| 67 | - public void updateMenu(MenuUpdateReqVO reqVO) { | |
| 66 | + public void updateMenu(MenuSaveVO updateReqVO) { | |
| 68 | 67 | // 校验更新的菜单是否存在 |
| 69 | - if (menuMapper.selectById(reqVO.getId()) == null) { | |
| 68 | + if (menuMapper.selectById(updateReqVO.getId()) == null) { | |
| 70 | 69 | throw exception(MENU_NOT_EXISTS); |
| 71 | 70 | } |
| 72 | 71 | // 校验父菜单存在 |
| 73 | - validateParentMenu(reqVO.getParentId(), reqVO.getId()); | |
| 72 | + validateParentMenu(updateReqVO.getParentId(), updateReqVO.getId()); | |
| 74 | 73 | // 校验菜单(自己) |
| 75 | - validateMenu(reqVO.getParentId(), reqVO.getName(), reqVO.getId()); | |
| 74 | + validateMenu(updateReqVO.getParentId(), updateReqVO.getName(), updateReqVO.getId()); | |
| 76 | 75 | |
| 77 | 76 | // 更新到数据库 |
| 78 | - MenuDO updateObject = MenuConvert.INSTANCE.convert(reqVO); | |
| 79 | - initMenuProperty(updateObject); | |
| 80 | - menuMapper.updateById(updateObject); | |
| 77 | + MenuDO updateObj = BeanUtils.toBean(updateReqVO, MenuDO.class); | |
| 78 | + initMenuProperty(updateObj); | |
| 79 | + menuMapper.updateById(updateObj); | |
| 81 | 80 | } |
| 82 | 81 | |
| 83 | 82 | @Override | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleService.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.permission; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; | |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; | |
| 6 | 4 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleUpdateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; | |
| 8 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 9 | 7 | |
| 10 | 8 | import javax.validation.Valid; |
| ... | ... | @@ -22,18 +20,18 @@ public interface RoleService { |
| 22 | 20 | /** |
| 23 | 21 | * 创建角色 |
| 24 | 22 | * |
| 25 | - * @param reqVO 创建角色信息 | |
| 23 | + * @param createReqVO 创建角色信息 | |
| 26 | 24 | * @param type 角色类型 |
| 27 | 25 | * @return 角色编号 |
| 28 | 26 | */ |
| 29 | - Long createRole(@Valid RoleCreateReqVO reqVO, Integer type); | |
| 27 | + Long createRole(@Valid RoleSaveReqVO createReqVO, Integer type); | |
| 30 | 28 | |
| 31 | 29 | /** |
| 32 | 30 | * 更新角色 |
| 33 | 31 | * |
| 34 | - * @param reqVO 更新角色信息 | |
| 32 | + * @param updateReqVO 更新角色信息 | |
| 35 | 33 | */ |
| 36 | - void updateRole(@Valid RoleUpdateReqVO reqVO); | |
| 34 | + void updateRole(@Valid RoleSaveReqVO updateReqVO); | |
| 37 | 35 | |
| 38 | 36 | /** |
| 39 | 37 | * 删除角色 |
| ... | ... | @@ -115,14 +113,6 @@ public interface RoleService { |
| 115 | 113 | PageResult<RoleDO> getRolePage(RolePageReqVO reqVO); |
| 116 | 114 | |
| 117 | 115 | /** |
| 118 | - * 获得角色列表 | |
| 119 | - * | |
| 120 | - * @param reqVO 列表查询 | |
| 121 | - * @return 角色列表 | |
| 122 | - */ | |
| 123 | - List<RoleDO> getRoleList(RoleExportReqVO reqVO); | |
| 124 | - | |
| 125 | - /** | |
| 126 | 116 | * 判断角色编号数组中,是否有管理员 |
| 127 | 117 | * |
| 128 | 118 | * @param ids 角色编号数组 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java
| ... | ... | @@ -6,11 +6,9 @@ import cn.hutool.core.util.ObjectUtil; |
| 6 | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; | |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; | |
| 9 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 11 | 10 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; |
| 12 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleUpdateReqVO; | |
| 13 | -import cn.iocoder.yudao.module.system.convert.permission.RoleConvert; | |
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; | |
| 14 | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 15 | 13 | import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMapper; |
| 16 | 14 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| ... | ... | @@ -50,11 +48,11 @@ public class RoleServiceImpl implements RoleService { |
| 50 | 48 | |
| 51 | 49 | @Override |
| 52 | 50 | @Transactional(rollbackFor = Exception.class) |
| 53 | - public Long createRole(RoleCreateReqVO reqVO, Integer type) { | |
| 51 | + public Long createRole(RoleSaveReqVO createReqVO, Integer type) { | |
| 54 | 52 | // 校验角色 |
| 55 | - validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), null); | |
| 53 | + validateRoleDuplicate(createReqVO.getName(), createReqVO.getCode(), null); | |
| 56 | 54 | // 插入到数据库 |
| 57 | - RoleDO role = RoleConvert.INSTANCE.convert(reqVO); | |
| 55 | + RoleDO role = BeanUtils.toBean(createReqVO, RoleDO.class); | |
| 58 | 56 | role.setType(ObjectUtil.defaultIfNull(type, RoleTypeEnum.CUSTOM.getType())); |
| 59 | 57 | role.setStatus(CommonStatusEnum.ENABLE.getStatus()); |
| 60 | 58 | role.setDataScope(DataScopeEnum.ALL.getScope()); // 默认可查看所有数据。原因是,可能一些项目不需要项目权限 |
| ... | ... | @@ -64,15 +62,15 @@ public class RoleServiceImpl implements RoleService { |
| 64 | 62 | } |
| 65 | 63 | |
| 66 | 64 | @Override |
| 67 | - @CacheEvict(value = RedisKeyConstants.ROLE, key = "#reqVO.id") | |
| 68 | - public void updateRole(RoleUpdateReqVO reqVO) { | |
| 65 | + @CacheEvict(value = RedisKeyConstants.ROLE, key = "#updateReqVO.id") | |
| 66 | + public void updateRole(RoleSaveReqVO updateReqVO) { | |
| 69 | 67 | // 校验是否可以更新 |
| 70 | - validateRoleForUpdate(reqVO.getId()); | |
| 68 | + validateRoleForUpdate(updateReqVO.getId()); | |
| 71 | 69 | // 校验角色的唯一字段是否重复 |
| 72 | - validateRoleDuplicate(reqVO.getName(), reqVO.getCode(), reqVO.getId()); | |
| 70 | + validateRoleDuplicate(updateReqVO.getName(), updateReqVO.getCode(), updateReqVO.getId()); | |
| 73 | 71 | |
| 74 | 72 | // 更新到数据库 |
| 75 | - RoleDO updateObj = RoleConvert.INSTANCE.convert(reqVO); | |
| 73 | + RoleDO updateObj = BeanUtils.toBean(updateReqVO, RoleDO.class); | |
| 76 | 74 | roleMapper.updateById(updateObj); |
| 77 | 75 | } |
| 78 | 76 | |
| ... | ... | @@ -209,11 +207,6 @@ public class RoleServiceImpl implements RoleService { |
| 209 | 207 | } |
| 210 | 208 | |
| 211 | 209 | @Override |
| 212 | - public List<RoleDO> getRoleList(RoleExportReqVO reqVO) { | |
| 213 | - return roleMapper.selectList(reqVO); | |
| 214 | - } | |
| 215 | - | |
| 216 | - @Override | |
| 217 | 210 | public boolean hasAnySuperAdmin(Collection<Long> ids) { |
| 218 | 211 | if (CollectionUtil.isEmpty(ids)) { |
| 219 | 212 | return false; | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java
| ... | ... | @@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.common.util.date.DateUtils; |
| 11 | 11 | import cn.iocoder.yudao.framework.tenant.config.TenantProperties; |
| 12 | 12 | import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
| 13 | 13 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 14 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; | |
| 14 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; | |
| 15 | 15 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantCreateReqVO; |
| 16 | 16 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantExportReqVO; |
| 17 | 17 | import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; |
| ... | ... | @@ -130,7 +130,7 @@ public class TenantServiceImpl implements TenantService { |
| 130 | 130 | |
| 131 | 131 | private Long createRole(TenantPackageDO tenantPackage) { |
| 132 | 132 | // 创建角色 |
| 133 | - RoleCreateReqVO reqVO = new RoleCreateReqVO(); | |
| 133 | + RoleSaveReqVO reqVO = new RoleSaveReqVO(); | |
| 134 | 134 | reqVO.setName(RoleCodeEnum.TENANT_ADMIN.getName()).setCode(RoleCodeEnum.TENANT_ADMIN.getCode()) |
| 135 | 135 | .setSort(0).setRemark("系统自动生成"); |
| 136 | 136 | Long roleId = roleService.createRole(reqVO, RoleTypeEnum.SYSTEM.getType()); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImplTest.java
| ... | ... | @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.system.service.permission; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuCreateReqVO; | |
| 6 | 5 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuUpdateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.menu.MenuSaveVO; | |
| 8 | 7 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
| 9 | 8 | import cn.iocoder.yudao.module.system.dal.mysql.permission.MenuMapper; |
| 10 | 9 | import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum; |
| ... | ... | @@ -14,7 +13,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; |
| 14 | 13 | import org.springframework.context.annotation.Import; |
| 15 | 14 | |
| 16 | 15 | import javax.annotation.Resource; |
| 17 | -import java.util.*; | |
| 16 | +import java.util.List; | |
| 17 | +import java.util.Set; | |
| 18 | 18 | |
| 19 | 19 | import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet; |
| 20 | 20 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| ... | ... | @@ -51,16 +51,16 @@ public class MenuServiceImplTest extends BaseDbUnitTest { |
| 51 | 51 | menuMapper.insert(menuDO); |
| 52 | 52 | Long parentId = menuDO.getId(); |
| 53 | 53 | // 准备参数 |
| 54 | - MenuCreateReqVO reqVO = randomPojo(MenuCreateReqVO.class, o -> { | |
| 54 | + MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> { | |
| 55 | 55 | o.setParentId(parentId); |
| 56 | 56 | o.setName("testSonName"); |
| 57 | 57 | o.setType(MenuTypeEnum.MENU.getType()); |
| 58 | - }); | |
| 58 | + }).setId(null); // 防止 id 被赋值 | |
| 59 | 59 | Long menuId = menuService.createMenu(reqVO); |
| 60 | 60 | |
| 61 | 61 | // 校验记录的属性是否正确 |
| 62 | 62 | MenuDO dbMenu = menuMapper.selectById(menuId); |
| 63 | - assertPojoEquals(reqVO, dbMenu); | |
| 63 | + assertPojoEquals(reqVO, dbMenu, "id"); | |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | @Test |
| ... | ... | @@ -69,7 +69,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest { |
| 69 | 69 | MenuDO sonMenuDO = createParentAndSonMenu(); |
| 70 | 70 | Long sonId = sonMenuDO.getId(); |
| 71 | 71 | // 准备参数 |
| 72 | - MenuUpdateReqVO reqVO = randomPojo(MenuUpdateReqVO.class, o -> { | |
| 72 | + MenuSaveVO reqVO = randomPojo(MenuSaveVO.class, o -> { | |
| 73 | 73 | o.setId(sonId); |
| 74 | 74 | o.setName("testSonName"); // 修改名字 |
| 75 | 75 | o.setParentId(sonMenuDO.getParentId()); |
| ... | ... | @@ -86,7 +86,7 @@ public class MenuServiceImplTest extends BaseDbUnitTest { |
| 86 | 86 | @Test |
| 87 | 87 | public void testUpdateMenu_sonIdNotExist() { |
| 88 | 88 | // 准备参数 |
| 89 | - MenuUpdateReqVO reqVO = randomPojo(MenuUpdateReqVO.class); | |
| 89 | + MenuSaveVO reqVO = randomPojo(MenuSaveVO.class); | |
| 90 | 90 | // 调用,并断言异常 |
| 91 | 91 | assertServiceException(() -> menuService.updateMenu(reqVO), MENU_NOT_EXISTS); |
| 92 | 92 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImplTest.java
| ... | ... | @@ -4,10 +4,8 @@ import cn.hutool.extra.spring.SpringUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleCreateReqVO; | |
| 8 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleExportReqVO; | |
| 9 | 7 | import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; |
| 10 | -import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleUpdateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; | |
| 11 | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| 12 | 10 | import cn.iocoder.yudao.module.system.dal.mysql.permission.RoleMapper; |
| 13 | 11 | import cn.iocoder.yudao.module.system.enums.permission.DataScopeEnum; |
| ... | ... | @@ -52,13 +50,14 @@ public class RoleServiceImplTest extends BaseDbUnitTest { |
| 52 | 50 | @Test |
| 53 | 51 | public void testCreateRole() { |
| 54 | 52 | // 准备参数 |
| 55 | - RoleCreateReqVO reqVO = randomPojo(RoleCreateReqVO.class); | |
| 53 | + RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class) | |
| 54 | + .setId(null); // 防止 id 被赋值 | |
| 56 | 55 | |
| 57 | 56 | // 调用 |
| 58 | 57 | Long roleId = roleService.createRole(reqVO, null); |
| 59 | 58 | // 断言 |
| 60 | 59 | RoleDO roleDO = roleMapper.selectById(roleId); |
| 61 | - assertPojoEquals(reqVO, roleDO); | |
| 60 | + assertPojoEquals(reqVO, roleDO, "id"); | |
| 62 | 61 | assertEquals(RoleTypeEnum.CUSTOM.getType(), roleDO.getType()); |
| 63 | 62 | assertEquals(CommonStatusEnum.ENABLE.getStatus(), roleDO.getStatus()); |
| 64 | 63 | assertEquals(DataScopeEnum.ALL.getScope(), roleDO.getDataScope()); |
| ... | ... | @@ -71,7 +70,7 @@ public class RoleServiceImplTest extends BaseDbUnitTest { |
| 71 | 70 | roleMapper.insert(roleDO); |
| 72 | 71 | // 准备参数 |
| 73 | 72 | Long id = roleDO.getId(); |
| 74 | - RoleUpdateReqVO reqVO = randomPojo(RoleUpdateReqVO.class, o -> o.setId(id)); | |
| 73 | + RoleSaveReqVO reqVO = randomPojo(RoleSaveReqVO.class, o -> o.setId(id)); | |
| 75 | 74 | |
| 76 | 75 | // 调用 |
| 77 | 76 | roleService.updateRole(reqVO); |
| ... | ... | @@ -257,36 +256,6 @@ public class RoleServiceImplTest extends BaseDbUnitTest { |
| 257 | 256 | } |
| 258 | 257 | |
| 259 | 258 | @Test |
| 260 | - public void testGetRoleList() { | |
| 261 | - // mock 数据 | |
| 262 | - RoleDO dbRole = randomPojo(RoleDO.class, o -> { // 等会查询到 | |
| 263 | - o.setName("土豆"); | |
| 264 | - o.setCode("tudou"); | |
| 265 | - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 266 | - o.setCreateTime(buildTime(2022, 2, 8)); | |
| 267 | - }); | |
| 268 | - roleMapper.insert(dbRole); | |
| 269 | - // 测试 name 不匹配 | |
| 270 | - roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setName("红薯"))); | |
| 271 | - // 测试 code 不匹配 | |
| 272 | - roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCode("hong"))); | |
| 273 | - // 测试 createTime 不匹配 | |
| 274 | - roleMapper.insert(cloneIgnoreId(dbRole, o -> o.setCreateTime(buildTime(2022, 2, 16)))); | |
| 275 | - // 准备参数 | |
| 276 | - RoleExportReqVO reqVO = new RoleExportReqVO(); | |
| 277 | - reqVO.setName("土豆"); | |
| 278 | - reqVO.setCode("tu"); | |
| 279 | - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); | |
| 280 | - reqVO.setCreateTime(buildBetweenTime(2022, 2, 1, 2022, 2, 12)); | |
| 281 | - | |
| 282 | - // 调用 | |
| 283 | - List<RoleDO> list = roleService.getRoleList(reqVO); | |
| 284 | - // 断言 | |
| 285 | - assertEquals(1, list.size()); | |
| 286 | - assertPojoEquals(dbRole, list.get(0)); | |
| 287 | - } | |
| 288 | - | |
| 289 | - @Test | |
| 290 | 259 | public void testGetRolePage() { |
| 291 | 260 | // mock 数据 |
| 292 | 261 | RoleDO dbRole = randomPojo(RoleDO.class, o -> { // 等会查询到 | ... | ... |