wangting
2024-11-19 9c67a9d48ec6a71e2d4edf11fae3f5e802a97bff
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmFunctionQueryServicePlatformImpl.java
@@ -4,17 +4,20 @@
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONReader;
import com.vci.client.ClientSession;
import com.vci.client.common.objects.RoleObject;
import com.vci.common.exception.VciException;
import com.vci.common.locale.LocaleDisplay;
import com.vci.corba.common.PLException;
import com.vci.corba.framework.data.FuncOperationInfo;
import com.vci.corba.framework.data.FunctionInfo;
import com.vci.corba.framework.data.OperateInfo;
import com.vci.corba.framework.data.RoleRightInfo;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.framework.data.*;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.dto.RoleInfoDTO;
import com.vci.dto.RoleRightDTO;
import com.vci.dto.RoleRightParamDTO;
import com.vci.frameworkcore.compatibility.ISmFunctionQueryService;
import com.vci.frameworkcore.enumpck.ResourceControlTypeEnum;
import com.vci.model.RoleRightDO;
import com.vci.model.SmFunctionForPlatform1;
import com.vci.model.SmRoleForPlatform1;
import com.vci.pagemodel.MenuVO;
@@ -337,6 +340,8 @@
                                    menuVO.setModeType("FunctionObject");
                                    menuVO.setIsValid(info.isValid);
                                    menuVO.setHasChildren(false);
                                    menuVO.setCategory(1);
                                    menuVO.setFunctionType(2);
                                    menuVOList.add(menuVO);
                                }
                            }
@@ -354,6 +359,7 @@
                                    MenuVO menuVO = this.functionInfoToMenuVO(funcInfo);
                                    menuVO.setChildType(childType);
                                    menuVO.setModeType("FunctionObject");
                                    menuVO.setCategory(0);
                                    menuVOList.add(menuVO);
                                }
                            }
@@ -386,7 +392,9 @@
                        FunctionInfo funcInfo = funcInfos[i];
                        MenuVO menuVO = this.functionInfoToMenuVO(funcInfo);
                        menuVO.setModeType("FunctionObject");
                        childType = this.checkChildObject(funcInfos[i].id);
                        menuVO.setChildType(childType);
                        menuVO.setCategory(0);
                        menuVOList.add(menuVO);
                    }
                    return menuVOList;
@@ -413,7 +421,8 @@
                    menuVO.setName(operateInfo.name);
                    menuVO.setCode(operateInfo.identify);
                    menuVO.setAlias(operateInfo.alias);
                    menuVO.setCategory(2);
                    menuVO.setCategory(1);
                    menuVO.setFunctionType(2);
                    menuVO.setChildType(0);
                    menuVO.setRemark(operateInfo.desc);
                    menuVO.getMeta().put("keepAlive",false);
