权限菜单优化

master
chen 2 years ago
parent b60d97d219
commit e6fc950c7b
  1. 8
      src/main/java/com/huoran/iasf/controller/PermissionController.java
  2. 9
      src/main/java/com/huoran/iasf/entity/SysPermission.java
  3. 2
      src/main/java/com/huoran/iasf/service/PermissionService.java
  4. 50
      src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java
  5. 2
      src/main/java/com/huoran/iasf/service/impl/RoleServiceImpl.java
  6. 23
      src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java

@ -51,7 +51,7 @@ public class PermissionController {
return R.success(); return R.success();
} }
@PutMapping("/permission") /* @PutMapping("/permission")
@ApiOperation(value = "更新菜单权限接口") @ApiOperation(value = "更新菜单权限接口")
@LogAnnotation(title = "菜单权限管理", action = "更新菜单权限") @LogAnnotation(title = "菜单权限管理", action = "更新菜单权限")
@RequiresPermissions("sys:permission:update") @RequiresPermissions("sys:permission:update")
@ -69,15 +69,15 @@ public class PermissionController {
} }
permissionService.updatePermission(vo); permissionService.updatePermission(vo);
return R.success(); return R.success();
} }*/
@GetMapping("/permission/{id}") /* @GetMapping("/permission/{id}")
@ApiOperation(value = "查询菜单权限接口") @ApiOperation(value = "查询菜单权限接口")
@LogAnnotation(title = "菜单权限管理", action = "查询菜单权限") @LogAnnotation(title = "菜单权限管理", action = "查询菜单权限")
@RequiresPermissions("sys:permission:detail") @RequiresPermissions("sys:permission:detail")
public R detailInfo(@PathVariable("id") String id) { public R detailInfo(@PathVariable("id") String id) {
return R.success(permissionService.getById(id)); return R.success(permissionService.getById(id));
} }*/
/*@GetMapping("/permissions") /*@GetMapping("/permissions")
@ApiOperation(value = "获取所有菜单权限接口") @ApiOperation(value = "获取所有菜单权限接口")

@ -10,6 +10,7 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* 权限菜单 * 权限菜单
@ -63,8 +64,12 @@ public class SysPermission implements Serializable {
@TableField(fill = FieldFill.INSERT) @TableField(fill = FieldFill.INSERT)
private Integer deleted; private Integer deleted;
@ApiModelProperty(value = "层级")
@TableField(exist = false) @TableField(exist = false)
@ApiModelProperty(value = "父级菜单权限名称") private Integer level;
private String pidName;
@ApiModelProperty(value = "下级")
@TableField(exist = false)
private List<SysPermission> children;
} }

@ -59,7 +59,7 @@ public interface PermissionService extends IService<SysPermission> {
* *
* @return List * @return List
*/ */
List<PermissionRespNode> selectAllByTree(); List<SysPermission> selectAllByTree();
/** /**
* 根据目录树 * 根据目录树

@ -114,7 +114,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
for (SysPermission sysPermission : result) { for (SysPermission sysPermission : result) {
SysPermission parent = sysPermissionMapper.selectById(sysPermission.getPid()); SysPermission parent = sysPermissionMapper.selectById(sysPermission.getPid());
if (parent != null) { if (parent != null) {
sysPermission.setPidName(parent.getName()); // sysPermission.setPidName(parent.getName());
} }
} }
} }
@ -216,10 +216,50 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
* 获取所有菜单权限按钮 * 获取所有菜单权限按钮
*/ */
@Override @Override
public List<PermissionRespNode> selectAllByTree() { public List<SysPermission> selectAllByTree() {
List<SysPermission> list = selectAll(); // List<SysPermission> list = selectAll();
return getTree(list, false); // return getTree(list, false);
List<SysPermission> permissionList = baseMapper.selectList(null);
return build(permissionList);
}
/**
* 使用递归方法建菜单
* @param treeNodes 权限菜单
* @return 权限菜单
*/
private static List<SysPermission> build(List<SysPermission> treeNodes) {
List<SysPermission> trees = new ArrayList<>();
for (SysPermission treeNode : treeNodes) {
if ("0".equals(treeNode.getPid())) {
treeNode.setLevel(1);
trees.add(findChildren(treeNode,treeNodes));
}
}
return trees;
}
/**
* 递归查找子节点
* @param treeNodes 权限子菜单
* @return 权限子菜单
*/
private static SysPermission findChildren(SysPermission treeNode,List<SysPermission> treeNodes) {
treeNode.setChildren(new ArrayList<SysPermission>());
for (SysPermission it : treeNodes) {
if(treeNode.getId().equals(it.getPid())) {
int level = treeNode.getLevel() + 1;
it.setLevel(level);
if (treeNode.getChildren() == null) {
treeNode.setChildren(new ArrayList<>());
}
treeNode.getChildren().add(findChildren(it,treeNodes));
}
}
return treeNode;
} }
/** /**
@ -247,7 +287,7 @@ public class PermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysP
PermissionRespNode respNode = new PermissionRespNode(); PermissionRespNode respNode = new PermissionRespNode();
respNode.setId("0"); respNode.setId("0");
respNode.setName("默认顶级菜单"); respNode.setName("默认顶级菜单");
respNode.setSpread(true); // respNode.setSpread(true);
respNode.setChildren(getTree(list, true)); respNode.setChildren(getTree(list, true));
result.add(respNode); result.add(respNode);
return result; return result;

@ -94,7 +94,7 @@ public class RoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impleme
for (PermissionRespNode node : list) { for (PermissionRespNode node : list) {
if (checkList.contains(node.getId()) if (checkList.contains(node.getId())
&& CollectionUtils.isEmpty(node.getChildren())) { && CollectionUtils.isEmpty(node.getChildren())) {
node.setChecked(true); // node.setChecked(true);
} }
setChecked((List<PermissionRespNode>) node.getChildren(), checkList); setChecked((List<PermissionRespNode>) node.getChildren(), checkList);
} }

@ -26,28 +26,23 @@ public class PermissionRespNode {
@ApiModelProperty(value = "接口地址") @ApiModelProperty(value = "接口地址")
private String url; private String url;
@ApiModelProperty(value = "icon") /* @ApiModelProperty(value = "icon")
private String icon; private String icon;*/
private String target; // private String target;
@ApiModelProperty(value = "父级id") @ApiModelProperty(value = "父级id")
private String pid; private String pid;
@ApiModelProperty(value = "父级名称") // @ApiModelProperty(value = "父级名称")
private String pidName; // private String pidName;
@ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)") /* @ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)")
private Integer type; private Integer type;*/
@ApiModelProperty(value = "排序码") /* @ApiModelProperty(value = "排序码")
private Integer orderNum; private Integer orderNum;*/
@ApiModelProperty(value = "是否展开 默认不展开(false)")
private boolean spread = true;
@ApiModelProperty(value = "是否选中 默认false")
private boolean checked;
private List<?> children; private List<?> children;

Loading…
Cancel
Save