diff --git a/src/main/java/com/nov/KgLowDurable/annotation/NotEmpty.java b/src/main/java/com/nov/KgLowDurable/annotation/NotEmpty.java new file mode 100644 index 0000000..a3bfe1f --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/annotation/NotEmpty.java @@ -0,0 +1,25 @@ +package com.nov.KgLowDurable.annotation; + +import com.auth0.jwt.interfaces.Payload; + +import java.lang.annotation.*; + +@Documented +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE}) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(NotEmpty.List.class) +public @interface NotEmpty { + String message() default "{jakarta.validation.constraints.NotEmpty.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; + + @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE}) + @Retention(RetentionPolicy.RUNTIME) + @Documented + public @interface List { + NotEmpty[] value(); + } +} + diff --git a/src/main/java/com/nov/KgLowDurable/controller/LdDictController.java b/src/main/java/com/nov/KgLowDurable/controller/LdDictController.java index 51e7ff3..d6559e8 100644 --- a/src/main/java/com/nov/KgLowDurable/controller/LdDictController.java +++ b/src/main/java/com/nov/KgLowDurable/controller/LdDictController.java @@ -1,28 +1,3 @@ -/** - * BladeX Commercial License Agreement - * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. - *

- * Use of this software is governed by the Commercial License Agreement - * obtained after purchasing a license from BladeX. - *

- * 1. This software is for development use only under a valid license - * from BladeX. - *

- * 2. Redistribution of this software's source code to any third party - * without a commercial license is strictly prohibited. - *

- * 3. Licensees may copyright their own code but cannot use segments - * from this software for such purposes. Copyright of this software - * remains with BladeX. - *

- * Using this software signifies agreement to this License, and the software - * must not be used for illegal purposes. - *

- * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is - * not liable for any claims arising from secondary or illegal development. - *

- * Author: Chill Zhuang (bladejava@qq.com) - */ package com.nov.KgLowDurable.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; diff --git a/src/main/java/com/nov/KgLowDurable/controller/LdRoleController.java b/src/main/java/com/nov/KgLowDurable/controller/LdRoleController.java new file mode 100644 index 0000000..048bace --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/controller/LdRoleController.java @@ -0,0 +1,88 @@ +package com.nov.KgLowDurable.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.nov.KgLowDurable.pojo.entity.Role; +import com.nov.KgLowDurable.pojo.entity.User; +import com.nov.KgLowDurable.pojo.vo.GrantVO; +import com.nov.KgLowDurable.pojo.vo.RoleVO; +import com.nov.KgLowDurable.service.IRoleService; +import com.nov.KgLowDurable.util.Condition; +import com.nov.KgLowDurable.util.Result; +import com.nov.KgLowDurable.wrapper.RoleWrapper; +import io.swagger.annotations.*; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + + +/** + * 控制器 + * + * @author Chill + */ +@RestController +@AllArgsConstructor +@RequestMapping("/role") +@Api(value = "角色", description = "角色") +public class LdRoleController { + + private final IRoleService roleService; + + /** + * 详情 + */ + @GetMapping("/detail") + @ApiOperation(value = "详情", notes = "传入role") + public Result detail(@RequestParam Long id) { + return Result.OK(roleService.getById(id)); + } + + /** + * 列表 + */ + @GetMapping("/list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "roleName", value = "参数名称"), + @ApiImplicitParam(name = "roleAlias", value = "角色别名") + }) + @ApiOperation(value = "列表", notes = "传入role") + public Result> list(@ApiParam(hidden = true) @RequestParam Map role) { + QueryWrapper queryWrapper = Condition.getQueryWrapper(role, Role.class); + List list = roleService.list(queryWrapper); + return Result.OK(RoleWrapper.build().listNodeVO(list)); + } + /** + * 新增或修改 + */ + @PostMapping("/submit") + @ApiOperation(value = "新增或修改", notes = "传入role") + public Result submit(@RequestBody Role role) { + return Result.OK(roleService.submit(role)); + } + + /** + * 删除 + */ + @PostMapping("/remove") + @ApiOperation(value = "删除", notes = "传入ids") + public Result remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { + return Result.OK(roleService.removeRole(ids)); + } + + /** + * 设置角色权限 + */ + @PostMapping("/grant") + @ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合") + public Result grant(@RequestBody GrantVO grantVO) { + try { + boolean temp = roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds(), grantVO.getDataScopeIds(), grantVO.getApiScopeIds()); + return Result.OK(temp); + } catch (Exception e) { + return Result.fail("操作失败"); + } + } + +} diff --git a/src/main/java/com/nov/KgLowDurable/controller/MenuController.java b/src/main/java/com/nov/KgLowDurable/controller/MenuController.java index 8748ea9..687dfa4 100644 --- a/src/main/java/com/nov/KgLowDurable/controller/MenuController.java +++ b/src/main/java/com/nov/KgLowDurable/controller/MenuController.java @@ -1,41 +1,19 @@ -/** - * BladeX Commercial License Agreement - * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. - *

- * Use of this software is governed by the Commercial License Agreement - * obtained after purchasing a license from BladeX. - *

- * 1. This software is for development use only under a valid license - * from BladeX. - *

- * 2. Redistribution of this software's source code to any third party - * without a commercial license is strictly prohibited. - *

- * 3. Licensees may copyright their own code but cannot use segments - * from this software for such purposes. Copyright of this software - * remains with BladeX. - *

- * Using this software signifies agreement to this License, and the software - * must not be used for illegal purposes. - *

- * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is - * not liable for any claims arising from secondary or illegal development. - *

- * Author: Chill Zhuang (bladejava@qq.com) - */ package com.nov.KgLowDurable.controller; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.nov.KgLowDurable.common.TreeNode; import com.nov.KgLowDurable.pojo.entity.Kv; import com.nov.KgLowDurable.pojo.entity.Menu; +import com.nov.KgLowDurable.pojo.vo.CheckedTreeVO; +import com.nov.KgLowDurable.pojo.vo.GrantTreeVO; import com.nov.KgLowDurable.pojo.vo.MenuVO; import com.nov.KgLowDurable.service.IMenuService; +import com.nov.KgLowDurable.service.ITopMenuService; import com.nov.KgLowDurable.util.Condition; +import com.nov.KgLowDurable.util.Func; import com.nov.KgLowDurable.util.Result; +import com.nov.KgLowDurable.util.StringUtils; import com.nov.KgLowDurable.wrapper.MenuWrapper; import io.swagger.annotations.*; - import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -55,7 +33,7 @@ import java.util.Map; public class MenuController { private final IMenuService menuService; - //private final ITopMenuService topMenuService; + private final ITopMenuService topMenuService; /** * 详情 @@ -128,12 +106,16 @@ public class MenuController { @PostMapping("/submit") @ApiOperation(value = "新增或修改", notes = "传入menu") public Result submit( @RequestBody Menu menu) { - if (menuService.submit(menu)) { - // 返回懒加载树更新节点所需字段 - Kv kv = Kv.create().set("id", String.valueOf(menu.getId())); - return Result.OK(kv); + try { + if (menuService.submit(menu)) { + // 返回懒加载树更新节点所需字段 + Kv kv = Kv.create().set("id", String.valueOf(menu.getId())); + return Result.OK(kv); + } + } catch (Exception e) { + return Result.fail("操作失败"); } - return Result.error("操作失败"); + return Result.fail("操作失败"); } @@ -149,35 +131,32 @@ public class MenuController { /** * 前端菜单数据 */ -// @GetMapping("/routes") -// @ApiOperationSupport(order = 8) -// @Operation(summary = "前端菜单数据", description = "前端菜单数据") -// public R> routes(BladeUser user, Long topMenuId) { -// List list = menuService.routes((user == null) ? null : user.getRoleId(), topMenuId); -// return R.data(list); -// } + @GetMapping("/routes") + @ApiOperation(value = "前端菜单数据", notes = "前端菜单数据") + public Result> routes(String roleId, Long topMenuId) { + List list = menuService.routes((roleId == null) ? null : roleId, topMenuId); + return Result.OK(list); + } /** * 前端菜单数据 */ // @GetMapping("/routes-ext") -// @ApiOperationSupport(order = 9) -// @Operation(summary = "前端菜单数据", description = "前端菜单数据") -// public R> routesExt(BladeUser user, Long topMenuId) { -// List list = menuService.routesExt(user.getRoleId(), topMenuId); -// return R.data(list); +// @ApiOperation(value = "前端菜单数据", notes = "前端菜单数据") +// public Result> routesExt(String roleId, Long topMenuId) { +// List list = menuService.routesExt(roleId, topMenuId); +// return Result.OK(list); // } /** * 前端按钮数据 */ -// @GetMapping("/buttons") -// @ApiOperationSupport(order = 10) -// @Operation(summary = "前端按钮数据", description = "前端按钮数据") -// public R> buttons(BladeUser user) { -// List list = menuService.buttons(user.getRoleId()); -// return R.data(list); -// } + @GetMapping("/buttons") + @ApiOperation(value = "前端按钮数据", notes = "前端按钮数据") + public Result> buttons(String roleId) { + List list = menuService.buttons(roleId); + return Result.OK(list); + } /** * 获取菜单树形结构 @@ -192,80 +171,81 @@ public class MenuController { /** * 获取权限分配树形结构 */ -// @GetMapping("/grant-tree") -// @ApiOperationSupport(order = 12) -// @Operation(summary = "权限分配树形结构", description = "权限分配树形结构") -// public R grantTree(BladeUser user) { -// GrantTreeVO vo = new GrantTreeVO(); -// vo.setMenu(menuService.grantTree(user)); + @GetMapping("/grant-tree") + @ApiOperation(value = "权限分配树形结构", notes = "权限分配树形结构") + public Result grantTree(String roleId) { + GrantTreeVO vo = new GrantTreeVO(); + if(StringUtils.isEmpty(roleId)){ + vo.setMenu(menuService.grantTreeALL()); + return Result.OK(vo); + } + vo.setMenu(menuService.grantTree(roleId)); // vo.setDataScope(menuService.grantDataScopeTree(user)); // vo.setApiScope(menuService.grantApiScopeTree(user)); -// return R.data(vo); -// } + return Result.OK(vo); + } /** * 获取权限分配树形结构 */ -// @GetMapping("/role-tree-keys") -// @ApiOperationSupport(order = 13) -// @Operation(summary = "角色所分配的树", description = "角色所分配的树") -// public R roleTreeKeys(String roleIds) { -// CheckedTreeVO vo = new CheckedTreeVO(); -// vo.setMenu(menuService.roleTreeKeys(roleIds)); + @GetMapping("/role-tree-keys") + @ApiOperation(value = "角色所分配的树", notes = "角色所分配的树") + public Result roleTreeKeys(String roleIds) { + if(StringUtils.isEmpty(roleIds)){ + return Result.error("请传roleIds",null); + } + CheckedTreeVO vo = new CheckedTreeVO(); + vo.setMenu(menuService.roleTreeKeys(roleIds)); // vo.setDataScope(menuService.dataScopeTreeKeys(roleIds)); // vo.setApiScope(menuService.apiScopeTreeKeys(roleIds)); -// return R.data(vo); -// } + return Result.OK(vo); + } /** * 获取顶部菜单树形结构 */ -// @GetMapping("/grant-top-tree") -// @ApiOperationSupport(order = 14) -// @Operation(summary = "顶部菜单树形结构", description = "顶部菜单树形结构") -// public R grantTopTree(BladeUser user) { -// GrantTreeVO vo = new GrantTreeVO(); -// vo.setMenu(menuService.grantTopTree(user)); -// return R.data(vo); -// } + @GetMapping("/grant-top-tree") + @ApiOperation(value = "顶部菜单树形结构", notes = "顶部菜单树形结构") + public Result grantTopTree(String roleId) { + GrantTreeVO vo = new GrantTreeVO(); + vo.setMenu(menuService.grantTopTree(roleId)); + return Result.OK(vo); + } /** * 获取顶部菜单树形结构 */ // @GetMapping("/top-tree-keys") -// @ApiOperationSupport(order = 15) -// @Operation(summary = "顶部菜单所分配的树", description = "顶部菜单所分配的树") -// public R topTreeKeys(String topMenuIds) { +// @ApiOperation(value = "顶部菜单所分配的树", notes = "顶部菜单所分配的树") +// public Result topTreeKeys(String topMenuIds) { // CheckedTreeVO vo = new CheckedTreeVO(); // vo.setMenu(menuService.topTreeKeys(topMenuIds)); -// return R.data(vo); +// return Result.OK(vo); // } /** * 顶部菜单数据 */ // @GetMapping("/top-menu") -// @ApiOperationSupport(order = 16) -// @Operation(summary = "顶部菜单数据", description = "顶部菜单数据") -// public R> topMenu(BladeUser user) { +// @ApiOperation(value = "顶部菜单数据", notes = "顶部菜单数据") +// public Result> topMenu(User user) { // if (Func.isEmpty(user)) { // return null; // } // List list = topMenuService.list(Wrappers.query().lambda().orderByAsc(TopMenu::getSort)); -// return R.data(list); +// return Result.OK(list); // } /** * 获取配置的角色权限 */ -// @GetMapping("auth-routes") -// @ApiOperationSupport(order = 17) -// @Operation(summary = "菜单的角色权限") -// public R> authRoutes(BladeUser user) { -// if (Func.isEmpty(user)) { -// return null; -// } -// return R.data(menuService.authRoutes(user)); -// } + @GetMapping("auth-routes") + @ApiOperation(value = "菜单的角色权限") + public Result> authRoutes(String roleId) { + if (Func.isEmpty(roleId)) { + return null; + } + return Result.OK(menuService.authRoutes(roleId)); + } } diff --git a/src/main/java/com/nov/KgLowDurable/controller/RoleController.java b/src/main/java/com/nov/KgLowDurable/controller/RoleController.java deleted file mode 100644 index 1e72a24..0000000 --- a/src/main/java/com/nov/KgLowDurable/controller/RoleController.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * BladeX Commercial License Agreement - * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. - *

- * Use of this software is governed by the Commercial License Agreement - * obtained after purchasing a license from BladeX. - *

- * 1. This software is for development use only under a valid license - * from BladeX. - *

- * 2. Redistribution of this software's source code to any third party - * without a commercial license is strictly prohibited. - *

- * 3. Licensees may copyright their own code but cannot use segments - * from this software for such purposes. Copyright of this software - * remains with BladeX. - *

- * Using this software signifies agreement to this License, and the software - * must not be used for illegal purposes. - *

- * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is - * not liable for any claims arising from secondary or illegal development. - *

- * Author: Chill Zhuang (bladejava@qq.com) - */ -package com.nov.KgLowDurable.controller; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.nov.KgLowDurable.pojo.entity.Role; -import com.nov.KgLowDurable.pojo.entity.User; -import com.nov.KgLowDurable.pojo.vo.RoleVO; -import com.nov.KgLowDurable.service.IRoleService; -import com.nov.KgLowDurable.util.Condition; -import com.nov.KgLowDurable.util.Result; -import com.nov.KgLowDurable.wrapper.RoleWrapper; -import io.swagger.annotations.*; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - - -/** - * 控制器 - * - * @author Chill - */ -@RestController -@AllArgsConstructor -@RequestMapping("/role") -@Api(value = "角色", description = "角色") -public class RoleController { - - private final IRoleService roleService; - - /** - * 详情 - */ - @GetMapping("/detail") - @ApiOperation(value = "详情", notes = "传入role") - public Result detail(@RequestParam Long id) { - return Result.OK(roleService.getById(id)); - } - - /** - * 列表 - */ - @GetMapping("/list") - @ApiImplicitParams({ - @ApiImplicitParam(name = "roleName", value = "参数名称"), - @ApiImplicitParam(name = "roleAlias", value = "角色别名") - }) - @ApiOperation(value = "列表", notes = "传入role") - public Result> list(@ApiParam(hidden = true) @RequestParam Map role) { - QueryWrapper queryWrapper = Condition.getQueryWrapper(role, Role.class); - List list = roleService.list(queryWrapper); - return Result.OK(RoleWrapper.build().listNodeVO(list)); - } - - /** - * 获取角色树形结构 - */ -// @GetMapping("/tree") -// @ApiOperation(value = "树形结构", notes = "树形结构") -// public Result> tree(Tuser bladeUser) { -// List tree = roleService.tree(bladeUser.getUserId()); -// return Result.OK(tree); -// } - - /** - * 获取指定角色树形结构 - */ - @GetMapping("/tree-by-id") - @ApiOperation(value = "树形结构", notes = "树形结构") - public Result> treeById(Long roleId, User bladeUser) { - List tree = roleService.tree(bladeUser.getUserId()); - return Result.OK(tree); - } - - /** - * 新增或修改 - */ - @PostMapping("/submit") - @ApiOperation(value = "新增或修改", notes = "传入role") - public Result submit(@RequestBody Role role) { - return Result.OK(roleService.submit(role)); - } - - /** - * 删除 - */ - @PostMapping("/remove") - @ApiOperation(value = "删除", notes = "传入ids") - public Result remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { - return Result.OK(roleService.removeRole(ids)); - } - - /** - * 设置角色权限 - */ -// @PostMapping("/grant") -// @ApiOperationSupport(order = 7) -// @Operation(summary = "权限设置", description = "传入roleId集合以及menuId集合") -// public R grant(@RequestBody GrantVO grantVO) { -// CacheUtil.clear(SYS_CACHE); -// CacheUtil.clear(SYS_CACHE, Boolean.FALSE); -// boolean temp = roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds(), grantVO.getDataScopeIds(), grantVO.getApiScopeIds()); -// return R.status(temp); -// } - - /** - * 下拉数据源 - */ -// @GetMapping("/select") -// @Operation(summary = "下拉数据源", description = "传入id集合") -// public R> select(Long userId, String roleId) { -// if (Func.isNotEmpty(userId)) { -// User user = UserCache.getUser(userId); -// roleId = user.getRoleId(); -// } -// List list = roleService.list(Wrappers.lambdaQuery().in(Role::getId, Func.toLongList(roleId))); -// return R.data(list); -// } - - /** - * 获取现有角色别名列表 - */ - @GetMapping("/alias") - @ApiOperation(value = "获取角色别名", notes = "获取角色别名") - public Result> alias() { - return Result.OK(roleService.alias()); - } - -} diff --git a/src/main/java/com/nov/KgLowDurable/enums/ResultCode.java b/src/main/java/com/nov/KgLowDurable/enums/ResultCode.java new file mode 100644 index 0000000..db1b3f9 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/enums/ResultCode.java @@ -0,0 +1,41 @@ +package com.nov.KgLowDurable.enums; + +import com.nov.KgLowDurable.exception.IResultCode; +import lombok.Generated; + +public enum ResultCode implements IResultCode { + SUCCESS(200, "操作成功"), + FAILURE(400, "业务异常"), + UN_AUTHORIZED(401, "请求未授权"), + CLIENT_UN_AUTHORIZED(401, "客户端请求未授权"), + NOT_FOUND(404, "404 没找到请求"), + MSG_NOT_READABLE(400, "消息不能读取"), + METHOD_NOT_SUPPORTED(405, "不支持当前请求方法"), + MEDIA_TYPE_NOT_SUPPORTED(415, "不支持当前媒体类型"), + REQ_REJECT(403, "请求被拒绝"), + INTERNAL_SERVER_ERROR(500, "请求未完成,请联系管理员"), + PARAM_MISS(400, "缺少必要的请求参数"), + PARAM_TYPE_ERROR(400, "请求参数类型错误"), + PARAM_BIND_ERROR(400, "请求参数绑定错误"), + PARAM_VALID_ERROR(400, "参数校验失败"); + + final int code; + final String message; + + @Generated + public int getCode() { + return this.code; + } + + @Generated + public String getMessage() { + return this.message; + } + + @Generated + private ResultCode(final int code, final String message) { + this.code = code; + this.message = message; + } +} + diff --git a/src/main/java/com/nov/KgLowDurable/exception/IResultCode.java b/src/main/java/com/nov/KgLowDurable/exception/IResultCode.java new file mode 100644 index 0000000..18b10a2 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/exception/IResultCode.java @@ -0,0 +1,9 @@ +package com.nov.KgLowDurable.exception; + +import java.io.Serializable; + +public interface IResultCode extends Serializable { + String getMessage(); + + int getCode(); +} diff --git a/src/main/java/com/nov/KgLowDurable/exception/ServiceException.java b/src/main/java/com/nov/KgLowDurable/exception/ServiceException.java new file mode 100644 index 0000000..42a9b03 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/exception/ServiceException.java @@ -0,0 +1,38 @@ +package com.nov.KgLowDurable.exception; + +import com.nov.KgLowDurable.enums.ResultCode; +import lombok.Generated; + +public class ServiceException extends RuntimeException { + private static final long serialVersionUID = 2359767895161832954L; + private final IResultCode resultCode; + + public ServiceException(String message) { + super(message); + this.resultCode = ResultCode.FAILURE; + } + + public ServiceException(IResultCode resultCode) { + super(resultCode.getMessage()); + this.resultCode = resultCode; + } + + public ServiceException(IResultCode resultCode, Throwable cause) { + super(cause); + this.resultCode = resultCode; + } + + public Throwable fillInStackTrace() { + return this; + } + + public Throwable doFillInStackTrace() { + return super.fillInStackTrace(); + } + + @Generated + public IResultCode getResultCode() { + return this.resultCode; + } +} + diff --git a/src/main/java/com/nov/KgLowDurable/mapper/MenuMapper.java b/src/main/java/com/nov/KgLowDurable/mapper/MenuMapper.java index 66d1f09..a485a45 100644 --- a/src/main/java/com/nov/KgLowDurable/mapper/MenuMapper.java +++ b/src/main/java/com/nov/KgLowDurable/mapper/MenuMapper.java @@ -205,4 +205,10 @@ public interface MenuMapper extends BaseMapper

{ * @return */ List authRoutes(List roleIds); + + /** + * 查询全部 + * @return + */ + List grantTreeByRoleALL(); } diff --git a/src/main/java/com/nov/KgLowDurable/mapper/TopMenuMapper.java b/src/main/java/com/nov/KgLowDurable/mapper/TopMenuMapper.java new file mode 100644 index 0000000..42b8780 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/mapper/TopMenuMapper.java @@ -0,0 +1,38 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package com.nov.KgLowDurable.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nov.KgLowDurable.pojo.entity.TopMenu; + +/** + * 顶部菜单表 Mapper 接口 + * + * @author BladeX + */ +public interface TopMenuMapper extends BaseMapper { + +} diff --git a/src/main/java/com/nov/KgLowDurable/mapper/TopMenuSettingMapper.java b/src/main/java/com/nov/KgLowDurable/mapper/TopMenuSettingMapper.java new file mode 100644 index 0000000..d28834b --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/mapper/TopMenuSettingMapper.java @@ -0,0 +1,38 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package com.nov.KgLowDurable.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nov.KgLowDurable.pojo.entity.TopMenuSetting; + +/** + * Mapper 接口 + * + * @author Chill + */ +public interface TopMenuSettingMapper extends BaseMapper { + +} diff --git a/src/main/java/com/nov/KgLowDurable/pojo/entity/Role.java b/src/main/java/com/nov/KgLowDurable/pojo/entity/Role.java index b48c9ef..9c86ea4 100644 --- a/src/main/java/com/nov/KgLowDurable/pojo/entity/Role.java +++ b/src/main/java/com/nov/KgLowDurable/pojo/entity/Role.java @@ -42,7 +42,7 @@ import java.io.Serializable; * @author Chill */ @Data -@TableName("blade_role") +@TableName("t_role") @Schema(description = "Role对象") public class Role implements Serializable { @@ -55,54 +55,15 @@ public class Role implements Serializable { @Schema(description = "主键") @TableId(value = "id", type = IdType.AUTO) private Long id; - - /** - * 租户ID - */ - @Schema(description = "租户ID") - private String tenantId; - - /** - * 父主键 - */ - @JsonSerialize(using = ToStringSerializer.class) - @Schema(description = "父主键") - private Long parentId; - /** * 角色名 */ @Schema(description = "角色名") - private String roleName; - - /** - * 排序 - */ - @Schema(description = "排序") - private Integer sort; - - /** - * 角色别名 - */ - @Schema(description = "角色别名") - private String roleAlias; - - /** - * 业务状态 - */ - @Schema(description = "业务状态") - private Integer status; - - /** - * 是否已删除 - */ - @TableLogic - @Schema(description = "是否已删除") - private Integer isDeleted; + private String name; @Schema(description = "角色编码") - private String roleCode; + private String code; } diff --git a/src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenu.java b/src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenu.java new file mode 100644 index 0000000..ed167b8 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenu.java @@ -0,0 +1,73 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package com.nov.KgLowDurable.pojo.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.nov.KgLowDurable.annotation.Schema; +import lombok.Data; + +import java.io.Serializable; + +/** + * 顶部菜单表实体类 + * + * @author BladeX + */ +@Data +@TableName("blade_top_menu") +@Schema(description = "顶部菜单表") +public class TopMenu implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 顶部菜单编号 + */ + @Schema(description = "顶部菜单编号") + private String code; + /** + * 顶部菜单名 + */ + @Schema(description = "顶部菜单名") + private String name; + /** + * 顶部菜单资源 + */ + @Schema(description = "顶部菜单资源") + private String source; + /** + * 顶部菜单路由 + */ + @Schema(description = "顶部菜单路由") + private String path; + /** + * 顶部菜单排序 + */ + @Schema(description = "顶部菜单排序") + private Integer sort; + + +} diff --git a/src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenuSetting.java b/src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenuSetting.java new file mode 100644 index 0000000..bb324fb --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenuSetting.java @@ -0,0 +1,38 @@ +package com.nov.KgLowDurable.pojo.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; + +/** + * TopMenuSetting + * + * @author Chill + */ +@Data +@TableName("blade_top_menu_setting") +public class TopMenuSetting { + + /** + * 主键id + */ + @JsonSerialize(using = ToStringSerializer.class) + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 顶部菜单id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long topMenuId; + + /** + * 菜单id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long menuId; + +} diff --git a/src/main/java/com/nov/KgLowDurable/pojo/vo/CheckedTreeVO.java b/src/main/java/com/nov/KgLowDurable/pojo/vo/CheckedTreeVO.java new file mode 100644 index 0000000..38d20a4 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/pojo/vo/CheckedTreeVO.java @@ -0,0 +1,16 @@ +package com.nov.KgLowDurable.pojo.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class CheckedTreeVO { + + private List menu; + + private List dataScope; + + private List apiScope; + +} diff --git a/src/main/java/com/nov/KgLowDurable/pojo/vo/GrantTreeVO.java b/src/main/java/com/nov/KgLowDurable/pojo/vo/GrantTreeVO.java new file mode 100644 index 0000000..0667924 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/pojo/vo/GrantTreeVO.java @@ -0,0 +1,21 @@ +package com.nov.KgLowDurable.pojo.vo; + +import com.nov.KgLowDurable.common.TreeNode; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class GrantTreeVO implements Serializable { + + private static final long serialVersionUID = 1L; + + private List menu; + + private List dataScope; + + private List apiScope; + +} + diff --git a/src/main/java/com/nov/KgLowDurable/pojo/vo/GrantVO.java b/src/main/java/com/nov/KgLowDurable/pojo/vo/GrantVO.java new file mode 100644 index 0000000..194c033 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/pojo/vo/GrantVO.java @@ -0,0 +1,28 @@ +package com.nov.KgLowDurable.pojo.vo; + +import com.nov.KgLowDurable.annotation.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class GrantVO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "roleIds集合") + private List roleIds; + + @Schema(description = "menuIds集合") + private List menuIds; + + @Schema(description = "topMenuIds集合") + private List topMenuIds; + + @Schema(description = "dataScopeIds集合") + private List dataScopeIds; + + @Schema(description = "apiScopeIds集合") + private List apiScopeIds; + +} diff --git a/src/main/java/com/nov/KgLowDurable/service/IMenuService.java b/src/main/java/com/nov/KgLowDurable/service/IMenuService.java index b603178..a324f40 100644 --- a/src/main/java/com/nov/KgLowDurable/service/IMenuService.java +++ b/src/main/java/com/nov/KgLowDurable/service/IMenuService.java @@ -27,7 +27,9 @@ package com.nov.KgLowDurable.service; import com.baomidou.mybatisplus.extension.service.IService; import com.nov.KgLowDurable.common.TreeNode; +import com.nov.KgLowDurable.pojo.entity.Kv; import com.nov.KgLowDurable.pojo.entity.Menu; +import com.nov.KgLowDurable.pojo.entity.User; import com.nov.KgLowDurable.pojo.vo.MenuVO; import java.util.List; @@ -65,7 +67,7 @@ public interface IMenuService extends IService

{ * @param topMenuId * @return */ - //List routes(String roleId, Long topMenuId); + List routes(String roleId, Long topMenuId); /** * 菜单树形结构 @@ -94,10 +96,10 @@ public interface IMenuService extends IService { /** * 授权树形结构 * - * @param user + * @param * @return */ - //List grantTree(Tuser user); + List grantTree(String roleId); /** * 顶部菜单树形结构 @@ -105,7 +107,7 @@ public interface IMenuService extends IService { * @param user * @return */ -// List grantTopTree(Tuser user); + List grantTopTree(String roleId); /** * 数据权限授权树形结构 @@ -137,7 +139,7 @@ public interface IMenuService extends IService { * @param topMenuIds * @return */ - //List topTreeKeys(String topMenuIds); + List topTreeKeys(String topMenuIds); /** * 默认选中节点 @@ -161,7 +163,7 @@ public interface IMenuService extends IService { * @param user * @return */ - //List authRoutes(Tuser user); + List authRoutes(String roleId); /** * 删除菜单 @@ -179,4 +181,9 @@ public interface IMenuService extends IService { */ boolean submit(Menu menu); + /** + * 查询全部 + * @return + */ + List grantTreeALL(); } diff --git a/src/main/java/com/nov/KgLowDurable/service/IRoleService.java b/src/main/java/com/nov/KgLowDurable/service/IRoleService.java index 541ea73..01df1b0 100644 --- a/src/main/java/com/nov/KgLowDurable/service/IRoleService.java +++ b/src/main/java/com/nov/KgLowDurable/service/IRoleService.java @@ -30,7 +30,6 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.nov.KgLowDurable.pojo.entity.Role; import com.nov.KgLowDurable.pojo.vo.RoleVO; - import java.util.List; /** @@ -49,13 +48,6 @@ public interface IRoleService extends IService { */ IPage selectRolePage(IPage page, RoleVO role); - /** - * 树形结构 - * - * @param tenantId 租户id - * @return 角色列表 - */ - List tree(String tenantId); /** * 权限配置 @@ -68,15 +60,6 @@ public interface IRoleService extends IService { */ boolean grant(List roleIds, List menuIds, List dataScopeIds, List apiScopeIds); - /** - * 获取角色ID - * - * @param tenantId 租户id - * @param roleNames 角色名 - * @return 角色id - */ - String getRoleIds(String tenantId, String roleNames); - /** * 获取角色名 * @@ -85,13 +68,6 @@ public interface IRoleService extends IService { */ List getRoleNames(String roleIds); - /** - * 获取角色名 - * - * @param roleIds 角色id - * @return 角色别名 - */ - List getRoleAliases(String roleIds); /** * 提交 @@ -118,13 +94,6 @@ public interface IRoleService extends IService { */ boolean removeRole(String ids); - /** - * 获取角色别名列表 - * - * @param tenantId 租户id - * @return 别名列表 - */ - List alias(); } diff --git a/src/main/java/com/nov/KgLowDurable/service/ITopMenuService.java b/src/main/java/com/nov/KgLowDurable/service/ITopMenuService.java new file mode 100644 index 0000000..21f85bc --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/service/ITopMenuService.java @@ -0,0 +1,50 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package com.nov.KgLowDurable.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.nov.KgLowDurable.pojo.entity.TopMenu; + +import java.util.List; + +/** + * 顶部菜单表 服务类 + * + * @author BladeX + */ +public interface ITopMenuService extends IService { + + /** + * 顶部菜单配置 + * + * @param topMenuIds 顶部菜单id集合 + * @param menuIds 菜单id集合 + * @return 是否成功 + */ + boolean grant(List topMenuIds, List menuIds); + +} diff --git a/src/main/java/com/nov/KgLowDurable/service/ITopMenuSettingService.java b/src/main/java/com/nov/KgLowDurable/service/ITopMenuSettingService.java new file mode 100644 index 0000000..aa8cfd3 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/service/ITopMenuSettingService.java @@ -0,0 +1,38 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package com.nov.KgLowDurable.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.nov.KgLowDurable.pojo.entity.TopMenuSetting; + +/** + * 服务类 + * + * @author Chill + */ +public interface ITopMenuSettingService extends IService { + +} diff --git a/src/main/java/com/nov/KgLowDurable/service/Impl/LdDictServiceImpl.java b/src/main/java/com/nov/KgLowDurable/service/Impl/LdDictServiceImpl.java index eca1998..00b51e2 100644 --- a/src/main/java/com/nov/KgLowDurable/service/Impl/LdDictServiceImpl.java +++ b/src/main/java/com/nov/KgLowDurable/service/Impl/LdDictServiceImpl.java @@ -28,10 +28,12 @@ package com.nov.KgLowDurable.service.Impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.util.StringUtil; +import com.nov.KgLowDurable.exception.ServiceException; import com.nov.KgLowDurable.mapper.LdDictMapper; import com.nov.KgLowDurable.pojo.entity.LdDict; import com.nov.KgLowDurable.pojo.vo.LdDictVO; @@ -41,10 +43,7 @@ import com.nov.KgLowDurable.wrapper.LdDictWrapper; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.apache.commons.lang3.math.NumberUtils.toLong; @@ -83,7 +82,7 @@ public class LdDictServiceImpl extends ServiceImpl impleme if(dict.getId()!=null&&dict.getId()!=0){ Integer cnt = baseMapper.selectCount((StringUtils.isEmpty(dict.getId().toString())) ? lqw : lqw.notIn(LdDict::getId, dict.getId())); if (cnt > 0) { - throw new MybatisPlusException("当前字典键值已存在!"); + throw new ServiceException("当前字典键值已存在!"); } } // 修改顶级字典后同步更新下属字典的编号 @@ -135,7 +134,7 @@ public class LdDictServiceImpl extends ServiceImpl impleme dict.remove("parentId"); LdDict parentDict = baseMapper.selectById(parentId); List list = this.list(Condition.getQueryWrapper(dict, LdDict.class).lambda().ne(LdDict::getId, parentId).eq(LdDict::getCode, parentDict.getCode()).orderByAsc(LdDict::getSort)); - return LdDictWrapper.build().listNodeVO(list); + return LdDictWrapper.build().listNodeVO(CollectionUtils.isEmpty(list)?new ArrayList<>():list); } @Override public List tree() { diff --git a/src/main/java/com/nov/KgLowDurable/service/Impl/MenuServiceImpl.java b/src/main/java/com/nov/KgLowDurable/service/Impl/MenuServiceImpl.java index 68d0df8..7787d1f 100644 --- a/src/main/java/com/nov/KgLowDurable/service/Impl/MenuServiceImpl.java +++ b/src/main/java/com/nov/KgLowDurable/service/Impl/MenuServiceImpl.java @@ -29,17 +29,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.nov.KgLowDurable.common.TreeNode; -import com.nov.KgLowDurable.exception.CustomerException; +import com.nov.KgLowDurable.exception.ServiceException; import com.nov.KgLowDurable.mapper.MenuMapper; -import com.nov.KgLowDurable.pojo.entity.Menu; -import com.nov.KgLowDurable.pojo.entity.RoleMenu; +import com.nov.KgLowDurable.pojo.dto.MenuDTO; +import com.nov.KgLowDurable.pojo.entity.*; import com.nov.KgLowDurable.pojo.vo.MenuVO; import com.nov.KgLowDurable.service.IMenuService; import com.nov.KgLowDurable.service.IRoleMenuService; -import com.nov.KgLowDurable.util.BladeConstant; -import com.nov.KgLowDurable.util.ForestNodeMerger; -import com.nov.KgLowDurable.util.Func; -import com.nov.KgLowDurable.util.StringUtils; +import com.nov.KgLowDurable.service.IRoleService; +import com.nov.KgLowDurable.service.ITopMenuSettingService; +import com.nov.KgLowDurable.util.*; import com.nov.KgLowDurable.wrapper.MenuWrapper; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; @@ -63,7 +62,9 @@ public class MenuServiceImpl extends ServiceImpl implements IM private final IRoleMenuService roleMenuService; //private final IRoleScopeService roleScopeService; - //private final ITopMenuSettingService topMenuSettingService; + private final ITopMenuSettingService topMenuSettingService; + + private final IRoleService roleService; private final static String PARENT_ID = "parentId"; private final static Integer MENU_CATEGORY = 1; @@ -83,42 +84,43 @@ public class MenuServiceImpl extends ServiceImpl implements IM return baseMapper.lazyMenuList(parentId, param); } -// @Override -// public List routes(String roleId, Long topMenuId) { + @Override + public List routes(String roleId, Long topMenuId) { // if (StringUtils.isBlank(roleId)) { // return null; // } -// List

allMenus = baseMapper.allMenu(); -// List roleMenus; -// // 超级管理员并且不是顶部菜单请求则返回全部菜单 -// if (isEmpty(topMenuId.toString())) { -// roleMenus = allMenus; -// } -// // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单 -// else if (isEmpty(topMenuId.toString())) { -// // 角色配置对应菜单 -// List roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId)); -// // 反向递归角色菜单所有父级 -// List routes = new LinkedList<>(roleIdMenus); -// roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu)); -// // roleMenus = tenantPackageMenu(routes); -// } -// // 顶部菜单请求返回对应角色权限菜单 -// else { -// // 角色配置对应菜单 -// List roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId)); -// // 反向递归角色菜单所有父级 -// List routes = new LinkedList<>(roleIdMenus); -// roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu)); -// // 顶部配置对应菜单 -// List topIdMenus = baseMapper.roleMenuByTopMenuId(topMenuId); -// // 筛选匹配角色对应的权限菜单 -//// roleMenus = tenantPackageMenu(topIdMenus.stream().filter(x -> -//// routes.stream().anyMatch(route -> route.getId().longValue() == x.getId().longValue()) -//// ).collect(Collectors.toList())); -// } -// return buildRoutes(allMenus, roleMenus); -// } + List allMenus = baseMapper.allMenu(); + List roleMenus = null; + Role role=roleService.getById(roleId); + // 超级管理员并且不是顶部菜单请求则返回全部菜单 + if (Func.isEmpty(topMenuId)) { + roleMenus = allMenus; + } + // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单 + else if (role!=null&&!role.getName().equals("超级管理员")&&Func.isEmpty(topMenuId)) { + // 角色配置对应菜单 + List roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId)); + // 反向递归角色菜单所有父级 + List routes = new LinkedList<>(roleIdMenus); + roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu)); + roleMenus = tenantPackageMenu(routes); + } + // 顶部菜单请求返回对应角色权限菜单 + else { + // 角色配置对应菜单 + List roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId)); + // 反向递归角色菜单所有父级 + List routes = new LinkedList<>(roleIdMenus); + roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu)); + // 顶部配置对应菜单 + List topIdMenus = baseMapper.roleMenuByTopMenuId(topMenuId); + // 筛选匹配角色对应的权限菜单 + roleMenus = tenantPackageMenu(topIdMenus.stream().filter(x -> + routes.stream().anyMatch(route -> route.getId().longValue() == x.getId().longValue()) + ).collect(Collectors.toList())); + } + return buildRoutes(allMenus, roleMenus); + } @Override public List routesExt(String roleId, Long topMenuId) { @@ -149,7 +151,7 @@ public class MenuServiceImpl extends ServiceImpl implements IM @Override public List buttons(String roleId) { - List buttons = (false) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId)); + List buttons = StringUtils.isEmpty(roleId) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId)); MenuWrapper menuWrapper = new MenuWrapper(); return menuWrapper.listNodeVO(buttons); } @@ -159,29 +161,29 @@ public class MenuServiceImpl extends ServiceImpl implements IM return ForestNodeMerger.merge(baseMapper.tree()); } -// @Override -// public List grantTree(Tuser user) { -// List menuTree = user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantTree() : baseMapper.grantTreeByRole(Func.toLongList(user.getRoleId())); -// return ForestNodeMerger.merge(tenantPackageTree(menuTree, user.getTenantId())); -// } + @Override + public List grantTree(String roleId) { + List menuTree = baseMapper.grantTreeByRole(Func.toLongList(roleId));//Func.toLongList(user.getRoleId()) + return ForestNodeMerger.merge(menuTree); + } -// @Override -// public List grantTopTree(BladeUser user) { -// List menuTree = user.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId())); -// return ForestNodeMerger.merge(tenantPackageTree(menuTree, user.getTenantId())); -// } + @Override + public List grantTopTree(String roleId) { + List menuTree = StringUtils.isEmpty(roleId)? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(roleId)); + return ForestNodeMerger.merge(menuTree); + } /** * 租户菜单权限自定义筛选 */ // private List tenantPackageTree(List menuTree, String tenantId) { -// //TenantPackage tenantPackage = SysCache.getTenantPackage(tenantId); -// //if (isNotEmpty(tenantPackage) && tenantPackage.getId() > 0L) { -// // List menuIds = Func.toLongList(tenantPackage.getMenuId()); +// TenantPackage tenantPackage = SysCache.getTenantPackage(tenantId); +// if (isNotEmpty(tenantPackage) && tenantPackage.getId() > 0L) { +// List menuIds = Func.toLongList(tenantPackage.getMenuId()); // // 筛选出两者菜单交集集合 -// //List collect = menuTree.stream().filter(x -> menuIds.contains(x.getId())).toList(); +// List collect = menuTree.stream().filter(x -> menuIds.contains(x.getId())).toList(); // // 创建递归基础集合 -// // List packageTree = new LinkedList<>(collect); +// List packageTree = new LinkedList<>(collect); // // 递归筛选出菜单集合所有父级 // collect.forEach(treeNode -> recursionParent(menuTree, packageTree, treeNode)); // // 递归筛选出菜单集合所有子级 @@ -219,14 +221,14 @@ public class MenuServiceImpl extends ServiceImpl implements IM /** * 租户菜单权限自定义筛选 */ -// private List tenantPackageMenu(List menu) { + private List tenantPackageMenu(List menu) { // TenantPackage tenantPackage = SysCache.getTenantPackage(AuthUtil.getTenantId()); // if (Func.isNotEmpty(tenantPackage) && Func.isNotEmpty(tenantPackage.getId()) && tenantPackage.getId() > 0L) { // List menuIds = Func.toLongList(tenantPackage.getMenuId()); // menu = menu.stream().filter(x -> menuIds.contains(x.getId())).collect(Collectors.toList()); // } -// return menu; -// } + return menu; + } // @Override // public List grantDataScopeTree(BladeUser user) { @@ -244,11 +246,11 @@ public class MenuServiceImpl extends ServiceImpl implements IM return roleMenus.stream().map(roleMenu -> Func.toStr(roleMenu.getMenuId())).collect(Collectors.toList()); } -// @Override -// public List topTreeKeys(String topMenuIds) { -// List settings = topMenuSettingService.list(Wrappers.query().lambda().in(TopMenuSetting::getTopMenuId, Func.toLongList(topMenuIds))); -// return settings.stream().map(setting -> Func.toStr(setting.getMenuId())).collect(Collectors.toList()); -// } + @Override + public List topTreeKeys(String topMenuIds) { + List settings = topMenuSettingService.list(Wrappers.query().lambda().in(TopMenuSetting::getTopMenuId, Func.toLongList(topMenuIds))); + return settings.stream().map(setting -> Func.toStr(setting.getMenuId())).collect(Collectors.toList()); + } // @Override // public List dataScopeTreeKeys(String roleIds) { @@ -262,20 +264,19 @@ public class MenuServiceImpl extends ServiceImpl implements IM // return roleScopes.stream().map(roleScope -> Func.toStr(roleScope.getScopeId())).collect(Collectors.toList()); // } -// @Override -// @Cacheable(cacheNames = MENU_CACHE, key = "'auth:routes:' + #user.roleId") -// public List authRoutes(BladeUser user) { -// List routes = baseMapper.authRoutes(Func.toLongList(user.getRoleId())); -// List list = new ArrayList<>(); -// routes.forEach(route -> list.add(Kv.create().set(route.getPath(), Kv.create().set("authority", Func.toStrArray(route.getAlias()))))); -// return list; -// } + @Override + public List authRoutes(String roleId) { + List routes = baseMapper.authRoutes(Func.toLongList(roleId)); + List list = new ArrayList<>(); + routes.forEach(route -> list.add(Kv.create().set(route.getPath(), Kv.create().set("authority", Func.toStrArray(route.getAlias()))))); + return list; + } @Override public boolean removeMenu(String ids) { Integer cnt = baseMapper.selectCount(Wrappers.query().lambda().in(Menu::getParentId, Func.toLongList(ids))); if (cnt > 0L) { - throw new CustomerException("请先删除子节点!"); + throw new ServiceException("请先删除子节点!"); } return removeByIds(Func.toLongList(ids)); } @@ -291,7 +292,7 @@ public class MenuServiceImpl extends ServiceImpl implements IM .or(o -> o.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY))); if (baseMapper.selectCount(menuQueryWrapper) > 0L) { - throw new CustomerException("菜单名或编号已存在!"); + throw new ServiceException("菜单名或编号已存在!"); } // 验证path唯一性 @@ -301,7 +302,7 @@ public class MenuServiceImpl extends ServiceImpl implements IM .ne(!isNewMenu, Menu::getId, menu.getId()); if (baseMapper.selectCount(pathQueryWrapper) > 0L) { - throw new CustomerException("菜单路径已存在!"); + throw new ServiceException("菜单路径已存在!"); } } @@ -314,12 +315,18 @@ public class MenuServiceImpl extends ServiceImpl implements IM if (isNewMenu || menu.getParentId() != null) { Menu parentMenu = baseMapper.selectById(menu.getParentId()); if (parentMenu != null && parentMenu.getCategory() != 1) { - throw new CustomerException("父节点只可选择菜单类型!"); + throw new ServiceException("父节点只可选择菜单类型!"); } } - + menu.setIsDeleted(BladeConstant.DB_NOT_DELETED); return saveOrUpdate(menu); } + @Override + public List grantTreeALL() { + List menuTree = baseMapper.grantTreeByRoleALL();//Func.toLongList(user.getRoleId()) + return ForestNodeMerger.merge(menuTree); + } + } diff --git a/src/main/java/com/nov/KgLowDurable/service/Impl/RoleServiceImpl.java b/src/main/java/com/nov/KgLowDurable/service/Impl/RoleServiceImpl.java index 98cea1b..9949b65 100644 --- a/src/main/java/com/nov/KgLowDurable/service/Impl/RoleServiceImpl.java +++ b/src/main/java/com/nov/KgLowDurable/service/Impl/RoleServiceImpl.java @@ -27,23 +27,18 @@ package com.nov.KgLowDurable.service.Impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.nov.KgLowDurable.constant.RoleConstant; -import com.nov.KgLowDurable.exception.CustomerException; +import com.nov.KgLowDurable.exception.ServiceException; import com.nov.KgLowDurable.mapper.RoleMapper; import com.nov.KgLowDurable.pojo.entity.Role; import com.nov.KgLowDurable.pojo.entity.RoleMenu; import com.nov.KgLowDurable.pojo.vo.RoleVO; import com.nov.KgLowDurable.service.IRoleMenuService; import com.nov.KgLowDurable.service.IRoleService; -import com.nov.KgLowDurable.util.BladeConstant; -import com.nov.KgLowDurable.util.ForestNodeMerger; import com.nov.KgLowDurable.util.Func; import com.nov.KgLowDurable.wrapper.RoleWrapper; import lombok.AllArgsConstructor; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -51,11 +46,9 @@ import org.springframework.validation.annotation.Validated; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import static com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty; -import static com.nov.KgLowDurable.util.Condition.isEmpty; /** @@ -77,16 +70,6 @@ public class RoleServiceImpl extends ServiceImpl implements IR return page.setRecords(baseMapper.selectRolePage(page, role)); } - @Override - public List tree(String tenantId) { - // String userRole = AuthUtil.getUserRole(); - String excludeRole = null; -// if (!CollectionUtil.contains(Func.toStrArray(userRole), RoleConstant.ADMIN) && !CollectionUtil.contains(Func.toStrArray(userRole), RoleConstant.ADMINISTRATOR)) { -// excludeRole = RoleConstant.ADMIN; -// } - return ForestNodeMerger.merge(baseMapper.tree(tenantId, excludeRole)); - } - @Override @Transactional(rollbackFor = Exception.class) public boolean grant( List roleIds, List menuIds, List dataScopeIds, List apiScopeIds) { @@ -95,14 +78,14 @@ public class RoleServiceImpl extends ServiceImpl implements IR private boolean grantRoleMenu(List roleIds, List menuIds) { // 防止越权配置超管角色 - Integer administratorCount = baseMapper.selectCount(Wrappers.query().lambda().eq(Role::getRoleAlias, RoleConstant.ADMINISTRATOR).in(Role::getId, roleIds)); + Integer administratorCount = baseMapper.selectCount(Wrappers.query().lambda().in(Role::getId, roleIds)); if (administratorCount > 0L) { - //throw new Exception("无权配置超管角色!"); + throw new ServiceException("无权配置超管角色!"); } // 防止越权配置管理员角色 - Integer adminCount = baseMapper.selectCount(Wrappers.query().lambda().eq(Role::getRoleAlias, RoleConstant.ADMIN).in(Role::getId, roleIds)); + Integer adminCount = baseMapper.selectCount(Wrappers.query().lambda().in(Role::getId, roleIds)); if ( adminCount > 0L) { - //throw new ServiceException("无权配置管理员角色!"); + throw new ServiceException("无权配置管理员角色!"); } // 删除角色配置的菜单集合 roleMenuService.remove(Wrappers.update().lambda().in(RoleMenu::getRoleId, roleIds)); @@ -122,7 +105,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR } private void recursionRoleMenu(List roleIds, List menuIds) { - roleIds.forEach(roleId -> baseMapper.selectList(Wrappers.query().lambda().eq(Role::getParentId, roleId)).forEach(role -> { + roleIds.forEach(roleId -> baseMapper.selectList(Wrappers.query().lambda()).forEach(role -> { List roleMenuList = roleMenuService.list(Wrappers.query().lambda().eq(RoleMenu::getRoleId, role.getId())); // 子节点过滤出父节点删除的菜单集合 List collectRoleMenuIds = roleMenuList.stream().map(RoleMenu::getMenuId).filter(menuId -> !menuIds.contains(menuId)).collect(Collectors.toList()); @@ -168,96 +151,34 @@ public class RoleServiceImpl extends ServiceImpl implements IR // roleScopeService.saveBatch(roleApiScopes); // return true; // } - - @Override - public String getRoleIds(String tenantId, String roleNames) { - List roleList = baseMapper.selectList(Wrappers.query().lambda().eq(Role::getTenantId, tenantId).in(Role::getRoleName, Func.toStrList(roleNames))); - if (roleList != null && roleList.size() > 0) { - return roleList.stream().map(role -> Func.toStr(role.getId())).distinct().collect(Collectors.joining(",")); - } - return null; - } - @Override public List getRoleNames(String roleIds) { return baseMapper.getRoleNames(Func.toLongArray(roleIds)); } - @Override - public List getRoleAliases(String roleIds) { - return baseMapper.getRoleAliases(Func.toLongArray(roleIds)); - } @Override public boolean submit(Role role) { -// if (!AuthUtil.isAdministrator()) { -// if (Func.toStr(role.getRoleAlias()).equals(RoleConstant.ADMINISTRATOR)) { -// throw new ServiceException("无权限创建超管角色!"); -// } -// } - if (isEmpty(role.getParentId())) { - //role.setTenantId(AuthUtil.getTenantId()); - role.setParentId(BladeConstant.TOP_PARENT_ID); - } - if (role.getParentId() > 0) { - Role parent = getById(role.getParentId()); -// if (Func.toLong(role.getParentId()) == Func.toLong(role.getId())) { -// throw new ServiceException("父节点不可选择自身!"); -// } - role.setTenantId(parent.getTenantId()); - } - role.setIsDeleted(BladeConstant.DB_NOT_DELETED); return saveOrUpdate(role); } @Override public List search(String roleName, Long parentId) { - //String tenantId = AuthUtil.getTenantId(); LambdaQueryWrapper queryWrapper = Wrappers.query().lambda(); if (isNotEmpty(roleName)) { - queryWrapper.like(Role::getRoleName, roleName); - } - if (isNotEmpty(parentId) && parentId > 0L) { - queryWrapper.eq(Role::getParentId, parentId); + queryWrapper.like(Role::getName, roleName); } -// if (Func.isNotEmpty(tenantId)) { -// queryWrapper.eq(Role::getTenantId, tenantId); -// } List roleList = baseMapper.selectList(queryWrapper); return RoleWrapper.build().listNodeVO(roleList); } @Override public boolean removeRole(String ids) { - Integer cnt = baseMapper.selectCount(Wrappers.query().lambda().in(Role::getParentId, Func.toLongList(ids))); + Integer cnt = baseMapper.selectCount(Wrappers.query().lambda()); if (cnt > 0L) { - throw new CustomerException("请先删除子节点!"); + throw new ServiceException("请先删除子节点!"); } return removeByIds(Func.toLongList(ids)); } - @Override - public List alias() { - // 获取所有角色数据 - List roles = baseMapper.selectList(Wrappers.lambdaQuery()); - - // 根据 roleAlias 对角色进行分组 - Map> aliasToNamesMap = roles.stream() - .collect(Collectors.groupingBy(Role::getRoleAlias, - Collectors.mapping(Role::getRoleName, Collectors.toList()))); - - // 创建新的角色列表,每个角色的 roleName 是 roleAlias 后跟括号内的所有 roleName - return aliasToNamesMap.entrySet().stream() - // 过滤掉超级管理员角色 - .filter(entry -> !RoleConstant.ADMINISTRATOR.equals(entry.getKey())) - .map(entry -> { - String roleAlias = entry.getKey(); - List names = entry.getValue(); - String namesConcat = names.stream().distinct().collect(Collectors.joining(StringPool.COMMA + StringPool.SPACE)); - Role role = new Role(); - role.setRoleAlias(roleAlias); - role.setRoleName(roleAlias + StringPool.SPACE + StringPool.LEFT_BRACKET + namesConcat + StringPool.RIGHT_BRACKET); - return role; - }).collect(Collectors.toList()); - } } diff --git a/src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuServiceImpl.java b/src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuServiceImpl.java new file mode 100644 index 0000000..9a7bfe3 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuServiceImpl.java @@ -0,0 +1,73 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package com.nov.KgLowDurable.service.Impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.nov.KgLowDurable.annotation.NotEmpty; +import com.nov.KgLowDurable.mapper.TopMenuMapper; +import com.nov.KgLowDurable.pojo.entity.TopMenu; +import com.nov.KgLowDurable.pojo.entity.TopMenuSetting; +import com.nov.KgLowDurable.service.ITopMenuService; +import com.nov.KgLowDurable.service.ITopMenuSettingService; +import lombok.AllArgsConstructor; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +/** + * 顶部菜单表 服务实现类 + * + * @author BladeX + */ +//@Master +@Service +@AllArgsConstructor +public class TopMenuServiceImpl extends ServiceImpl implements ITopMenuService { + + private final ITopMenuSettingService topMenuSettingService; + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean grant(@NotEmpty List topMenuIds, @NotEmpty List menuIds) { + // 删除顶部菜单配置的菜单集合 + topMenuSettingService.remove(Wrappers.update().lambda().in(TopMenuSetting::getTopMenuId, topMenuIds)); + // 组装配置 + List menuSettings = new ArrayList<>(); + topMenuIds.forEach(topMenuId -> menuIds.forEach(menuId -> { + TopMenuSetting menuSetting = new TopMenuSetting(); + menuSetting.setTopMenuId(topMenuId); + menuSetting.setMenuId(menuId); + menuSettings.add(menuSetting); + })); + // 新增配置 + topMenuSettingService.saveBatch(menuSettings); + return true; + } +} diff --git a/src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuSettingServiceImpl.java b/src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuSettingServiceImpl.java new file mode 100644 index 0000000..1189855 --- /dev/null +++ b/src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuSettingServiceImpl.java @@ -0,0 +1,43 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * Author: Chill Zhuang (bladejava@qq.com) + */ +package com.nov.KgLowDurable.service.Impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.nov.KgLowDurable.mapper.TopMenuSettingMapper; +import com.nov.KgLowDurable.pojo.entity.TopMenuSetting; +import com.nov.KgLowDurable.service.ITopMenuSettingService; +import org.springframework.stereotype.Service; + +/** + * 服务实现类 + * + * @author Chill + */ +//@Master +@Service +public class TopMenuSettingServiceImpl extends ServiceImpl implements ITopMenuSettingService { + +} diff --git a/src/main/java/com/nov/KgLowDurable/util/CommonConstant.java b/src/main/java/com/nov/KgLowDurable/util/CommonConstant.java index 21cb9cd..5a6bce8 100644 --- a/src/main/java/com/nov/KgLowDurable/util/CommonConstant.java +++ b/src/main/java/com/nov/KgLowDurable/util/CommonConstant.java @@ -101,6 +101,8 @@ public interface CommonConstant { /**访问权限认证未通过 510*/ public static final Integer SC_JEECG_NO_AUTHZ=510; + public static final Integer SC_INTERNAL_SERVER_ERROR_400 = 400; + /** 登录用户Shiro权限缓存KEY前缀 */ public static String PREFIX_USER_SHIRO_CACHE = "shiro:cache:org.jeecg.config.shiro.ShiroRealm.authorizationCache:"; /** 登录用户Token令牌缓存KEY前缀 */ diff --git a/src/main/java/com/nov/KgLowDurable/util/Func.java b/src/main/java/com/nov/KgLowDurable/util/Func.java index 50ed853..76add64 100644 --- a/src/main/java/com/nov/KgLowDurable/util/Func.java +++ b/src/main/java/com/nov/KgLowDurable/util/Func.java @@ -90,4 +90,23 @@ public class Func { public static boolean isNotEmpty(@Nullable Object obj) { return !ObjectUtil.isEmpty(obj); } + public static long toLong(final Object str) { + return toLong(String.valueOf(str)); + } + public static long toLong(final String str) { + return toLong(str, 0L); + } + + public static long toLong(@Nullable final String str, final long defaultValue) { + if (str == null) { + return defaultValue; + } else { + try { + return Long.valueOf(str); + } catch (NumberFormatException var4) { + return defaultValue; + } + } + } + } diff --git a/src/main/java/com/nov/KgLowDurable/util/Result.java b/src/main/java/com/nov/KgLowDurable/util/Result.java index 7f9028d..abf453b 100644 --- a/src/main/java/com/nov/KgLowDurable/util/Result.java +++ b/src/main/java/com/nov/KgLowDurable/util/Result.java @@ -142,4 +142,8 @@ public class Result implements Serializable { @JsonIgnore private String onlTable; + public static Result fail(String msg) { + return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_400, msg); + } + } diff --git a/src/main/java/com/nov/KgLowDurable/wrapper/RoleWrapper.java b/src/main/java/com/nov/KgLowDurable/wrapper/RoleWrapper.java index e96379e..3c5ba3c 100644 --- a/src/main/java/com/nov/KgLowDurable/wrapper/RoleWrapper.java +++ b/src/main/java/com/nov/KgLowDurable/wrapper/RoleWrapper.java @@ -54,22 +54,14 @@ public class RoleWrapper extends BaseEntityWrapper { return new RoleWrapper(); } - @Override - public RoleVO entityVO(Role role) { - RoleVO roleVO = Objects.requireNonNull(BeanUtil.copyProperties(role, RoleVO.class)); - if (Func.equals(role.getParentId(), BladeConstant.TOP_PARENT_ID)) { - roleVO.setParentName(BladeConstant.TOP_PARENT_NAME); - } else { - Role parent = roleMapper.selectById(role.getParentId()); - roleVO.setParentName(parent.getRoleName()); - } - return roleVO; - } - public List listNodeVO(List list) { List collect = list.stream().map(Role -> BeanUtil.copyProperties(Role, RoleVO.class)).collect(Collectors.toList()); return ForestNodeMerger.merge(collect); } + @Override + public RoleVO entityVO(Role entity) { + return null; + } } diff --git a/src/main/resources/mapper/MenuMapper.xml b/src/main/resources/mapper/MenuMapper.xml index 138d4fd..9a3d20c 100644 --- a/src/main/resources/mapper/MenuMapper.xml +++ b/src/main/resources/mapper/MenuMapper.xml @@ -257,6 +257,10 @@ ) order by sort +