ludc
2024-09-13 d79ba1d249da7e4a347107b06be2a2add00fad6e
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java
@@ -1,8 +1,10 @@
package com.vci.web.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.PLException;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.framework.data.RoleRightInfo;
import com.vci.corba.omd.btm.BizType;
import com.vci.corba.portal.PortalService;
@@ -39,6 +41,7 @@
import javax.annotation.Resource;
import java.io.File;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.regex.Pattern;
@@ -57,6 +60,11 @@
    @Resource
    private PlatformClientUtil platformClientUtil;
    /**
     * 角色
     */
    @Resource
    private SmRoleQueryServiceI smRoleQueryServiceI;
    /***
     * 是否是管理员
     */
@@ -136,7 +144,7 @@
    public List<PLUILayout> getUIContextDataByBtName(String btemName,String context) throws PLException {
        VciBaseUtil.alertNotNull(btemName,"业务类型");
        List<PLUILayout> pluiLayoutList=new ArrayList<>();
        List<String> contextList= VciBaseUtil.str2List(context);
        List<String> contextList= new ArrayList<>();
        if(StringUtils.isNotBlank(context)){
            contextList=VciBaseUtil.str2List(context);
        }else{
@@ -1354,7 +1362,7 @@
          String userName= WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
            RoleRightInfo[] rightInfos= platformClientUtil.getFrameworkService().getRoleRightList(roleId,userName);
            List<RoleRightVO>  roleRightVOList=roleRightDOO2VOS(Arrays.asList(rightInfos));
            roleRightVOMap=roleRightVOList.stream().collect(Collectors.toMap(RoleRightVO::getFuncId,roleRightVO ->roleRightVO));
            roleRightVOMap=roleRightVOList.stream().collect(Collectors.toMap(RoleRightVO::getFuncId,roleRightVO ->roleRightVO,(oldValue,newOldValue)->oldValue));
        }
        BizType[] bizTypes=osBtmServiceI.getBizTypes(type);
        List<Tree> treeList=new ArrayList<>();
@@ -1372,12 +1380,10 @@
            bizTypeTree.setShowCheckbox(true);
            bizTypeTree.setParentBtmName(bizTypes[i].name);
            childList.add(bizTypeTree);
            if(roleRightVOMap.containsKey(bizTypes[i].oid)){
                List<PLUILayout>contextList=getUIContextDataByBtName(bizTypes[i].name,context);
                List<Tree> btmChildList=new ArrayList<>();
                btmChildList.add(bizTypeTree);
                setChildNode(btmChildList,contextList,roleRightVOMap,showCheckBox);
            }
            List<PLUILayout>contextList=getUIContextDataByBtName(bizTypes[i].name,context);
            List<Tree> btmChildList=new ArrayList<>();
            btmChildList.add(bizTypeTree);
            setChildNode(btmChildList,contextList,roleRightVOMap,showCheckBox);
        }
        rootNode.setChildren(childList);
        treeList.add(rootNode);
