diff --git a/src/main/java/com/huoran/iasf/controller/PermissionController.java b/src/main/java/com/huoran/iasf/controller/PermissionController.java index 02246ea..af4bf09 100644 --- a/src/main/java/com/huoran/iasf/controller/PermissionController.java +++ b/src/main/java/com/huoran/iasf/controller/PermissionController.java @@ -51,7 +51,7 @@ public class PermissionController { return R.success(); } - @PutMapping("/permission") +/* @PutMapping("/permission") @ApiOperation(value = "更新菜单权限接口") @LogAnnotation(title = "菜单权限管理", action = "更新菜单权限") @RequiresPermissions("sys:permission:update") @@ -69,15 +69,15 @@ public class PermissionController { } permissionService.updatePermission(vo); return R.success(); - } + }*/ - @GetMapping("/permission/{id}") +/* @GetMapping("/permission/{id}") @ApiOperation(value = "查询菜单权限接口") @LogAnnotation(title = "菜单权限管理", action = "查询菜单权限") @RequiresPermissions("sys:permission:detail") public R detailInfo(@PathVariable("id") String id) { return R.success(permissionService.getById(id)); - } + }*/ /*@GetMapping("/permissions") @ApiOperation(value = "获取所有菜单权限接口") diff --git a/src/main/java/com/huoran/iasf/entity/SysPermission.java b/src/main/java/com/huoran/iasf/entity/SysPermission.java index cdef760..3fb88a2 100644 --- a/src/main/java/com/huoran/iasf/entity/SysPermission.java +++ b/src/main/java/com/huoran/iasf/entity/SysPermission.java @@ -10,6 +10,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; +import java.util.List; /** * 权限菜单 @@ -63,8 +64,12 @@ public class SysPermission implements Serializable { @TableField(fill = FieldFill.INSERT) private Integer deleted; + @ApiModelProperty(value = "层级") @TableField(exist = false) - @ApiModelProperty(value = "父级菜单权限名称") - private String pidName; + private Integer level; + + @ApiModelProperty(value = "下级") + @TableField(exist = false) + private List children; } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/service/PermissionService.java b/src/main/java/com/huoran/iasf/service/PermissionService.java index 6a5d4bf..87e76e1 100644 --- a/src/main/java/com/huoran/iasf/service/PermissionService.java +++ b/src/main/java/com/huoran/iasf/service/PermissionService.java @@ -59,7 +59,7 @@ public interface PermissionService extends IService { * * @return List */ - List selectAllByTree(); + List selectAllByTree(); /** * 根据目录树 diff --git a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java index c2971a3..dd700db 100644 --- a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java @@ -114,7 +114,7 @@ public class PermissionServiceImpl extends ServiceImpl selectAllByTree() { + public List selectAllByTree() { - List list = selectAll(); - return getTree(list, false); + // List list = selectAll(); + // return getTree(list, false); + + List permissionList = baseMapper.selectList(null); + return build(permissionList); + } + + /** + * 使用递归方法建菜单 + * @param treeNodes 权限菜单 + * @return 权限菜单 + */ + private static List build(List treeNodes) { + List 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 treeNodes) { + treeNode.setChildren(new ArrayList()); + + 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 impleme for (PermissionRespNode node : list) { if (checkList.contains(node.getId()) && CollectionUtils.isEmpty(node.getChildren())) { - node.setChecked(true); + // node.setChecked(true); } setChecked((List) node.getChildren(), checkList); } diff --git a/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java b/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java index d317938..5f3c667 100644 --- a/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java +++ b/src/main/java/com/huoran/iasf/vo/resp/PermissionRespNode.java @@ -26,28 +26,23 @@ public class PermissionRespNode { @ApiModelProperty(value = "接口地址") private String url; - @ApiModelProperty(value = "icon") - private String icon; +/* @ApiModelProperty(value = "icon") + private String icon;*/ - private String target; + // private String target; @ApiModelProperty(value = "父级id") private String pid; - @ApiModelProperty(value = "父级名称") - private String pidName; + // @ApiModelProperty(value = "父级名称") + // private String pidName; - @ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)") - private Integer type; +/* @ApiModelProperty(value = "菜单权限类型(1:目录;2:菜单;3:按钮)") + private Integer type;*/ - @ApiModelProperty(value = "排序码") - private Integer orderNum; +/* @ApiModelProperty(value = "排序码") + private Integer orderNum;*/ - @ApiModelProperty(value = "是否展开 默认不展开(false)") - private boolean spread = true; - - @ApiModelProperty(value = "是否选中 默认false") - private boolean checked; private List children;