| | |
| | | } |
| | | |
| | | /** |
| | | * 根据用户返回所有菜单下的按钮(树形结构) |
| | | * |
| | | * @param treeQueryObject |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MenuVO> buttons(TreeQueryObject treeQueryObject) { |
| | | //1、先根据session判断当前用户类型 |
| | | SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException(); |
| | | boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId()); |
| | | String parentId; |
| | | //2、根据不同用户返回不同的节点下的菜单和按钮 |
| | | if (adminOrDeveloperOrRoot) { |
| | | //系统菜单 |
| | | parentId = SYSTEMMANAGMENTNODE; |
| | | } else if (rightControlUtil.isThreeAdminCurUser()) { |
| | | //三员返回管理功能模块相关的菜单 |
| | | parentId = SYSTEMMANAGMENTNODE; |
| | | } else { |
| | | // 普通用户只返回业务功能模块相关的菜单, |
| | | // 但可能存在普通用户分配系统功能的菜单和按钮权限,不过需要 |
| | | // 再业务功能模块下创建对应的管理功能模块的菜单并进行授权。 |
| | | parentId = ROOT_MENU_ID; |
| | | } |
| | | RoleRightInfo[] userRoleRights = rightControlUtil.getRoleRightByUserName(sessionInfo.getUserId()); |
| | | //3、根据角色查询出对应的父节点下的所有的菜单,然后再获取菜单下的所有按钮 |
| | | //List<FunctionInfo> menuList = rightControlUtil.getMenusByPIdAndPermission(parentId, sessionInfo.getUserId(),userRoleRights); |
| | | Map<String, List<FunctionInfo>> map = rightControlUtil.getAllChildrenFunctionsByUserName( |
| | | parentId, sessionInfo.getUserId(), userRoleRights); |
| | | List<MenuVO> functionVOList = new ArrayList<>(); |
| | | //4、先获取parentid对应的菜单,再获取每一层子节点,同时过滤掉按钮未启用的功能模块 |
| | | for (FunctionInfo menu : map.get(parentId)) { |
| | | if(!menu.isValid){ |
| | | continue; |
| | | } |
| | | MenuVO functionVO = new MenuVO(); |
| | | functionVO.setId(menu.id); |
| | | functionVO.setSource(menu.image); |
| | | functionVO.setPath(menu.resourceB); |
| | | functionVO.setParentId(menu.parentId); |
| | | functionVO.setCode(menu.aliasName); |
| | | functionVO.setAlias(menu.aliasName); |
| | | functionVO.setName(menu.name); |
| | | functionVO.setFunctionType(menu.functionType); |
| | | functionVO.setIsValid(menu.isValid); |
| | | functionVO.getMeta().put("keepAlive",false); |
| | | functionVO.setSort((int) menu.seq); |
| | | try { |
| | | functionVO.setChildren(findChildFunctionVO(menu.id, map)); |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | String errorMsg = "菜单查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(errorMsg); |
| | | throw new VciBaseException(errorMsg); |
| | | } |
| | | if(functionVO.getChildren().size() > 0){ |
| | | functionVO.setHasChildren(true); |
| | | }else { |
| | | functionVO.setHasChildren(false); |
| | | } |
| | | functionVOList.add(functionVO); |
| | | } |
| | | //6、过滤出实际的菜单节点 |
| | | List<MenuVO> menuVOList = new ArrayList<>(); |
| | | recursionFunction(functionVOList,menuVOList); |
| | | // 5、处理每一个菜单下需要返回的按钮 |
| | | menuVOList.stream().forEach(menuVO -> { |
| | | try { |
| | | //6、获取当前菜单下的按钮 |
| | | Map<String, Long> authMap = Arrays.stream(userRoleRights).collect(Collectors.toMap(e -> e.funcId, e -> e.rightValue, |
| | | (existing, replacement) -> existing)); |
| | | menuVO.setChildren(getButtonsByAuth(menuVO.getId(),adminOrDeveloperOrRoot,authMap)); |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | String errorMsg = "按钮查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(errorMsg); |
| | | throw new VciBaseException(errorMsg); |
| | | } |
| | | }); |
| | | return menuVOList; |
| | | } |
| | | |
| | | /** |
| | | * 过滤出菜单只返回菜单节点 |
| | | * @param sourceList |
| | | * @param targetList |
| | | */ |
| | | private static void recursionFunction(List<MenuVO> sourceList, List<MenuVO> targetList) { |
| | | for (MenuVO menu : sourceList) { |
| | | // 检查functionType是否为0 |
| | | if (menu.getFunctionType() == 0) { |
| | | targetList.add(menu); |
| | | } |
| | | // 递归处理children |
| | | recursionFunction(menu.getChildren(), targetList); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据菜单主键和角色权限获取其下的按钮 |
| | | * @param parentOid |
| | | * @return |
| | | * @throws PLException |
| | | */ |
| | | private List<MenuVO> getButtonsByAuth(String parentOid,boolean adminOrDeveloperOrRoot,Map<String, Long> authMap) throws PLException { |
| | | List<MenuVO> buttonList = new ArrayList<>(); |
| | | if(Func.isBlank(parentOid)){ |
| | | return buttonList; |
| | | } |
| | | FuncOperationInfo[] funcOperates = platformClientUtil.getFrameworkService().getFuncOperationByModule(parentOid, "", true); |
| | | List<FuncOperationInfo> funcOperationList = new ArrayList<>(); |
| | | if(!adminOrDeveloperOrRoot){ |
| | | for (int i = 0; i < funcOperates.length; i++) { |
| | | if(authMap.containsKey(funcOperates[i].funcId)){ |
| | | long rightValue = authMap.get(funcOperates[i].funcId); |
| | | long nodeValue = funcOperates[i].number; |
| | | long preValue = (rightValue >> nodeValue) & 1; |
| | | //进行位与操作,如果相等则表示具有当前操作的权限 |
| | | if (preValue == 1) { |
| | | funcOperationList.add(funcOperates[i]); |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | funcOperationList = Arrays.asList(funcOperates); |
| | | } |
| | | if(Func.isNotEmpty(funcOperationList)){ |
| | | for(FuncOperationInfo info: funcOperationList){ |
| | | MenuVO menuVO = new MenuVO(); |
| | | menuVO.setChildType(0); |
| | | menuVO.setId(info.id); |
| | | menuVO.setFuncId(info.funcId); |
| | | menuVO.setCode(info.operIndentify); |
| | | menuVO.setOperId(info.operId); |
| | | menuVO.setName(info.operName); |
| | | menuVO.setAlias(info.operAlias); |
| | | menuVO.setRemark(info.operDesc); |
| | | menuVO.setSort((int) info.number); |
| | | menuVO.setIsValid(info.isValid); |
| | | menuVO.setHasChildren(false); |
| | | menuVO.setCategory(1); |
| | | menuVO.setFunctionType(2); |
| | | buttonList.add(menuVO); |
| | | } |
| | | } |
| | | return buttonList; |
| | | } |
| | | |
| | | /** |
| | | * 原平台功能转换为新平台的功能 |
| | | * @param functionForPlatform1List 原平台功能对象列表 |
| | | * @return 新平台功能对象 |
| | |
| | | } |
| | | functionVOList.add(functionVO); |
| | | } |
| | | //如果是开发或者测试用户,需哟获取系统模块配置菜单 |
| | | //如果是开发或者测试用户,需要获取系统模块配置菜单 |
| | | if(adminOrDeveloperOrRoot){ |
| | | //获取首页系统模块配置菜单 |
| | | MenuVO menuVO = JsonConfigReader.getSysModuleConf().getSysModuleNode(); |
| | |
| | | if(childType == 2){ |
| | | try{ |
| | | FuncOperationInfo[] infos = platformClientUtil.getFrameworkService().getFuncOperationByModule(parentId, "", false); |
| | | if(Func.isNotEmpty(infos.length)){ |
| | | if(Func.isNotEmpty(infos)){ |
| | | childType = this.checkChildObject(infos[0].id); //都是同一层所以取第一个即可查询是什么类型 |
| | | for(int i = 0;i < infos.length ;i++){ |
| | | FuncOperationInfo info = infos[i]; |
| | |
| | | menuVO.setIsValid(info.isValid); |
| | | menuVO.setHasChildren(false); |
| | | menuVO.setCategory(1); |
| | | menuVO.setFunctionType(2); |
| | | menuVO.setFunctionType(3); |
| | | menuVOList.add(menuVO); |
| | | } |
| | | } |
| | |
| | | * @param funcInfo |
| | | * @return |
| | | */ |
| | | private MenuVO functionInfoToMenuVO(FunctionInfo funcInfo) |
| | | { |
| | | private MenuVO functionInfoToMenuVO(FunctionInfo funcInfo) { |
| | | MenuVO menuVO = new MenuVO(); |
| | | menuVO.setId(funcInfo.id); |
| | | menuVO.setIsValid(funcInfo.isValid); |
| | |
| | | functionVO.setId(menu.id); |
| | | functionVO.setSource(menu.image); |
| | | functionVO.setFunctionType(menu.functionType); |
| | | // if(StringUtils.isBlank(menu.resourceB) ){ |
| | | // continue; |
| | | // } |
| | | functionVO.setIsValid(menu.isValid); |
| | | functionVO.setPath(menu.resourceB); |
| | | functionVO.setCode(menu.aliasName); |
| | | functionVO.setAlias(menu.aliasName); |
| | |
| | | List<String> authList = new ArrayList<>(); |
| | | for (FunctionInfo functionInfo : moduleListByParentId) { |
| | | if(authMap.containsKey(functionInfo.id)){ |
| | | // authList.add(functionInfo.id); |
| | | // authList.add(functionInfo.id); |
| | | getChildAuthNode(functionInfo, authMap, authList); |
| | | } |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 通过模块ID获取子级列表 |
| | | * @param isAll 是否包括无效的模块,true则包括 |
| | |
| | | return functionVOList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 通过模块ID获取子级列表 |
| | | * @param parentId |
| | |
| | | funcInfos = platformClientUtil.getFrameworkService().getModuleListByParentId(parentId, isAll); |
| | | return funcInfos; |
| | | } |
| | | |
| | | } |