| | |
| | | package com.vci.web.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.vci.common.utility.ObjectUtility; |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.common.data.UserEntityInfo; |
| | |
| | | convertTreeDOO2Map(treeList,allTreeMap); |
| | | List<RoleRightDTO> roleRightDTOList = new ArrayList<>(); |
| | | List<Tree> selectTreeList = uiAuthorDTO.getSelectTreeList(); |
| | | List<Tree> selectTreeList2 = this.authTreeListConvert(selectTreeList); |
| | | getSelectedRoleRightObjs_old(uiAuthorDTO.getRoleId(),selectTreeList2,allTreeMap,roleRightDTOList); |
| | | List<Tree> filterSelectTreeList = this.authTreeListConvert(selectTreeList); |
| | | //过滤出选择的按钮 |
| | | List<String> checkButtonList = new ArrayList<>(); |
| | | selectTreeList.stream().forEach(item->{ |
| | | Object data = item.getData(); |
| | | if(data instanceof PLTabButton || item.isLeaf()){ |
| | | checkButtonList.add(item.getOid()); |
| | | } |
| | | }); |
| | | |
| | | getSelectedRoleRightObjs(uiAuthorDTO.getRoleId(),filterSelectTreeList,checkButtonList,allTreeMap,roleRightDTOList); |
| | | SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread(); |
| | | String currentUserName = sessionInfo.getUserId(); |
| | | //boolean isDeveloper = rightControlUtil.isDeveloper(currentUserName); |
| | |
| | | * @param selectTreeList |
| | | */ |
| | | private List<Tree> authTreeListConvert(List<Tree> selectTreeList){ |
| | | |
| | | // 创建一个包含另一个集合中满足条件的 oid 的集合 |
| | | List<String> validOids = selectTreeList.stream() |
| | | .filter(Tree::isChecked) // checked 为 true |
| | |
| | | * @param allTreeMap |
| | | * @param roleRightDTOList |
| | | */ |
| | | private void getSelectedRoleRightObjs_old(String roleOid, List<Tree> selectTreeList, HashMap<String,Tree> allTreeMap, List<RoleRightDTO> roleRightDTOList){ |
| | | private void getSelectedRoleRightObjs(String roleOid, List<Tree> selectTreeList, List<String> checkButtonList, HashMap<String,Tree> allTreeMap, List<RoleRightDTO> roleRightDTOList){ |
| | | Map<String,RoleRightDTO> roleRightDTOMap = new HashMap<>(); |
| | | |
| | | if(!CollectionUtil.isEmpty(selectTreeList)){ |
| | | selectTreeList.stream().forEach(tree -> { |
| | | String oid = tree.getOid(); |
| | | if(allTreeMap.containsKey(oid)){ |
| | | tree = allTreeMap.get(oid); |
| | | Object data = tree.getData(); |
| | | Object data = tree.getData(); |
| | | if (data instanceof String) { |
| | | getRightValue(roleOid, tree, allTreeMap, false, roleRightDTOMap);//向下获取所有模块的权限值 |
| | | getRightValue(roleOid, tree, allTreeMap, checkButtonList,false, roleRightDTOMap);//向下获取所有模块的权限值 |
| | | } else if (!(data instanceof PLTabButton)) {//业务类型 |
| | | getRightValue(roleOid, tree, allTreeMap, true, roleRightDTOMap);//向上处理 |
| | | getRightValue(roleOid, tree, allTreeMap, false, roleRightDTOMap);//向下处理(包含当前节点) |
| | | getRightValue(roleOid, tree, allTreeMap, checkButtonList, true, roleRightDTOMap);//向上处理 |
| | | getRightValue(roleOid, tree, allTreeMap, checkButtonList, false, roleRightDTOMap);//向下处理(包含当前节点) |
| | | } else if (data instanceof PLTabButton) {//按钮 |
| | | String parrentId=tree.getParentId(); |
| | | if(allTreeMap.containsKey(parrentId)){ |
| | |
| | | boolean isDeveloper = rightControlUtil.isDeveloper(currentUserName); |
| | | Tree parentNode= allTreeMap.get(parrentId); |
| | | String funcId = parentNode.getOid(); |
| | | getRightValue(roleOid, tree, allTreeMap, true, roleRightDTOMap);//向上处理该操作父级的上级模块权限(不包含父节点) |
| | | getRightValue(roleOid, parentNode, allTreeMap, checkButtonList, true, roleRightDTOMap);//向上处理该操作父级的上级模块权限(不包含父节点) |
| | | if(!roleRightDTOMap.containsKey(funcId)){ |
| | | RoleRightDTO roleRightDTO = new RoleRightDTO(); |
| | | roleRightDTO.setId(ObjectUtility.getNewObjectID36());//主键 |
| | |
| | | }else{ |
| | | roleRightDTO.setRightType((short) 2); |
| | | } |
| | | roleRightDTO.setRightValue(countRightValue(parentNode,false));// 权限值,没有操作的模块权限值存储为0 |
| | | roleRightDTO.setRightValue(countRightValue(parentNode,checkButtonList,false));// 权限值,没有操作的模块权限值存储为0 |
| | | roleRightDTO.setRoleId(roleOid);//角色ID |
| | | roleRightDTO.setCreateUser(currentUserName);//创建者 |
| | | roleRightDTO.setCreateTime(VciDateUtil.date2Str(new Date(),""));//创建时间 |
| | |
| | | * 获取权限 |
| | | * @param isUp 是否是向上获取,如果是向上获取,传进来的必然是模块节点,且上级模块必然是没有选中 |
| | | */ |
| | | private void getRightValue(String roleId,Tree node,HashMap<String,Tree> allTreeMap,boolean isUp,Map<String,RoleRightDTO> rightMap){ |
| | | private void getRightValue(String roleId,Tree node,Map<String,Tree> allTreeMap,List<String> checkButton,boolean isUp,Map<String,RoleRightDTO> rightMap){ |
| | | SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread(); |
| | | String currentUserName = sessionInfo.getUserId(); |
| | | boolean isDeveloper= rightControlUtil.isDeveloper(currentUserName); |
| | | String id=ObjectUtility.getNewObjectID36(); |
| | | Object data=node.getData(); |
| | | if(isUp) {//向上获取,存储每个上级模块的权限值 |
| | | while (!"root".equals(node.getData())){ |
| | | data=node.getData(); |
| | | String oid=node.getOid(); |
| | | String parentId = node.getParentId(); |
| | | Tree parentNode = allTreeMap.get(parentId); |
| | | while (!"root".equals(parentNode.getData())){ |
| | | data=parentNode.getData(); |
| | | String oid=parentNode.getOid(); |
| | | if(allTreeMap.containsKey(oid)){ |
| | | String funcId = ""; |
| | | if (data instanceof BizType) { |
| | |
| | | if(!rightMap.containsKey(funcId)){ |
| | | rightMap.put(funcId, roleRightDTO); |
| | | } |
| | | oid= node.getParentId(); |
| | | oid = parentNode.getParentId(); |
| | | if(allTreeMap.containsKey(oid)) { |
| | | node=allTreeMap.get(oid); |
| | | parentNode = allTreeMap.get(oid); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | for (int i = 0; i < node.getChildren().size(); i++) { |
| | | //对每个子向下递归遍历 |
| | | getRightValue(roleId, node.getChildren().get(i), allTreeMap, false, rightMap); |
| | | getRightValue(roleId, node.getChildren().get(i), allTreeMap, checkButton,false, rightMap); |
| | | } |
| | | } else { |
| | | if (!rightMap.containsKey(funcId)) { |
| | | RoleRightDTO roleRightDTO = new RoleRightDTO(); |
| | | roleRightDTO.setFuncId(funcId); |
| | | roleRightDTO.setRightType((short) 2); // 设置UI权限 |
| | | roleRightDTO.setRightValue(countRightValue(node, true));//没有操作的模块权限值存储为0 |
| | | roleRightDTO.setRightValue(countRightValue(node, checkButton,true));//没有操作的模块权限值存储为0 |
| | | roleRightDTO.setRoleId(roleId); |
| | | |
| | | roleRightDTO.setCreateUser(currentUserName); |
| | |
| | | * @param isAll 是否子级全部选中 |
| | | * @return |
| | | */ |
| | | private long countRightValue(Tree node,boolean isAll){ |
| | | private long countRightValue(Tree node,List<String> checkButton,boolean isAll){ |
| | | long value = 0; |
| | | for(int i = 0; i < node.getChildren().size(); i++){ |
| | | Tree childNode = (Tree)node.getChildren().get(i); |
| | | if(isAll || node.getData() instanceof PLTabButton ){ |
| | | //node.getData() instanceof PLTabButton这儿应该换成是否是选中的按钮节点 |
| | | if(isAll || checkButton.contains(node.getOid())){ |
| | | PLTabButton obj = (PLTabButton)childNode.getData(); |
| | | value += (long)Math.pow(2, obj.plSeq);//累计加上各个操作的权限值 |
| | | } |