修改和删除多余字段

master
sugy 4 months ago
parent b34345b0a4
commit e5dbb4e9e5
  1. 25
      src/main/java/com/nov/KgLowDurable/annotation/NotEmpty.java
  2. 25
      src/main/java/com/nov/KgLowDurable/controller/LdDictController.java
  3. 88
      src/main/java/com/nov/KgLowDurable/controller/LdRoleController.java
  4. 166
      src/main/java/com/nov/KgLowDurable/controller/MenuController.java
  5. 156
      src/main/java/com/nov/KgLowDurable/controller/RoleController.java
  6. 41
      src/main/java/com/nov/KgLowDurable/enums/ResultCode.java
  7. 9
      src/main/java/com/nov/KgLowDurable/exception/IResultCode.java
  8. 38
      src/main/java/com/nov/KgLowDurable/exception/ServiceException.java
  9. 6
      src/main/java/com/nov/KgLowDurable/mapper/MenuMapper.java
  10. 38
      src/main/java/com/nov/KgLowDurable/mapper/TopMenuMapper.java
  11. 38
      src/main/java/com/nov/KgLowDurable/mapper/TopMenuSettingMapper.java
  12. 45
      src/main/java/com/nov/KgLowDurable/pojo/entity/Role.java
  13. 73
      src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenu.java
  14. 38
      src/main/java/com/nov/KgLowDurable/pojo/entity/TopMenuSetting.java
  15. 16
      src/main/java/com/nov/KgLowDurable/pojo/vo/CheckedTreeVO.java
  16. 21
      src/main/java/com/nov/KgLowDurable/pojo/vo/GrantTreeVO.java
  17. 28
      src/main/java/com/nov/KgLowDurable/pojo/vo/GrantVO.java
  18. 19
      src/main/java/com/nov/KgLowDurable/service/IMenuService.java
  19. 31
      src/main/java/com/nov/KgLowDurable/service/IRoleService.java
  20. 50
      src/main/java/com/nov/KgLowDurable/service/ITopMenuService.java
  21. 38
      src/main/java/com/nov/KgLowDurable/service/ITopMenuSettingService.java
  22. 11
      src/main/java/com/nov/KgLowDurable/service/Impl/LdDictServiceImpl.java
  23. 163
      src/main/java/com/nov/KgLowDurable/service/Impl/MenuServiceImpl.java
  24. 97
      src/main/java/com/nov/KgLowDurable/service/Impl/RoleServiceImpl.java
  25. 73
      src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuServiceImpl.java
  26. 43
      src/main/java/com/nov/KgLowDurable/service/Impl/TopMenuSettingServiceImpl.java
  27. 2
      src/main/java/com/nov/KgLowDurable/util/CommonConstant.java
  28. 19
      src/main/java/com/nov/KgLowDurable/util/Func.java
  29. 4
      src/main/java/com/nov/KgLowDurable/util/Result.java
  30. 16
      src/main/java/com/nov/KgLowDurable/wrapper/RoleWrapper.java
  31. 4
      src/main/resources/mapper/MenuMapper.xml
  32. 22
      src/main/resources/mapper/TopMenuMapper.xml
  33. 5
      src/main/resources/mapper/TopMenuSettingMapper.xml

@ -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<? extends Payload>[] 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();
}
}

@ -1,28 +1,3 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package com.nov.KgLowDurable.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

@ -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<Role> 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<RoleVO>> list(@ApiParam(hidden = true) @RequestParam Map<String, Object> role) {
QueryWrapper<Role> queryWrapper = Condition.getQueryWrapper(role, Role.class);
List<Role> 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("操作失败");
}
}
}