@@ -1405,48 +1411,96 @@
        treeQueryObject.setConditionMap(conditionMap);
        List<Tree> treeList=this.getUIAuthor(treeQueryObject);
        HashMap<String,Tree> allTreeMap=new HashMap<>();
        Map<String,RoleRightVO> roleRightVOMap=new HashMap<>();
        Map<String,RoleRightDTO> 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));
                roleRightVOMap=roleRightVOList.stream().collect(Collectors.toMap(RoleRightVO::getFuncId,roleRightVO ->roleRightVOO2DTO(roleRightVO),(oldValue,newValue)->oldValue));
            }
            convertTreeDOO2Map(treeList,allTreeMap);
            List<RoleRightDTO> roleRightDTOList=new ArrayList<>();
            List<Tree>  selectTreeList= uiAuthorDTO.getSelectTreeList();
            getSelectedRoleRightObjs(uiAuthorDTO.getRoleId(),selectTreeList,allTreeMap,roleRightDTOList);
            getSelectedRoleRightObjs(uiAuthorDTO.getRoleId(),selectTreeList,allTreeMap,roleRightVOMap,roleRightDTOList);
            SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
            String currentUserName = sessionInfo.getUserId();
            boolean isDeveloper= rightControlUtil.isDeveloper(currentUserName);
            List<RoleRightInfo>  roleRightInfoList= roleRightDTOO2InfoS(roleRightDTOList);
            UserEntityInfo info=new UserEntityInfo();
            info.modules="UI授权";
            info.userName=currentUserName;
            try {
             res= platformClientUtil.getFrameworkService().saveRoleRight(roleRightInfoList.toArray(new RoleRightInfo[]{}),uiAuthorDTO.getRoleId(),currentUserName,info);
            }catch (PLException e){
                throw  new Exception("保存失败:"+e.getMessage());
            }
        }
        return res;
    }
    /**
     *
     *根据权限计算上下权限
     * @param roleOid
     * @param selectTreeList
     * @param allTreeMap
     * @param roleRightDTOList
     */
    private void getSelectedRoleRightObjs(String roleOid,List<Tree>  selectTreeList,HashMap<String,Tree> allTreeMap,  List<RoleRightDTO> roleRightDTOList){
    private void getSelectedRoleRightObjs(String roleOid,List<Tree>  selectTreeList,HashMap<String,Tree> allTreeMap,Map<String,RoleRightDTO> allRoleRightDTOMap,  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 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) {//按钮
        if(!CollectionUtil.isEmpty(selectTreeList)){
            selectTreeList.stream().forEach(tree -> {
                String oid=tree.getOid();
                if(allTreeMap.containsKey(oid)){
                    tree=   allTreeMap.get(oid);
                   Object data= tree.getData();
                    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) {//按钮
                        String parrentId=tree.getParentId();
                        if(allTreeMap.containsKey(parrentId)){
                            SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
                            String currentUserName = sessionInfo.getUserId();
                            boolean isDeveloper= rightControlUtil.isDeveloper(currentUserName);
                            Tree parentNode= allTreeMap.get(parrentId);
                            String funcId = parentNode.getOid();
                            getRightValue(roleOid,tree, allTreeMap, true, roleRightDTOMap);//向上处理该操作父级的上级模块权限(不包含父节点)
                            if(!roleRightDTOMap.containsKey(funcId)){
                                RoleRightDTO roleRightDTO = new RoleRightDTO();
                                roleRightDTO.setId(ObjectUtility.getNewObjectID36());//主键
                                roleRightDTO.setFuncId(funcId);
                                if(isDeveloper) {
                                    roleRightDTO.setRightType((short) 1);//权限类型 权限类型,超级管理员给管理员授权为1,管理员给普通用户授权为2
                                }else{
                                    roleRightDTO.setRightType((short) 2);
                                }
                                roleRightDTO.setRightValue(1);// 权限值,没有操作的模块权限值存储为0
                                roleRightDTO.setRoleId(roleOid);//角色ID
                                roleRightDTO.setCreateUser(currentUserName);//创建者
                                roleRightDTO.setCreateTime(VciDateUtil.date2Str(new Date(),""));//创建时间
                                roleRightDTO.setModifyUser(currentUserName);//修改者
                                roleRightDTO.setModifyTime(VciDateUtil.date2Str(new Date(),""));//修改时间
                                roleRightDTO.setLicensor("");
                                if(!roleRightDTOMap.containsKey(funcId)){
                                    roleRightDTOMap.put(funcId, roleRightDTO);
                                }
                                roleRightDTOMap.put(funcId, roleRightDTO);
                            }
                        }
            }
        });
                    }
                }
            });
          /*  allRoleRightDTOMap.putAll(roleRightDTOMap.entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::  getValue)));*/
         List<RoleRightDTO>    newRoleRightDTOList=Optional.ofNullable(roleRightDTOMap).orElseGet(()->new HashMap<String,RoleRightDTO>()).values().stream().collect(Collectors.toList());
            roleRightDTOList.addAll(newRoleRightDTOList);
        }
    }
    /**
@@ -1457,28 +1511,28 @@
        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 id=ObjectUtility.getNewObjectID36();
        Object data=node.getData();
        if(isUp) {//向上获取,存储每个上级模块的权限值
            while (!"root".equals(node.getData())){
                data=node.getData();
               String oid=node.getOid();
                if(allTreeMap.containsKey(oid)){
                    String funcId = "";
                    if (parentData instanceof BizType) {
                        BizType bizType = (BizType) parentData;
                    if (data instanceof BizType) {
                        BizType bizType = (BizType) data;
                        funcId = bizType.name;
                    } else if (parentData instanceof PLUILayout) {
                        PLUILayout context = (PLUILayout)parentData;
                    } else if (data instanceof PLUILayout) {
                        PLUILayout context = (PLUILayout)data;
                        funcId = context.plOId;
                    } else if (parentData instanceof PLTabPage) {
                        PLTabPage tab = (PLTabPage) parentData;
                    } else if (data instanceof PLTabPage) {
                        PLTabPage tab = (PLTabPage) data;
                        funcId = tab.plOId;
                    } else if (parentData instanceof PLPageDefination){
                        PLPageDefination pageDef = (PLPageDefination) parentData;
                    } else if (data instanceof PLPageDefination){
                        PLPageDefination pageDef = (PLPageDefination) data;
                        funcId = pageDef.plOId;
                    } else if (parentData instanceof PLTabButton) {
                        PLTabButton but = (PLTabButton)parentData;
                    } else if (data instanceof PLTabButton) {
                        PLTabButton but = (PLTabButton)data;
                        funcId = but.plOId;
                    }
                    RoleRightDTO roleRightDTO = new RoleRightDTO();
@@ -1492,74 +1546,77 @@
                    roleRightDTO.setRightValue(1);// 权限值,没有操作的模块权限值存储为0
                    roleRightDTO.setRoleId(roleId);//角色ID
                    roleRightDTO.setCreateUser(currentUserName);//创建者
                    roleRightDTO.setCreateTime(new Date());//创建时间
                    roleRightDTO.setCreateTime(VciDateUtil.date2Str(new Date(),""));//创建时间
                    roleRightDTO.setModifyUser(currentUserName);//修改者
                    roleRightDTO.setModifyTime(new Date());//修改时间
                    roleRightDTO.setModifyTime(VciDateUtil.date2Str(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);
                    oid= node.getParentId();
                    if(allTreeMap.containsKey(oid)) {
                        node=allTreeMap.get(oid);
                    }
                }
            }
        }else {
            String funcId = "";
            if (data instanceof String) {
                funcId = (String) data;
            } else if (data instanceof BizType) {
                BizType bizType = (BizType) data;
                funcId = bizType.name;
            } else if (data instanceof PLUILayout) {
                PLUILayout context = (PLUILayout) data;
                funcId = context.plOId;
            } else if (data instanceof PLTabPage) {
                PLTabPage tab = (PLTabPage) data;
                funcId = tab.plOId;
            } else if (data instanceof PLPageDefination) {
                PLPageDefination pageDef = (PLPageDefination) data;
                funcId = pageDef.plOId;
            } else if (data instanceof PLTabButton) {
                PLTabButton but = (PLTabButton) data;
                funcId = but.plOId;
            }
            if (!(data 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(VciDateUtil.date2Str(new Date(),""));
                    roleRightDTO.setModifyUser(currentUserName);
                    roleRightDTO.setModifyTime(VciDateUtil.date2Str(new Date(),""));
                    roleRightDTO.setLicensor("");
                    rightMap.put(funcId, roleRightDTO);
                }
                for (int i = 0; i < node.getChildren().size(); i++) {
                    //对每个子向下递归遍历
                    getRightValue(roleId, node.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(node, true));//没有操作的模块权限值存储为0
                    roleRightDTO.setRoleId(roleId);
                    roleRightDTO.setCreateUser(currentUserName);
                    roleRightDTO.setCreateTime(VciDateUtil.date2Str(new Date(),""));
                    roleRightDTO.setModifyUser(currentUserName);
                    roleRightDTO.setModifyTime(VciDateUtil.date2Str(new Date(),""));
                    roleRightDTO.setLicensor("");
                    rightMap.put(funcId, roleRightDTO);
                }
            }
        }
    }
@@ -1596,6 +1653,13 @@
        });
    }
    /***
     * 遍历子节点
     * @param parentTree
     * @param contextList
     * @param roleRightVOMap
     * @param isShowCheckBox
     */
    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();
