| | |
| | | import com.vci.corba.portal.data.*; |
| | | import com.vci.dto.RoleRightDTO; |
| | | import com.vci.dto.UIAuthorDTO; |
| | | import com.vci.frameworkcore.compatibility.SmRoleQueryServiceI; |
| | | import com.vci.model.PLDefination; |
| | | import com.vci.pagemodel.PLDefinationVO; |
| | | import com.vci.pagemodel.PLTabButtonVO; |
| | | import com.vci.pagemodel.PLUILayoutCloneVO; |
| | | import com.vci.pagemodel.RoleRightVO; |
| | | import com.vci.pagemodel.*; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | import com.vci.starter.web.pagemodel.*; |
| | | import com.vci.starter.web.pagemodel.BaseQueryObject; |
| | |
| | | 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; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.swing.*; |
| | | import javax.swing.tree.TreePath; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | */ |
| | | @Resource |
| | | private PlatformClientUtil platformClientUtil; |
| | | |
| | | /*** |
| | | * 是否是管理员 |
| | | */ |
| | | @Autowired |
| | | RightControlUtil rightControlUtil; |
| | | |
| | | /** |
| | | * 业务类型 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<PLTabButtonVO> getTabButton(String pageDefinationOid) { |
| | | public List<PLTabButtonVO> getTabButtons(String pageDefinationOid) { |
| | | VciBaseUtil.alertNotNull(pageDefinationOid,"页面定义主键"); |
| | | List<PLTabButton> buttonList = new ArrayList<>(); |
| | | try { |
| | | PLTabButton[] plTabButtons = platformClientUtil.getUIService().getPLTabButtonsByTableOId(pageDefinationOid); |
| | | buttonList = Arrays.asList(plTabButtons); |
| | | return this.tabButton2TabButtonVOS(buttonList); |
| | | List<PLTabButtonVO> plTabButtonVOList = this.tabButton2TabButtonVOS(buttonList); |
| | | PLTabButtonVO plTabButtonVO = new PLTabButtonVO(); |
| | | for(int i = 0; i < plTabButtonVOList.size(); i++){ |
| | | plTabButtonVO = plTabButtonVOList.get(i); |
| | | |
| | | if(plTabButtonVO.getParentOid().equals("")){ |
| | | plTabButtonVO.setChildren(plTabButtonVO2Children(plTabButtonVOList,plTabButtonVO.getOId())); |
| | | } |
| | | } |
| | | return plTabButtonVOList; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new VciBaseException("加载页签区域按钮配置信息异常:" + e.getMessage()); |
| | |
| | | plTabButtonVO.setButtonParams(parameterMap); |
| | | } |
| | | return plTabButtonVO; |
| | | } |
| | | |
| | | /** |
| | | * 按钮配置子节点查找 |
| | | * @param plOid |
| | | * @param plTabButtonVOList |
| | | * @return |
| | | */ |
| | | private List<PLTabButtonVO> plTabButtonVO2Children(List<PLTabButtonVO> plTabButtonVOList, String plOid){ |
| | | ArrayList<PLTabButtonVO> plTabButtonVOS = new ArrayList<>(); |
| | | for (PLTabButtonVO plTabButtonVO : plTabButtonVOList) { |
| | | if(StringUtils.isBlank(plTabButtonVO.getParentOid())){ |
| | | continue; |
| | | } |
| | | if(plTabButtonVO.getParentOid().equals(plOid)){ |
| | | plTabButtonVO.setChildren(plTabButtonVO2Children(plTabButtonVOList,plOid)); |
| | | plTabButtonVOS.add(plTabButtonVO); |
| | | } |
| | | } |
| | | return plTabButtonVOS; |
| | | } |
| | | |
| | | /** |
| | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 删除单个按钮配置 |
| | | * @param tabButton |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean deleteTapButton(PLTabButton tabButton) throws PLException { |
| | | VciBaseUtil.alertNotNull(tabButton,"删除的按钮配置对象"); |
| | | boolean success = UITools.getService().deletePLTabButton(tabButton); |
| | | if(success == false){ |
| | | throw new VciBaseException("该有子级按钮,不能删除!"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 调整为下级按钮 |
| | | * @param plTabButton |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BaseResult joinBtn(PLTabButton plTabButton) throws PLException { |
| | | VciBaseUtil.alertNotNull(plTabButton,"需调整为下级按钮",plTabButton.plTableOId,"当前按钮配置所在的页面主键"); |
| | | //同一页面下的按钮 |
| | | List<PLTabButtonVO> plTabButtons = this.getTabButtons(plTabButton.plTableOId); |
| | | if(Func.isEmpty(plTabButtons)){ |
| | | return BaseResult.fail("未获取到按钮配置信息!"); |
| | | } |
| | | //获取当前要移动的按钮的下标 |
| | | int index = 0; |
| | | for (int i = 0; i < plTabButtons.size(); i++) { |
| | | if (plTabButtons.get(i).getOId().equals(plTabButton.plOId)) { |
| | | index = i; // 找到后记录下标 |
| | | break; // 找到后退出循环 |
| | | } |
| | | } |
| | | //当选择的按钮为树的第一个节点的时候,他的兄节点是他自己,导致调整为下级按钮时出错,故作此判断。 |
| | | if(index == 0){ |
| | | return BaseResult.fail("当前节点不存在兄节点,无法调整为下级按钮!"); |
| | | } |
| | | //设置父id为上一个节点的 |
| | | plTabButton.plParentOid = plTabButtons.get(index-1).getOId(); |
| | | |
| | | boolean success = platformClientUtil.getUIService().updatePLTabButton(plTabButton); |
| | | if(success == false) { |
| | | return BaseResult.fail("修改失败!"); |
| | | } |
| | | return BaseResult.fail("修改成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 调整为上级按钮 |
| | | * @param plTabButton |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BaseResult exitBtn(PLTabButton plTabButton) throws PLException { |
| | | plTabButton.plParentOid = ""; |
| | | |
| | | boolean success = platformClientUtil.getUIService().updatePLTabButton(plTabButton); |
| | | if(success == false) { |
| | | BaseResult.fail("撤销失败!"); |
| | | } |
| | | return BaseResult.success("撤销成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 处理配置的event事件 |
| | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void setChildNode(List<Tree> parentTree, List<PLUILayout>contextList,Map<String,RoleRightVO> roleRightVOMap,boolean isShowCheckBox){ |
| | | Optional.ofNullable(parentTree).orElseGet(()->new ArrayList<Tree>()).stream().forEach(pTree -> { |
| | | Object funcObj= pTree.getData(); |