@ -1,41 +1,19 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<List<MenuVO>> routes(BladeUser user, Long topMenuId) {
// List<MenuVO> list = menuService.routes((user == null) ? null : user.getRoleId(), topMenuId);
// return R.data(list);
// }
@GetMapping("/routes")
@ApiOperation(value = "前端菜单数据", notes = "前端菜单数据")
public Result<List<MenuVO>> routes(String roleId, Long topMenuId) {
List<MenuVO> list = menuService.routes((roleId == null) ? null : roleId, topMenuId);
return Result.OK(list);
}
/**
* 前端菜单数据
*/
// @GetMapping("/routes-ext")
// @ApiOperationSupport(order = 9)
// @Operation(summary = "前端菜单数据", description = "前端菜单数据")
// public R<List<MenuVO>> routesExt(BladeUser user, Long topMenuId) {
// List<MenuVO> list = menuService.routesExt(user.getRoleId(), topMenuId);
// return R.data(list);
// @ApiOperation(value = "前端菜单数据", notes = "前端菜单数据")
// public Result<List<MenuVO>> routesExt(String roleId, Long topMenuId) {
// List<MenuVO> list = menuService.routesExt(roleId, topMenuId);
// return Result.OK(list);
// }
/**
* 前端按钮数据
*/
// @GetMapping("/buttons")
// @ApiOperationSupport(order = 10)
// @Operation(summary = "前端按钮数据", description = "前端按钮数据")
// public R<List<MenuVO>> buttons(BladeUser user) {
// List<MenuVO> list = menuService.buttons(user.getRoleId());
// return R.data(list);
// }
@GetMapping("/buttons")
@ApiOperation(value = "前端按钮数据", notes = "前端按钮数据")
public Result<List<MenuVO>> buttons(String roleId) {
List<MenuVO> 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<GrantTreeVO> grantTree(BladeUser user) {
// GrantTreeVO vo = new GrantTreeVO();
// vo.setMenu(menuService.grantTree(user));
@GetMapping("/grant-tree")
@ApiOperation(value = "权限分配树形结构", notes = "权限分配树形结构")
public Result<GrantTreeVO> 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<CheckedTreeVO> roleTreeKeys(String roleIds) {
// CheckedTreeVO vo = new CheckedTreeVO();
// vo.setMenu(menuService.roleTreeKeys(roleIds));
@GetMapping("/role-tree-keys")
@ApiOperation(value = "角色所分配的树", notes = "角色所分配的树")
public Result<CheckedTreeVO> 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<GrantTreeVO> 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<GrantTreeVO> 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<CheckedTreeVO> topTreeKeys(String topMenuIds) {
// @ApiOperation(value = "顶部菜单所分配的树", notes = "顶部菜单所分配的树")
// public Result<CheckedTreeVO> 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<List<TopMenu>> topMenu(BladeUser user) {
// @ApiOperation(value = "顶部菜单数据", notes = "顶部菜单数据")
// public Result<List<TopMenu>> topMenu(User user) {
// if (Func.isEmpty(user)) {
// return null;
// }
// List<TopMenu> list = topMenuService.list(Wrappers.<TopMenu>query().lambda().orderByAsc(TopMenu::getSort));
// return R.data(list);
// return Result.OK(list);
// }
/**
* 获取配置的角色权限
*/
// @GetMapping("auth-routes")
// @ApiOperationSupport(order = 17)
// @Operation(summary = "菜单的角色权限")
// public R<List<Kv>> authRoutes(BladeUser user) {
// if (Func.isEmpty(user)) {
// return null;
// }
// return R.data(menuService.authRoutes(user));
// }
@GetMapping("auth-routes")
@ApiOperation(value = "菜单的角色权限")
public Result<List<Kv>> authRoutes(String roleId) {
if (Func.isEmpty(roleId)) {
return null;
}
return Result.OK(menuService.authRoutes(roleId));
}
}

@ -1,156 +0,0 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<Role> 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<RoleVO>> list(@ApiParam(hidden = true) @RequestParam Map<String, Object> role) {
QueryWrapper<Role> queryWrapper = Condition.getQueryWrapper(role, Role.class);
List<Role> list = roleService.list(queryWrapper);
return Result.OK(RoleWrapper.build().listNodeVO(list));
}
/**
* 获取角色树形结构
*/
// @GetMapping("/tree")
// @ApiOperation(value = "树形结构", notes = "树形结构")
// public Result<List<RoleVO>> tree(Tuser bladeUser) {
// List<RoleVO> tree = roleService.tree(bladeUser.getUserId());
// return Result.OK(tree);
// }
/**
* 获取指定角色树形结构
*/
@GetMapping("/tree-by-id")
@ApiOperation(value = "树形结构", notes = "树形结构")
public Result<List<RoleVO>> treeById(Long roleId, User bladeUser) {
List<RoleVO> 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<List<Role>> select(Long userId, String roleId) {
// if (Func.isNotEmpty(userId)) {
// User user = UserCache.getUser(userId);
// roleId = user.getRoleId();
// }
// List<Role> list = roleService.list(Wrappers.<Role>lambdaQuery().in(Role::getId, Func.toLongList(roleId)));
// return R.data(list);
// }
/**
* 获取现有角色别名列表
*/
@GetMapping("/alias")
@ApiOperation(value = "获取角色别名", notes = "获取角色别名")
public Result<List<Role>> alias() {
return Result.OK(roleService.alias());
}
}

@ -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;
}
}

@ -0,0 +1,9 @@
package com.nov.KgLowDurable.exception;
import java.io.Serializable;
public interface IResultCode extends Serializable {
String getMessage();
int getCode();
}

@ -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;
}
}

@ -205,4 +205,10 @@ public interface MenuMapper extends BaseMapper<Menu> {
* @return
*/
List<MenuDTO> authRoutes(List<Long> roleIds);
/**
* 查询全部
* @return
*/
List<TreeNode> grantTreeByRoleALL();
}

@ -0,0 +1,38 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<TopMenu> {
}

@ -0,0 +1,38 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<TopMenuSetting> {
}

@ -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;
}

