| | |
| | | import lombok.NoArgsConstructor; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | */ |
| | | @Resource |
| | | private SmRoleQueryServiceI smRoleQueryServiceI; |
| | | |
| | | /*** |
| | | * 是否是管理员 |
| | | */ |
| | | @Autowired |
| | | RightControlUtil rightControlUtil; |
| | | /** |
| | | * 业务类型 |
| | | */ |
| | |
| | | return treeList; |
| | | } |
| | | |
| | | /*** |
| | | * UI授权 |
| | | * @param uiAuthorDTO |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public boolean authorizedUI(UIAuthorDTO uiAuthorDTO) throws Exception { |
| | | boolean res=false; |
| | |
| | | treeQueryObject.setConditionMap(conditionMap); |
| | | List<Tree> treeList=this.getUIAuthor(treeQueryObject); |
| | | HashMap<String,Tree> allTreeMap=new HashMap<>(); |
| | | Map<String,RoleRightVO> roleRightVOMap=new HashMap<>(); |
| | | if(!CollectionUtil.isEmpty(treeList)){ |
| | | if(StringUtils.isNotBlank(uiAuthorDTO.getRoleId())){ |
| | | String userName= WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | RoleRightInfo[] rightInfos= platformClientUtil.getFrameworkService().getRoleRightList(uiAuthorDTO.getRoleId(),userName); |
| | | List<RoleRightVO> roleRightVOList=roleRightDOO2VOS(Arrays.asList(rightInfos)); |
| | | roleRightVOMap=roleRightVOList.stream().collect(Collectors.toMap(RoleRightVO::getFuncId,roleRightVO ->roleRightVO)); |
| | | } |
| | | convertTreeDOO2Map(treeList,allTreeMap); |
| | | List<RoleRightDTO> roleRightDTOList=new ArrayList<>(); |
| | | List<Tree> selectTreeList= uiAuthorDTO.getSelectTreeList(); |
| | | getRoleRightDTOS(uiAuthorDTO.getRoleId(),selectTreeList,allTreeMap,roleRightDTOList); |
| | | getSelectedRoleRightObjs(uiAuthorDTO.getRoleId(),selectTreeList,allTreeMap,roleRightDTOList); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | private void getRoleRightDTOS(String roleOid,List<Tree> selectTreeList,HashMap<String,Tree> allTreeMap, List<RoleRightDTO> roleRightDTOList){ |
| | | /** |
| | | * |
| | | * @param roleOid |
| | | * @param selectTreeList |
| | | * @param allTreeMap |
| | | * @param roleRightDTOList |
| | | */ |
| | | private void getSelectedRoleRightObjs(String roleOid,List<Tree> selectTreeList,HashMap<String,Tree> allTreeMap, List<RoleRightDTO> roleRightDTOList){ |
| | | Date date=new Date(); |
| | | Map<String,RoleRightDTO> roleRightDTOMap=new HashMap<>(); |
| | | selectTreeList.stream().forEach(tree -> { |
| | | RoleRightDTO roleRightDTO=new RoleRightDTO(); |
| | | String id=ObjectUtility.getNewObjectID36(); |
| | | Object data= tree.getData(); |
| | | |
| | | if (data instanceof BizType) {//业务类型 |
| | | BizType bizType=(BizType)data; |
| | | roleRightDTO.setId(id);//主键 |
| | | roleRightDTO.setCreateUser(null);//创建者 |
| | | roleRightDTO.setCreateTime(null);//创建时间 |
| | | roleRightDTO.setModifyUser(null);//修改者 |
| | | roleRightDTO.setModifyTime(null);//修改时间 |
| | | roleRightDTO.setRoleId(roleOid);//角色ID |
| | | roleRightDTO.setRightValue(1);// 权限值 |
| | | roleRightDTO.setRightType((short) -1);//权限类型 权限类型,超级管理员给管理员授权为1,管理员给普通用户授权为2 |
| | | roleRightDTO.setFuncId(null); |
| | | roleRightDTO.setLicensor(null); |
| | | }else if (data instanceof PLUILayout){//UI |
| | | |
| | | }else if (data instanceof PLTabPage) {//UI上下文 |
| | | |
| | | |
| | | }else if (data instanceof PLPageDefination) {// |
| | | |
| | | |
| | | if(data instanceof String){ |
| | | getRightValue(roleOid,tree,allTreeMap,false,roleRightDTOMap);//向下获取所有模块的权限值 |
| | | }else if (!(data instanceof PLTabButton)) {//业务类型 |
| | | getRightValue(roleOid,tree,allTreeMap,true,roleRightDTOMap);//向上处理 |
| | | getRightValue(roleOid,tree,allTreeMap,false,roleRightDTOMap);//向下处理(包含当前节点) |
| | | }else if (data instanceof PLTabButton) {//按钮 |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | } |
| | | /** |
| | | * 获取权限 |
| | | * @param isUp 是否是向上获取,如果是向上获取,传进来的必然是模块节点,且上级模块必然是没有选中 |
| | | */ |
| | | private void getRightValue(String roleId,Tree node,HashMap<String,Tree> allTreeMap,boolean isUp,Map<String,RoleRightDTO> rightMap){ |
| | | SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread(); |
| | | String currentUserName = sessionInfo.getUserId(); |
| | | boolean isDeveloper= rightControlUtil.isDeveloper(currentUserName); |
| | | String parentOid=node.getParentId(); |
| | | if(allTreeMap.containsKey(parentOid)){ |
| | | String id=ObjectUtility.getNewObjectID36(); |
| | | Tree parentNode =allTreeMap.get(parentOid); |
| | | Object parentData= parentNode.getData(); |
| | | if(isUp) {//向上获取,存储每个上级模块的权限值 |
| | | while (!"root".equals(parentNode.getData())){ |
| | | String funcId = ""; |
| | | if (parentData instanceof BizType) { |
| | | BizType bizType = (BizType) parentData; |
| | | funcId = bizType.name; |
| | | } else if (parentData instanceof PLUILayout) { |
| | | PLUILayout context = (PLUILayout)parentData; |
| | | funcId = context.plOId; |
| | | } else if (parentData instanceof PLTabPage) { |
| | | PLTabPage tab = (PLTabPage) parentData; |
| | | funcId = tab.plOId; |
| | | } else if (parentData instanceof PLPageDefination){ |
| | | PLPageDefination pageDef = (PLPageDefination) parentData; |
| | | funcId = pageDef.plOId; |
| | | } else if (parentData instanceof PLTabButton) { |
| | | PLTabButton but = (PLTabButton)parentData; |
| | | funcId = but.plOId; |
| | | } |
| | | RoleRightDTO roleRightDTO = new RoleRightDTO(); |
| | | roleRightDTO.setId(id);//主键 |
| | | roleRightDTO.setFuncId(funcId); |
| | | if(isDeveloper) { |
| | | roleRightDTO.setRightType((short) 1);//权限类型 权限类型,超级管理员给管理员授权为1,管理员给普通用户授权为2 |
| | | }else{ |
| | | roleRightDTO.setRightType((short) 2); |
| | | } |
| | | roleRightDTO.setRightValue(1);// 权限值,没有操作的模块权限值存储为0 |
| | | roleRightDTO.setRoleId(roleId);//角色ID |
| | | roleRightDTO.setCreateUser(currentUserName);//创建者 |
| | | roleRightDTO.setCreateTime(new Date());//创建时间 |
| | | roleRightDTO.setModifyUser(currentUserName);//修改者 |
| | | roleRightDTO.setModifyTime(new Date());//修改时间 |
| | | roleRightDTO.setLicensor(""); |
| | | if(!rightMap.containsKey(funcId)){ |
| | | rightMap.put(funcId, roleRightDTO); |
| | | } |
| | | } |
| | | }else{ |
| | | String funcId = ""; |
| | | if(parentData instanceof String){ |
| | | funcId = (String)parentData; |
| | | } else if (parentData instanceof BizType) { |
| | | BizType bizType = (BizType)parentData; |
| | | funcId = bizType.name; |
| | | } else if (parentData instanceof PLUILayout) { |
| | | PLUILayout context = (PLUILayout)parentData; |
| | | funcId = context.plOId; |
| | | } else if (parentData instanceof PLTabPage) { |
| | | PLTabPage tab = (PLTabPage) parentData; |
| | | funcId = tab.plOId; |
| | | } else if (parentData instanceof PLPageDefination){ |
| | | PLPageDefination pageDef = (PLPageDefination) parentData; |
| | | funcId = pageDef.plOId; |
| | | } else if (parentData instanceof PLTabButton) { |
| | | PLTabButton but = (PLTabButton)parentData; |
| | | funcId = but.plOId; |
| | | } |
| | | if(!(parentData instanceof PLPageDefination)) {//子节点不是操作 |
| | | if(!rightMap.containsKey(funcId)&&!funcId.equals("root")){ |
| | | RoleRightDTO roleRightDTO = new RoleRightDTO(); |
| | | roleRightDTO.setFuncId(funcId); |
| | | if(isDeveloper) { |
| | | roleRightDTO.setRightType((short) 1);//权限类型 权限类型,超级管理员给管理员授权为1,管理员给普通用户授权为2 |
| | | }else{ |
| | | roleRightDTO.setRightType((short) 2); |
| | | } |
| | | roleRightDTO.setRightValue(0);//没有操作的模块权限值存储为0 |
| | | roleRightDTO.setRoleId(roleId); |
| | | roleRightDTO.setCreateUser(currentUserName); |
| | | roleRightDTO.setCreateTime(new Date()); |
| | | roleRightDTO.setModifyUser(currentUserName); |
| | | roleRightDTO.setModifyTime(new Date()); |
| | | roleRightDTO.setLicensor(""); |
| | | rightMap.put(funcId, roleRightDTO); |
| | | } |
| | | for(int i = 0;i < parentNode.getChildren().size();i++){ |
| | | //对每个子向下递归遍历 |
| | | getRightValue(roleId,parentNode.getChildren().get(i),allTreeMap,false,rightMap); |
| | | } |
| | | }else { |
| | | if(!rightMap.containsKey(funcId)){ |
| | | RoleRightDTO roleRightDTO = new RoleRightDTO(); |
| | | roleRightDTO.setFuncId(funcId); |
| | | roleRightDTO.setRightType((short)2); // 设置UI权限 |
| | | roleRightDTO.setRightValue(countRightValue(parentNode,true));//没有操作的模块权限值存储为0 |
| | | roleRightDTO.setRoleId(roleId); |
| | | |
| | | roleRightDTO.setCreateUser(currentUserName); |
| | | roleRightDTO.setCreateTime(new Date()); |
| | | roleRightDTO.setModifyUser(currentUserName); |
| | | roleRightDTO.setModifyTime(new Date()); |
| | | roleRightDTO.setLicensor(""); |
| | | rightMap.put(funcId, roleRightDTO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | /** |
| | | * 传入直接挂接操作的模块的节点,计算该节点的权限值 |
| | | * @param node 模块节点 |
| | | * @param isAll 是否子级全部选中 |
| | | * @return |
| | | */ |
| | | private long countRightValue(Tree node,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 ){ |
| | | PLTabButton obj = (PLTabButton)node.getData(); |
| | | value += (long)Math.pow(2, obj.plSeq);//累计加上各个操作的权限值 |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | /** |
| | | * |