@@ -1713,6 +1777,24 @@
        });
    }
    /**
     * UI角色对象转换
     * @param vos
     * @return
     */
    private List<RoleRightDTO> roleRightVOO2DTOS(List<RoleRightVO> vos){
        List<RoleRightDTO> roleRightVOS=new ArrayList<>();
        Optional.ofNullable(vos).orElseGet(()->new ArrayList<>()).stream().forEach(vo -> {
            RoleRightDTO dto=roleRightVOO2DTO(vo);
            roleRightVOS.add(dto);
        });
        return roleRightVOS;
    }
    /**
     * UI角色对象转换
     * @param infos
@@ -1727,7 +1809,25 @@
        return roleRightVOS;
    }
    /**
     * UI角色对象转换
     * @param dtos
     * @return
     */
    private List<RoleRightInfo> roleRightDTOO2InfoS(List<RoleRightDTO> dtos){
        List<RoleRightInfo> roleRightInfoList=new ArrayList<>();
        Optional.ofNullable(dtos).orElseGet(()->new ArrayList<>()).stream().forEach(dto -> {
            RoleRightInfo info= null;
            try {
                info = roleRightDTOO2Info(dto);
            } catch (Exception e) {
                e.printStackTrace();
            }
            roleRightInfoList.add(info);
        });
        return roleRightInfoList;
    }
    /**
     * UI角色对象转换
     * @param info
@@ -1746,6 +1846,45 @@
        vo.setModifyTime(VciDateUtil.date2Str(VciDateUtil.long2Date(info.modifyTime),""));
        vo.setModifyUser(info.modifyUser);
        return vo;
    }
    /**
     * UI角色对象转换
     * @param vo
     * @return
     */
    private RoleRightDTO  roleRightVOO2DTO(RoleRightVO vo){
        RoleRightDTO dto=new RoleRightDTO();
        dto.setId(vo.getId());
        dto.setCreateTime(vo.getCreateTime());
        dto.setCreateUser(vo.getCreateUser());
        dto.setRoleId(vo.getRoleId());
        dto.setRightType(vo.getRightType());
        dto.setLicensor(vo.getLicensor());
        dto.setRightValue(vo.getRightValue());
        dto.setFuncId(vo.getFuncId());
        dto.setModifyTime(vo.getModifyTime());
        dto.setModifyUser(vo.getModifyUser());
        return dto;
    }
    /**
     * UI角色对象转换
     * @param dto
     * @return
     */
    private RoleRightInfo  roleRightDTOO2Info(RoleRightDTO dto) throws Exception {
        RoleRightInfo info=new RoleRightInfo();
        info.id=StringUtils.isBlank(dto.getId())?"":dto.getId();
        info.createTime=StringUtils.isBlank(dto.getCreateTime())?new Date().getTime():VciDateUtil.getTime(VciDateUtil.str2Date(dto.getCreateTime(),""));
        info.createUser=StringUtils.isBlank(dto.getCreateUser())?"":dto.getCreateUser();
        info.roleId=StringUtils.isBlank(dto.getRoleId())?"":dto.getRoleId();
        info.rightType=dto.getRightType();
        info.licensor =StringUtils.isBlank(dto.getLicensor())?"":dto.getLicensor();
        info.rightValue=dto.getRightValue();
        info.funcId=StringUtils.isBlank(dto.getFuncId())?"":dto.getFuncId();
        info.modifyTime=StringUtils.isBlank(dto.getModifyTime())? new Date().getTime() :VciDateUtil.getTime(VciDateUtil.str2Date(dto.getModifyTime(),""));
        info.modifyUser=StringUtils.isBlank(dto.getModifyUser())?"":dto.getModifyUser();
        return info;
    }
    /**
@@ -2449,7 +2588,7 @@
                }
            } else {
                // 链接类型为空时,只需要检查业务类型下的查询模板是否有效
                if(!(super.checkQTNameTxtIsOk("查询模板", queryTemplateName, btmType,true))){
                if(!(super.checkQTNameTxtIsOk("查询模板", queryTemplateName, btmType))){
                    res = false;
                    return res;
                }