예제 #1
0
 @RequestMapping(value = "/assign/resource", method = RequestMethod.POST)
 @ResponseBody
 public String assignResource(
     @RequestParam(value = "id") Integer roleId, @RequestParam List<Integer> resourceIds) {
   roleResourceService.assignResource(roleId, resourceIds);
   return success("角色授权成功!");
 }
예제 #2
0
 @RequestMapping(value = "/{id}/resources/tree")
 @ResponseBody
 public String getRoleTreeNodes(@PathVariable("id") Integer roleId) {
   // 所有资源节点
   List<Resource> activeResources = resourceService.findActiveResources();
   List<TreeNode> activeTreeNodes = new ArrayList<TreeNode>();
   if (activeResources != null) {
     for (Resource resource : activeResources) {
       activeTreeNodes.add(resource.toTreeNode());
     }
   }
   // 构建树结构
   List<TreeNode> treeNodes = TreeNodeUtil.buildTree(activeTreeNodes);
   // 角色拥有的资源id
   List<Integer> resourceIds = roleResourceService.findResourceIdsByRoleId(roleId);
   if (activeTreeNodes != null && resourceIds != null) {
     for (TreeNode treeNode : activeTreeNodes) {
       if (resourceIds.contains(treeNode.getId()) && treeNode.getChildren().size() < 1) {
         treeNode.setChecked(true);
       }
     }
   }
   return success(treeNodes);
 }