@ -0,0 +1,73 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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;
}

@ -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;
}

@ -0,0 +1,16 @@
package com.nov.KgLowDurable.pojo.vo;
import lombok.Data;
import java.util.List;
@Data
public class CheckedTreeVO {
private List<String> menu;
private List<String> dataScope;
private List<String> apiScope;
}

@ -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<TreeNode> menu;
private List<TreeNode> dataScope;
private List<TreeNode> apiScope;
}

@ -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<Long> roleIds;
@Schema(description = "menuIds集合")
private List<Long> menuIds;
@Schema(description = "topMenuIds集合")
private List<Long> topMenuIds;
@Schema(description = "dataScopeIds集合")
private List<Long> dataScopeIds;
@Schema(description = "apiScopeIds集合")
private List<Long> apiScopeIds;
}

@ -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<Menu> {
* @param topMenuId
* @return
*/
//List<MenuVO> routes(String roleId, Long topMenuId);
List<MenuVO> routes(String roleId, Long topMenuId);
/**
* 菜单树形结构
@ -94,10 +96,10 @@ public interface IMenuService extends IService<Menu> {
/**
* 授权树形结构
*
* @param user
* @param
* @return
*/
//List<TreeNode> grantTree(Tuser user);
List<TreeNode> grantTree(String roleId);
/**
* 顶部菜单树形结构
@ -105,7 +107,7 @@ public interface IMenuService extends IService<Menu> {
* @param user
* @return
*/
// List<TreeNode> grantTopTree(Tuser user);
List<TreeNode> grantTopTree(String roleId);
/**
* 数据权限授权树形结构
@ -137,7 +139,7 @@ public interface IMenuService extends IService<Menu> {
* @param topMenuIds
* @return
*/
//List<String> topTreeKeys(String topMenuIds);
List<String> topTreeKeys(String topMenuIds);
/**
* 默认选中节点
@ -161,7 +163,7 @@ public interface IMenuService extends IService<Menu> {
* @param user
* @return
*/
//List<Kv> authRoutes(Tuser user);
List<Kv> authRoutes(String roleId);
/**
* 删除菜单
@ -179,4 +181,9 @@ public interface IMenuService extends IService<Menu> {
*/
boolean submit(Menu menu);
/**
* 查询全部
* @return
*/
List<TreeNode> grantTreeALL();
}

@ -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<Role> {
*/
IPage<RoleVO> selectRolePage(IPage<RoleVO> page, RoleVO role);
/**
* 树形结构
*
* @param tenantId 租户id
* @return 角色列表
*/
List<RoleVO> tree(String tenantId);
/**
* 权限配置
@ -68,15 +60,6 @@ public interface IRoleService extends IService<Role> {
*/
boolean grant(List<Long> roleIds, List<Long> menuIds, List<Long> dataScopeIds, List<Long> apiScopeIds);
/**
* 获取角色ID
*
* @param tenantId 租户id
* @param roleNames 角色名
* @return 角色id
*/
String getRoleIds(String tenantId, String roleNames);
/**
* 获取角色名
*
@ -85,13 +68,6 @@ public interface IRoleService extends IService<Role> {
*/
List<String> getRoleNames(String roleIds);
/**
* 获取角色名
*
* @param roleIds 角色id
* @return 角色别名
*/
List<String> getRoleAliases(String roleIds);
/**
* 提交
@ -118,13 +94,6 @@ public interface IRoleService extends IService<Role> {
*/
boolean removeRole(String ids);
/**
* 获取角色别名列表
*
* @param tenantId 租户id
* @return 别名列表
*/
List<Role> alias();
}