@@ -435,11 +444,13 @@
     * @param funcInfo
     * @return
     */
    private MenuVO functionInfoToMenuVO(FunctionInfo funcInfo){
    private MenuVO functionInfoToMenuVO(FunctionInfo funcInfo)
    {
        MenuVO menuVO = new MenuVO();
        menuVO.setId(funcInfo.id);
        menuVO.setValid(funcInfo.isValid);
        menuVO.setIsValid(funcInfo.isValid);
        menuVO.setSource(funcInfo.image);
        menuVO.setFunctionType(funcInfo.functionType);
        menuVO.setPathC(funcInfo.resourceC);
        menuVO.setResourceDotNet(funcInfo.resourceDotNet);
        menuVO.setResourceMobile(funcInfo.resourceMobile);
@@ -467,7 +478,7 @@
    @Override
    public int checkChildObject(String moduleId) throws VciBaseException {
        long res = 0;
        try{//20D63A69-C6BC-8519-8B2B-E5ACFEA62394
        try{
            res = platformClientUtil.getFrameworkService().checkChildObject(moduleId);
        }catch (PLException e) {
            e.printStackTrace();
@@ -489,6 +500,7 @@
            MenuVO functionVO = new MenuVO();
            functionVO.setId(menu.id);
            functionVO.setSource(menu.image);
            functionVO.setFunctionType(menu.functionType);
//            if(StringUtils.isBlank(menu.resourceB) ){
//                continue;
//            }
@@ -510,6 +522,51 @@
        return functionVOList.stream().sorted(Comparator.comparing(s -> s.getSort())).collect(Collectors.toList());
    }
    public void findChildAuthFunctionVO(MenuVO functionVO, boolean isAll) throws PLException {
        //0表示没有模块也没有操作,1表示有模块,2表示有操作
        long type = platformClientUtil.getFrameworkService().checkChildObject(functionVO.getId());
        if(type == 1){
            FunctionInfo[] funcObjs = platformClientUtil.getFrameworkService().getModuleListByParentId(functionVO.getId(), isAll);
            for (FunctionInfo funcObj : funcObjs) {
                MenuVO menuVO = new MenuVO();
                menuVO.setId(funcObj.id);
                menuVO.setSource(funcObj.image);
                menuVO.setPath(funcObj.resourceB);
                menuVO.setCode(funcObj.aliasName);
                menuVO.setAlias(funcObj.aliasName);
                menuVO.setParentId(funcObj.parentId);
                menuVO.setChildType((int) type);
                menuVO.setName(funcObj.name);
                menuVO.getMeta().put("keepAlive",false);
                menuVO.setSort((int) funcObj.seq);
                findChildAuthFunctionVO(menuVO, isAll);
                functionVO.getChildren().add(menuVO);
                functionVO.setHasChildren(true);
            }
        }else if(type == 2){
            FuncOperationInfo[] infos = platformClientUtil.getFrameworkService().getFuncOperationByModule(functionVO.getId(), "", true);
            for (FuncOperationInfo info : infos) {
                MenuVO menuVO = new MenuVO();
                menuVO.setChildType((int) type);
                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.setModeType("FunctionObject");
                menuVO.setIsValid(info.isValid);
                menuVO.setHasChildren(false);
                functionVO.getChildren().add(menuVO);
                functionVO.setHasChildren(true);
            }
        }else{
            functionVO.setHasChildren(false);
        }
    }
    @Override
    public UIContentVO getUIContentByBtmTypeAndId(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) throws PLException {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
@@ -523,6 +580,188 @@
            }
        }
        return null;
    }
    /**
     * 获取授权的模块
     * @param roleId 角色主键
     * @return 所具有权限的主键
     * @throws PLException
     */
    @Override
    public List<String> getSysModelAuth(String roleId) throws PLException {
        RoleRightInfo[] roleRightList = platformClientUtil.getFrameworkService().getRoleRightList(roleId, WebUtil.getCurrentUserId());
        Map<String, Long> authMap = Arrays.stream(roleRightList).collect(Collectors.toMap(e -> e.funcId, e -> e.rightValue,
                (existing, replacement) -> existing));
        String parentId;
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
        boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId());
        if (adminOrDeveloperOrRoot) {
            //系统菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else {
            //普通用户只返回业务功能模块相关的菜单
            parentId = ROOT_MENU_ID;
        }
        FunctionInfo[] moduleListByParentId = getModuleListByParentId(parentId, false);
        List<String> authList = new ArrayList<>();
        for (FunctionInfo functionInfo : moduleListByParentId) {
            if(authMap.containsKey(functionInfo.id)){
//                authList.add(functionInfo.id);
                getChildAuthNode(functionInfo, authMap, authList);
            }
        }
        return authList;
    }
    public BaseResult saveRoleRight(List<RoleRightParamDTO> roleRightDTOS, String roleId) throws PLException {
        /**
         * 存储需要保存的权限
         */
        Map<String,RoleRightInfo> rightMap = new HashMap<String,RoleRightInfo>();
        Map<String, List<RoleRightParamDTO>> parentMap = roleRightDTOS.stream().collect(Collectors.groupingBy(e -> e.parentId));
        for (RoleRightParamDTO dto : roleRightDTOS) {
            RoleRightInfo obj = null;
            //判断类型
            if(dto.getType() == 1 && !dto.getParentId().equals(ROOT_MENU_ID)
                    && !dto.getParentId().equals(SYSTEMMANAGMENTNODE)
                    && !dto.getParentId().equals(OPERATENODE)){
                if(!rightMap.containsKey(dto.getParentId())){
                    obj = new RoleRightInfo();
                    obj.funcId = dto.getParentId();
                    obj.rightType = (short)1;
                    obj.rightValue = 1;//没有操作的模块权限值存储为0
                    obj.roleId = roleId;
                    obj.createUser = WebUtil.getCurrentUserId();
                    obj.createTime = new Date().getTime();
                    obj.modifyUser = WebUtil.getCurrentUserId();
                    obj.modifyTime = new Date().getTime();
                    obj.licensor = "";
                }else{
                    obj = rightMap.get(dto.getParentId());
                    if (obj == null) {
                        obj = new RoleRightInfo();
                        obj.funcId = dto.getParentId();
                        obj.rightType = (short)1;
                        obj.rightValue = 1;//没有操作的模块权限值存储为0
                        obj.roleId = roleId;
                        obj.createUser = WebUtil.getCurrentUserId();
                        obj.createTime = new Date().getTime();
                        obj.modifyUser = WebUtil.getCurrentUserId();
                        obj.modifyTime = new Date().getTime();
                        obj.licensor = "";
                    }else {
                        obj.rightValue = 1;
                    }
                }
                rightMap.put(dto.getParentId(), obj);
            }else if (dto.getType() == 2){
//                RoleRightInfo roleRightObj = new RoleRightInfo();
                if(!rightMap.containsKey(dto.getParentId())) {
                    obj = new RoleRightInfo();
                    obj.funcId = dto.getParentId();
                    obj.rightType = (short)1;
                    obj.rightValue = countRightValue(parentMap.get(dto.getParentId()));//没有操作的模块权限值存储为0
                    obj.roleId = roleId;
                    obj.createUser = WebUtil.getCurrentUserId();
                    obj.createTime = new Date().getTime();
                    obj.modifyUser = WebUtil.getCurrentUserId();
                    obj.modifyTime = new Date().getTime();
                    obj.licensor = "";
                    rightMap.put(dto.getParentId(), obj);
                }
            }
        }
        /**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
        RoleRightInfo[] roleRightObjs =   new RoleRightInfo[rightMap.size()];
        Set<String> objSet = rightMap.keySet();
        Iterator<String> it = objSet.iterator();
        int i = 0;
        while(it.hasNext()){
            roleRightObjs[i++] = rightMap.get(it.next());
        }
        UserEntityInfo userEntityInfo = new UserEntityInfo();
        userEntityInfo.setModules("com.vci.client.framework.rightdistribution.roleRight.RoleRightPanel");
        userEntityInfo.setUserName(WebUtil.getCurrentUserId());
        boolean res =  platformClientUtil.getFrameworkService()
                .saveRoleRight(roleRightObjs,roleId,WebUtil.getCurrentUserId(), userEntityInfo);
        if(!res){
            throw new PLException("500", new String[]{"功能模块授权失败!"});
        }
        return BaseResult.success();
    }
    /**
     * 获取所授权的模块权限
     * @param roleName 搜索的角色
     * @return 角色列表
     */
    @Override
    public List<RoleInfoDTO> getRoleList(String roleName) throws PLException {
        RoleInfo[] roleInfos = platformClientUtil.getFrameworkService().fetchRoleInfoByUserType(WebUtil.getCurrentUserId());
        List<RoleInfoDTO> dtos = new ArrayList<>();
        for (RoleInfo roleInfo : roleInfos) {
            if(StringUtils.isBlank(roleName) || roleInfo.name.indexOf(roleName) != -1) {
                RoleInfoDTO dto = new RoleInfoDTO();
                dto.setName(roleInfo.name);
                dto.setDescription(roleInfo.description);
                dto.setId(roleInfo.id);
                dto.setGrantor(roleInfo.grantor);
                dto.setType(roleInfo.type);
                dto.setCreateTime(roleInfo.createTime);
                dto.setCreateUser(roleInfo.createUser);
                dto.setUpdateTime(roleInfo.updateTime);
                dto.setUpdateUser(roleInfo.updateUser);
                dtos.add(dto);
            }
        }
        return dtos;
    }
    private long countRightValue(List<RoleRightParamDTO> dtos){
        long value = 0;
        for (RoleRightParamDTO dto : dtos) {
            value += (long)Math.pow(2, dto.getNumber());//累计加上各个操作的权限值
        }
        return value;
    }
    /**
     *
     * @param funcObj 模块对象
     * @param authMap 该角色下所有的权限数据
     * @param authList 该角色下所具有的权限
     * @throws PLException
     */
    private void getChildAuthNode(FunctionInfo funcObj, Map<String, Long> authMap, List<String> authList) throws PLException {
        /**0表示该模块下什么都没有,1表示有模块,2表示有操作**/
        long funcType = platformClientUtil.getFrameworkService().checkChildObject(funcObj.id);
        if(funcType == 1){
            FunctionInfo[] funcInfos = platformClientUtil.getFrameworkService().getModuleListByParentId(funcObj.id, false);
            for(int i=0;i<funcInfos.length;i++){
                if(authMap.containsKey(funcInfos[i].id)){
//                    authList.add(funcInfos[i].id);
                    getChildAuthNode(funcInfos[i], authMap, authList);
                }
            }
        }else if(funcType == 2){
            FuncOperationInfo[] funcOperates = platformClientUtil.getFrameworkService().getFuncOperationByModule(funcObj.id, "", true);
            for (int j = 0; j < funcOperates.length; j++) {
                if(authMap.containsKey(funcOperates[j].funcId)){
                    long rightValue = authMap.get(funcOperates[j].funcId);
                    long nodeValue = funcOperates[j].number;
                    long preValue = (rightValue >> nodeValue) & 1;
                    //进行位与操作,如果相等则表示具有当前操作的权限
                    if (preValue == 1) {
                        authList.add(funcOperates[j].id);
                    }
                }
            }
        }
    }
    /**
@@ -858,4 +1097,64 @@
    public void clearCache() {
    }
    /**
     * 通过模块ID获取子级列表
     * @param isAll 是否包括无效的模块,true则包括
     * @return
     * @throws VciBaseException
     */
    @Override
    public List<MenuVO> getSysModelAuthTreeMenuByPID(boolean isAll) throws VciBaseException, PLException {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
        boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId());
        String parentId;
        if (adminOrDeveloperOrRoot) {
            //系统菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else {
            //普通用户只返回业务功能模块相关的菜单
            parentId = ROOT_MENU_ID;
        }
        List<MenuVO> functionVOList = new ArrayList<>();
        FunctionInfo[] moduleListByParentId = getModuleListByParentId(parentId, isAll);
        for (FunctionInfo menu : moduleListByParentId) {
            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.getMeta().put("keepAlive",false);
            functionVO.setSort((int) menu.seq);
            findChildAuthFunctionVO(functionVO, isAll);
            if(functionVO.getChildren().size() > 0){
                functionVO.setHasChildren(true);
            }else {
                functionVO.setHasChildren(false);
            }
            functionVOList.add(functionVO);
        }
        return functionVOList;
    }
    /**
     * 通过模块ID获取子级列表
     * @param parentId
     * @param isAll 是否包括无效的模块,true则包括
     * @return
     * @throws VciException
     */
    public FunctionInfo[] getModuleListByParentId(String parentId,boolean isAll) throws PLException {
        FunctionInfo[] funcInfos = null;
        funcInfos = platformClientUtil.getFrameworkService().getModuleListByParentId(parentId, isAll);
        return funcInfos;
    }
}