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