@ -0,0 +1,50 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<TopMenu> {
/**
* 顶部菜单配置
*
* @param topMenuIds 顶部菜单id集合
* @param menuIds 菜单id集合
* @return 是否成功
*/
boolean grant(List<Long> topMenuIds, List<Long> menuIds);
}

@ -0,0 +1,38 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<TopMenuSetting> {
}

@ -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<LdDictMapper, LdDict> 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<LdDictMapper, LdDict> impleme
dict.remove("parentId");
LdDict parentDict = baseMapper.selectById(parentId);
List<LdDict> 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<LdDictVO> tree() {

@ -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<MenuMapper, Menu> 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<MenuMapper, Menu> implements IM
return baseMapper.lazyMenuList(parentId, param);
}
// @Override
// public List<MenuVO> routes(String roleId, Long topMenuId) {
@Override
public List<MenuVO> routes(String roleId, Long topMenuId) {
// if (StringUtils.isBlank(roleId)) {
// return null;
// }
// List<Menu> allMenus = baseMapper.allMenu();
// List<Menu> roleMenus;
// // 超级管理员并且不是顶部菜单请求则返回全部菜单
// if (isEmpty(topMenuId.toString())) {
// roleMenus = allMenus;
// }
// // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
// else if (isEmpty(topMenuId.toString())) {
// // 角色配置对应菜单
// List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
// // 反向递归角色菜单所有父级
// List<Menu> routes = new LinkedList<>(roleIdMenus);
// roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
// // roleMenus = tenantPackageMenu(routes);
// }
// // 顶部菜单请求返回对应角色权限菜单
// else {
// // 角色配置对应菜单
// List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
// // 反向递归角色菜单所有父级
// List<Menu> routes = new LinkedList<>(roleIdMenus);
// roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
// // 顶部配置对应菜单
// List<Menu> 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<Menu> allMenus = baseMapper.allMenu();
List<Menu> roleMenus = null;
Role role=roleService.getById(roleId);
// 超级管理员并且不是顶部菜单请求则返回全部菜单
if (Func.isEmpty(topMenuId)) {
roleMenus = allMenus;
}
// 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
else if (role!=null&&!role.getName().equals("超级管理员")&&Func.isEmpty(topMenuId)) {
// 角色配置对应菜单
List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
// 反向递归角色菜单所有父级
List<Menu> routes = new LinkedList<>(roleIdMenus);
roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
roleMenus = tenantPackageMenu(routes);
}
// 顶部菜单请求返回对应角色权限菜单
else {
// 角色配置对应菜单
List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
// 反向递归角色菜单所有父级
List<Menu> routes = new LinkedList<>(roleIdMenus);
roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
// 顶部配置对应菜单
List<Menu> 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<MenuVO> routesExt(String roleId, Long topMenuId) {
@ -149,7 +151,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
@Override
public List<MenuVO> buttons(String roleId) {
List<Menu> buttons = (false) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
List<Menu> 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<MenuMapper, Menu> implements IM
return ForestNodeMerger.merge(baseMapper.tree());
}
// @Override
// public List<TreeNode> grantTree(Tuser user) {
// List<TreeNode> 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<TreeNode> grantTree(String roleId) {
List<TreeNode> menuTree = baseMapper.grantTreeByRole(Func.toLongList(roleId));//Func.toLongList(user.getRoleId())
return ForestNodeMerger.merge(menuTree);
}
// @Override
// public List<TreeNode> grantTopTree(BladeUser user) {
// List<TreeNode> 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<TreeNode> grantTopTree(String roleId) {
List<TreeNode> menuTree = StringUtils.isEmpty(roleId)? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(roleId));
return ForestNodeMerger.merge(menuTree);
}
/**
* 租户菜单权限自定义筛选
*/
// private List<TreeNode> tenantPackageTree(List<TreeNode> menuTree, String tenantId) {
// //TenantPackage tenantPackage = SysCache.getTenantPackage(tenantId);
// //if (isNotEmpty(tenantPackage) && tenantPackage.getId() > 0L) {
// // List<Long> menuIds = Func.toLongList(tenantPackage.getMenuId());
// TenantPackage tenantPackage = SysCache.getTenantPackage(tenantId);
// if (isNotEmpty(tenantPackage) && tenantPackage.getId() > 0L) {
// List<Long> menuIds = Func.toLongList(tenantPackage.getMenuId());
// // 筛选出两者菜单交集集合
// //List<TreeNode> collect = menuTree.stream().filter(x -> menuIds.contains(x.getId())).toList();
// List<TreeNode> collect = menuTree.stream().filter(x -> menuIds.contains(x.getId())).toList();
// // 创建递归基础集合
// // List<TreeNode> packageTree = new LinkedList<>(collect);
// List<TreeNode> packageTree = new LinkedList<>(collect);
// // 递归筛选出菜单集合所有父级
// collect.forEach(treeNode -> recursionParent(menuTree, packageTree, treeNode));
// // 递归筛选出菜单集合所有子级
@ -219,14 +221,14 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
/**
* 租户菜单权限自定义筛选
*/
// private List<Menu> tenantPackageMenu(List<Menu> menu) {
private List<Menu> tenantPackageMenu(List<Menu> menu) {
// TenantPackage tenantPackage = SysCache.getTenantPackage(AuthUtil.getTenantId());
// if (Func.isNotEmpty(tenantPackage) && Func.isNotEmpty(tenantPackage.getId()) && tenantPackage.getId() > 0L) {
// List<Long> menuIds = Func.toLongList(tenantPackage.getMenuId());
// menu = menu.stream().filter(x -> menuIds.contains(x.getId())).collect(Collectors.toList());
// }
// return menu;
// }
return menu;
}
// @Override
// public List<TreeNode> grantDataScopeTree(BladeUser user) {
@ -244,11 +246,11 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
return roleMenus.stream().map(roleMenu -> Func.toStr(roleMenu.getMenuId())).collect(Collectors.toList());
}
// @Override
// public List<String> topTreeKeys(String topMenuIds) {
// List<TopMenuSetting> settings = topMenuSettingService.list(Wrappers.<TopMenuSetting>query().lambda().in(TopMenuSetting::getTopMenuId, Func.toLongList(topMenuIds)));
// return settings.stream().map(setting -> Func.toStr(setting.getMenuId())).collect(Collectors.toList());
// }
@Override
public List<String> topTreeKeys(String topMenuIds) {
List<TopMenuSetting> settings = topMenuSettingService.list(Wrappers.<TopMenuSetting>query().lambda().in(TopMenuSetting::getTopMenuId, Func.toLongList(topMenuIds)));
return settings.stream().map(setting -> Func.toStr(setting.getMenuId())).collect(Collectors.toList());
}
// @Override
// public List<String> dataScopeTreeKeys(String roleIds) {
@ -262,20 +264,19 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> 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<Kv> authRoutes(BladeUser user) {
// List<MenuDTO> routes = baseMapper.authRoutes(Func.toLongList(user.getRoleId()));
// List<Kv> 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<Kv> authRoutes(String roleId) {
List<MenuDTO> routes = baseMapper.authRoutes(Func.toLongList(roleId));
List<Kv> 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.<Menu>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<MenuMapper, Menu> 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<MenuMapper, Menu> 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<MenuMapper, Menu> 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<TreeNode> grantTreeALL() {
List<TreeNode> menuTree = baseMapper.grantTreeByRoleALL();//Func.toLongList(user.getRoleId())
return ForestNodeMerger.merge(menuTree);
}
}

@ -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<RoleMapper, Role> implements IR
return page.setRecords(baseMapper.selectRolePage(page, role));
}
@Override
public List<RoleVO> 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<Long> roleIds, List<Long> menuIds, List<Long> dataScopeIds, List<Long> apiScopeIds) {
@ -95,14 +78,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds) {
// 防止越权配置超管角色
Integer administratorCount = baseMapper.selectCount(Wrappers.<Role>query().lambda().eq(Role::getRoleAlias, RoleConstant.ADMINISTRATOR).in(Role::getId, roleIds));
Integer administratorCount = baseMapper.selectCount(Wrappers.<Role>query().lambda().in(Role::getId, roleIds));
if (administratorCount > 0L) {
//throw new Exception("无权配置超管角色!");
throw new ServiceException("无权配置超管角色!");
}
// 防止越权配置管理员角色
Integer adminCount = baseMapper.selectCount(Wrappers.<Role>query().lambda().eq(Role::getRoleAlias, RoleConstant.ADMIN).in(Role::getId, roleIds));
Integer adminCount = baseMapper.selectCount(Wrappers.<Role>query().lambda().in(Role::getId, roleIds));
if ( adminCount > 0L) {
//throw new ServiceException("无权配置管理员角色!");
throw new ServiceException("无权配置管理员角色!");
}
// 删除角色配置的菜单集合
roleMenuService.remove(Wrappers.<RoleMenu>update().lambda().in(RoleMenu::getRoleId, roleIds));
@ -122,7 +105,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
}
private void recursionRoleMenu(List<Long> roleIds, List<Long> menuIds) {
roleIds.forEach(roleId -> baseMapper.selectList(Wrappers.<Role>query().lambda().eq(Role::getParentId, roleId)).forEach(role -> {
roleIds.forEach(roleId -> baseMapper.selectList(Wrappers.<Role>query().lambda()).forEach(role -> {
List<RoleMenu> roleMenuList = roleMenuService.list(Wrappers.<RoleMenu>query().lambda().eq(RoleMenu::getRoleId, role.getId()));
// 子节点过滤出父节点删除的菜单集合
List<Long> collectRoleMenuIds = roleMenuList.stream().map(RoleMenu::getMenuId).filter(menuId -> !menuIds.contains(menuId)).collect(Collectors.toList());
@ -168,96 +151,34 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
// roleScopeService.saveBatch(roleApiScopes);
// return true;
// }
@Override
public String getRoleIds(String tenantId, String roleNames) {
List<Role> roleList = baseMapper.selectList(Wrappers.<Role>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<String> getRoleNames(String roleIds) {
return baseMapper.getRoleNames(Func.toLongArray(roleIds));
}
@Override
public List<String> 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<RoleVO> search(String roleName, Long parentId) {
//String tenantId = AuthUtil.getTenantId();
LambdaQueryWrapper<Role> queryWrapper = Wrappers.<Role>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<Role> roleList = baseMapper.selectList(queryWrapper);
return RoleWrapper.build().listNodeVO(roleList);
}
@Override
public boolean removeRole(String ids) {
Integer cnt = baseMapper.selectCount(Wrappers.<Role>query().lambda().in(Role::getParentId, Func.toLongList(ids)));
Integer cnt = baseMapper.selectCount(Wrappers.<Role>query().lambda());
if (cnt > 0L) {
throw new CustomerException("请先删除子节点!");
throw new ServiceException("请先删除子节点!");
}
return removeByIds(Func.toLongList(ids));
}
@Override
public List<Role> alias() {
// 获取所有角色数据
List<Role> roles = baseMapper.selectList(Wrappers.<Role>lambdaQuery());
// 根据 roleAlias 对角色进行分组
Map<String, List<String>> 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<String> 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());
}
}

@ -0,0 +1,73 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<TopMenuMapper, TopMenu> implements ITopMenuService {
private final ITopMenuSettingService topMenuSettingService;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean grant(@NotEmpty List<Long> topMenuIds, @NotEmpty List<Long> menuIds) {
// 删除顶部菜单配置的菜单集合
topMenuSettingService.remove(Wrappers.<TopMenuSetting>update().lambda().in(TopMenuSetting::getTopMenuId, topMenuIds));
// 组装配置
List<TopMenuSetting> 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;
}
}

@ -0,0 +1,43 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* 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<TopMenuSettingMapper, TopMenuSetting> implements ITopMenuSettingService {
}

@ -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前缀 */

@ -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;
}
}
}
}

@ -142,4 +142,8 @@ public class Result<T> implements Serializable {
@JsonIgnore
private String onlTable;
public static Result<Object> fail(String msg) {
return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_400, msg);
}
}

@ -54,22 +54,14 @@ public class RoleWrapper extends BaseEntityWrapper<Role, RoleVO> {
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<RoleVO> listNodeVO(List<Role> list) {
List<RoleVO> 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;
}
}

@ -257,6 +257,10 @@
)
order by sort
</select>
<select id="grantTreeByRoleALL" resultMap="treeNodeResultMap">
select id, parent_id, name as title, id as "value", id as "key" from blade_menu where is_deleted = 0
order by sort
</select>
<select id="grantTopTree" resultMap="treeNodeResultMap">
select id, parent_id, name as title, id as "value", id as "key" from blade_menu where category = 1 and is_deleted = 0 order by sort

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nov.KgLowDurable.mapper.TopMenuMapper">
<!-- 通用查询映射结果 -->
<resultMap id="topMenuResultMap" type="com.nov.KgLowDurable.pojo.entity.TopMenu">
<!-- <result column="id" property="id"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="status" property="status"/>
<result column="is_deleted" property="isDeleted"/>-->
<result column="code" property="code"/>
<result column="name" property="name"/>
<result column="source" property="source"/>
<result column="path" property="path"/>
<result column="sort" property="sort"/>
</resultMap>
</mapper>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nov.KgLowDurable.mapper.TopMenuSettingMapper">
</mapper>
Loading…
Cancel
Save