ludc
2024-08-15 118211ba511524e94952c896bd508ff9baec46c8
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmFunctionQueryServicePlatformImpl.java
@@ -1,39 +1,42 @@
package com.vci.frameworkcore.compatibility.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.corba.common.PLException;
import com.vci.corba.framework.data.FunctionInfo;
import com.vci.corba.framework.data.RoleRightInfo;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.frameworkcore.compatibility.ISmFunctionQueryService;
import com.vci.frameworkcore.enumpck.ResourceControlTypeEnum;
import com.vci.frameworkcore.model.SmFunctionForPlatform1;
import com.vci.frameworkcore.model.SmRoleForPlatform1;
import com.vci.frameworkcore.pagemodel.MenuVO;
import com.vci.frameworkcore.pagemodel.SmFunctionVO;
import com.vci.model.SmFunctionForPlatform1;
import com.vci.model.SmRoleForPlatform1;
import com.vci.pagemodel.MenuVO;
import com.vci.pagemodel.SmFunctionVO;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.SmFunctionVO;
import com.vci.starter.web.constant.QueryOptionConstant;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.*;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.web.pageModel.UIContentVO;
import com.vci.pagemodel.UIContentVO;
import com.vci.web.service.UIEngineServiceI;
import com.vci.web.service.WebBoServiceI;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.RightControlUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
import static com.vci.web.constant.CacheKeyConstant.ALL_FUNCTION;
import static com.vci.web.constant.CacheNameConstant.VCI_OBJECT_SERVICE;
/**
 * 老平台的权限服务
@@ -51,9 +54,17 @@
    /**
     * 菜单的根节点主键,这个是平台定义的
     */
   private final String ROOT_MENU_Id  = "modelManagmentNode";
   private final String ROOT_MENU_ID  = "modelManagmentNode";
    /**
     * 管理功能模块菜单根节点
     */
    private final String SYSTEMMANAGMENTNODE = "systemManagmentNode";
    /**
     * 操作类型管理菜单根节点
     */
    private final String OPERATENODE = "operateNode";
    /**
     * 使用用户查询
@@ -76,6 +87,12 @@
    @Autowired
    private  UIEngineServiceI uiEngineServiceI;
    @Autowired
    private PlatformClientUtil platformClientUtil;
    @Autowired
    RightControlUtil rightControlUtil;
    /**
     * 查询所有的功能
     *
@@ -94,7 +111,6 @@
     * @return 功能的显示对象
     */
    @Override
    @Cacheable(value = VCI_OBJECT_SERVICE,key = ALL_FUNCTION,unless = "#result == null")
    public Map<String, SmFunctionVO> selectAllFunctionMap() {
        return Optional.ofNullable(self.selectAllFunction()).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.toMap(s->s.getOid(),t->t));
    }
@@ -195,38 +211,11 @@
                functionVO.setDescription(functionForPlatform1.getPldesc());
            }
        }
        functionVO.setBtmname("function");
        //老的数据里创建人,最后修改人等都没有
        return functionVO;
    }
//    /**
//     * 获取当前角色的菜单
//     *
//     * @param treeQueryObject     属性查询对象
//     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
//     * @return 菜单,包含上下级
//     */
//    @Override
//    public List<Tree> treeCurrentUserMenu(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) {
//        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
//        if(sessionInfo == null || CollectionUtils.isEmpty(sessionInfo.getFunctionOids())){
//            return new ArrayList<Tree>();
//        }
//        if(resourceControlTypeEnum == null){
//            resourceControlTypeEnum = ResourceControlTypeEnum.BS;
//        }
//        Map<String, SmFunctionVO> functionVOMap = selectAllFunctionMap();
//        List<SmFunctionVO> functionVOList = new ArrayList<>();
//        for(String oid : sessionInfo.getFunctionOids()) {
//           SmFunctionVO functionVO = functionVOMap.get(oid);
//           if(functionVO !=null && resourceControlTypeEnum.getValue().equals(functionVO.getResourceControlType())  &&  functionVO.isDisplayFlag()) {
//              functionVOList.add(functionVO);
//           }
//        }
//        return dos2Trees(functionVOList.stream().sorted(Comparator.comparing(s -> s.getOrderNum())).collect(Collectors.toList()),treeQueryObject == null?null:treeQueryObject.getParentOid());
//    }
    /**
     * 获取当前角色的菜单
@@ -238,45 +227,51 @@
    @Override
    public List<MenuVO> treeCurrentUserMenu(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) throws PLException {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
//        if(sessionInfo == null || CollectionUtils.isEmpty(sessionInfo.getFunctionOids())){
//            return new ArrayList<Tree>();
//        }
        if(resourceControlTypeEnum == null){
            resourceControlTypeEnum = ResourceControlTypeEnum.BS;
        String parentId;
        boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId());
        if (adminOrDeveloperOrRoot) {
            //系统菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else if (rightControlUtil.isThreeAdminCurUser()) {
            //三员返回管理功能模块相关的菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else {
            //普通用户只返回业务功能模块相关的菜单
            parentId = ROOT_MENU_ID;
        }
//        PortalServicePrx uiService = ServiceProvider.getUIService();
//        FrameworkServicePrx frameService = ServiceProvider.getFrameService();
        FunctionInfo[] menus = ServiceProvider.getFrameService().getModuleListByParentId("modelManagmentNode", true);
//        FunctionInfo[] menus = ServiceProvider.getFrameService().("modelManagmentNode", true);
        RoleRightInfo[] userRoleRights = rightControlUtil.getRoleRightByUserName(sessionInfo.getUserId());
        Map<String, List<FunctionInfo>> map = rightControlUtil.getAllChildrenFunctionsByUserName(
                parentId, sessionInfo.getUserId(), userRoleRights);
//        PLAction[] allPLAction = uiService.getAllPLAction();
        List<MenuVO> functionVOList = new ArrayList<>();
//        Map<String, SmFunctionVO> functionVOMap = selectAllFunctionMap();
        for (FunctionInfo menu : menus) {
        if(Func.isEmpty(map.get(parentId))) {
            return functionVOList;
        }
        for (FunctionInfo menu : map.get(parentId)) {
            if(!menu.isValid){
                continue;
            }
            MenuVO functionVO = new MenuVO();
            functionVO.setId(menu.id);
            functionVO.setSource(menu.image);
            if(StringUtils.isBlank(menu.resourceB)){
                continue;
            }
            //if(StringUtils.isBlank(menu.resourceB)){
            //    continue;
            //}
            functionVO.setPath(menu.resourceB);
//            if(menu.resourceB.contains("type=") || menu.resourceB.contains("context=")){
//                String[] split = menu.resourceB.split("\\?")[0].split("=");
//                functionVO.setPath((split.length>1 && split[1].equals("test") ? "/custom-ui/" :"/base/UIContentViewer") + menu.resourceB.substring(3));
//            }else{
//                functionVO.setPath("/views/" + menu.id);
////                functionVO.setPath("/" + menu.resourceB + menu.aliasName);
//            }
            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);
            functionVO.setChildren(findChildFunctionVO(menu.id));
            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 {
@@ -284,13 +279,115 @@
            }
            functionVOList.add(functionVO);
        }
//        return dos2Trees(functionVOList.stream().sorted(Comparator.comparing(s -> s.getSort())).collect(Collectors.toList()),treeQueryObject == null?null:treeQueryObject.getParentOid());
        if(adminOrDeveloperOrRoot){
            functionVOList.addAll(this.getSystemMenu());
        }
        return functionVOList.stream().sorted(Comparator.comparing(s -> s.getSort())).collect(Collectors.toList());
    }
    public List<MenuVO> findChildFunctionVO(String parentOid) throws PLException {
        FunctionInfo[] menus = ServiceProvider.getFrameService().getModuleListByParentId(parentOid, true);
    /**
     * 获取首页系统模块配置菜单
     * @return
     */
    private List<MenuVO> getSystemMenu(){
        /*如果是测试账号或者开发账号,处理返回systemManagmentNode和modelManagmentNode以外,
         还需要返回操作类型管理菜单节点(operateNode)和系统配置、系统运行监控节点*/
        List<MenuVO> functionVOList = new ArrayList<>();
        String menuJson = "{\n" +
                "    \"hasChildren\": true,\n" +
                "    \"children\": [\n" +
                "        {\n" +
                "            \"hasChildren\": true,\n" +
                "            \"children\": [],\n" +
                "            \"id\": \"systemManagmentNode\",\n" +
                "            \"name\": \"管理功能模块\",\n" +
                "            \"parentId\": \"VCIBaseTreeNode\",\n" +
                "            \"code\": \"systemManagmentNode\",\n" +
                "            \"alias\": \"system\",\n" +
                "            \"meta\": {\n" +
                "                \"keepAlive\": false\n" +
                "            },\n" +
                "            \"sort\": 2,\n" +
                "            \"soruce\": \"\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"hasChildren\": true,\n" +
                "            \"children\": [],\n" +
                "            \"id\": \"modelManagmentNode\",\n" +
                "            \"name\": \"业务功能模块\",\n" +
                "            \"parentId\": \"VCIBaseTreeNode\",\n" +
                "            \"code\": \"modelManagmentNode\",\n" +
                "            \"alias\": \"model\",\n" +
                "            \"meta\": {\n" +
                "                \"keepAlive\": false\n" +
                "            },\n" +
                "            \"sort\": 3,\n" +
                "            \"soruce\": \"\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"hasChildren\": true,\n" +
                "            \"children\": [],\n" +
                "            \"id\": \"operateNode\",\n" +
                "            \"name\": \"操作类型管理\",\n" +
                "            \"parentId\": \"VCIBaseTreeNode\",\n" +
                "            \"code\": \"operateNode\",\n" +
                "            \"alias\": \"operate\",\n" +
                "            \"meta\": {\n" +
                "                \"keepAlive\": false\n" +
                "            },\n" +
                "            \"sort\": 4,\n" +
                "            \"soruce\": \"\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"hasChildren\": false,\n" +
                "            \"children\": [],\n" +
                "            \"id\": \"sysOptionNode\",\n" +
                "            \"name\": \"系统配置\",\n" +
                "            \"parentId\": \"VCIBaseTreeNode\",\n" +
                "            \"code\": \"sysOptionNode\",\n" +
                "            \"alias\": \"sysOption\",\n" +
                "            \"meta\": {\n" +
                "                \"keepAlive\": false\n" +
                "            },\n" +
                "            \"sort\": 5,\n" +
                "            \"soruce\": \"\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"hasChildren\": false,\n" +
                "            \"children\": [],\n" +
                "            \"id\": \"sysMonitorNode\",\n" +
                "            \"name\": \"系统运行监控\",\n" +
                "            \"parentId\": \"VCIBaseTreeNode\",\n" +
                "            \"code\": \"sysMonitorNode\",\n" +
                "            \"alias\": \"sysMonitor\",\n" +
                "            \"meta\": {\n" +
                "                \"keepAlive\": false\n" +
                "            },\n" +
                "            \"sort\": 5,\n" +
                "            \"soruce\": \"\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"id\": \"VCIBaseTreeNode\",\n" +
                "    \"name\": \"系统模块配置\",\n" +
                "    \"parentId\": \"\",\n" +
                "    \"code\": \"rootNode\",\n" +
                "    \"alias\": \"root\",\n" +
                "    \"meta\": {\n" +
                "        \"keepAlive\": false\n" +
                "    },\n" +
                "    \"sort\": 1,\n" +
                "    \"soruce\": \"\"\n" +
                "}";
        functionVOList.add(JSON.parseObject(menuJson, MenuVO.class));
        return functionVOList;
    }
    public List<MenuVO> findChildFunctionVO(String parentOid,Map<String, List<FunctionInfo>> map) throws PLException {
        List<FunctionInfo> menus = map.get(parentOid);
        List<MenuVO> functionVOList = new ArrayList<>();
        if(menus == null){
            return functionVOList;
        }
        for (FunctionInfo menu : menus) {
            if(!menu.isValid){
                continue;
@@ -298,24 +395,17 @@
            MenuVO functionVO = new MenuVO();
            functionVO.setId(menu.id);
            functionVO.setSource(menu.image);
            if(StringUtils.isBlank(menu.resourceB) ){
                continue;
            }
            functionVO.setPath(menu.resourceB);
//            if(menu.resourceB.contains("type=") || menu.resourceB.contains("context=")){
//                String[] split = menu.resourceB.split("\\?")[0].split("=");
//                functionVO.setPath((split.length>1 && split[1].equals("test") ? "/custom-ui/" :"/base/UIContentViewer") + menu.resourceB.substring(3));
//            }else{
//                functionVO.setPath("/views/" + menu.id);
////                functionVO.setPath("/" + menu.resourceB + menu.aliasName);
//            if(StringUtils.isBlank(menu.resourceB) ){
//                continue;
//            }
            functionVO.setPath(menu.resourceB);
            functionVO.setCode(menu.aliasName);
            functionVO.setAlias(menu.aliasName);
            functionVO.setParentId(menu.parentId);
            functionVO.setName(menu.name);
            functionVO.getMeta().put("keepAlive",false);
            functionVO.setSort((int) menu.seq);
            functionVO.setChildren(findChildFunctionVO(menu.id));
            functionVO.setChildren(findChildFunctionVO(menu.id,map));
            if(functionVO.getChildren().size() > 0){
                functionVO.setHasChildren(true);
            }else {
@@ -325,18 +415,14 @@
        }
        return functionVOList.stream().sorted(Comparator.comparing(s -> s.getSort())).collect(Collectors.toList());
    }
    @Override
    public UIContentVO getUIContentByBtmTypeAndId(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) throws PLException {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
//        if(sessionInfo == null || CollectionUtils.isEmpty(sessionInfo.getFunctionOids())){
//            return new ArrayList<Tree>();
//        }
        if(resourceControlTypeEnum == null){
            resourceControlTypeEnum = ResourceControlTypeEnum.BS;
        }
        for (PLUILayout allPLUILayout : ServiceProvider.getUIService().getAllPLUILayouts()) {
        for (PLUILayout allPLUILayout : platformClientUtil.getUIService().getAllPLUILayouts()) {
            if(treeQueryObject.getConditionMap().getOrDefault("type","").equals(allPLUILayout.plRelatedType)
                    && treeQueryObject.getConditionMap().getOrDefault("context","").equals(allPLUILayout.plCode)){
                return uiEngineServiceI.UIContentDO2VO(allPLUILayout,true);
@@ -344,9 +430,6 @@
        }
        return null;
    }
    /**
     * 获取所有的功能菜单
@@ -359,7 +442,7 @@
    public List<Tree> treeAllMenu(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) {
        List<SmFunctionVO> functionVOList = self.selectAllFunction().stream().filter(s -> s.isDisplayFlag() && resourceControlTypeEnum.getValue().equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
        if(!treeQueryObject.isQueryAllLevel() && StringUtils.isNotBlank(treeQueryObject.getParentOid())){
           functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
           functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
        }
        return dos2Trees(functionVOList.stream().sorted(Comparator.comparing(s -> s.getOrderNum())).collect(Collectors.toList()),treeQueryObject == null?null:treeQueryObject.getParentOid());
    }
@@ -376,7 +459,7 @@
            List<Tree> childList = new ArrayList<>();
            functionVOList.stream().forEach(s -> {
                Tree tree = DO2Tree(s);
                if (tree.getParentId() == null || tree.getParentId().equals(rootId) || ROOT_MENU_Id.equalsIgnoreCase(tree.getParentId())) {
                if (tree.getParentId() == null || tree.getParentId().equals(rootId) || ROOT_MENU_ID.equalsIgnoreCase(tree.getParentId())) {
                    rootList.add(tree);
                } else {
                    childList.add(tree);
@@ -420,7 +503,7 @@
    public List<Tree> treeFunctionByParent(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) {
        List<SmFunctionVO> functionVOList = self.selectAllFunction().stream().filter(s -> s.isDisplayFlag() && resourceControlTypeEnum.getValue().equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
         if(!treeQueryObject.isQueryAllLevel() && StringUtils.isNotBlank(treeQueryObject.getParentOid())){
            functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
            functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
         }
         return dos2Trees(functionVOList,treeQueryObject == null?null:treeQueryObject.getParentOid());
    }
@@ -436,12 +519,12 @@
    public List<Tree> treeCurrentFunctionByParent(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) {
       SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfo();
        List<SmFunctionVO> functionVOList =self.selectAllFunction().stream().filter(s -> s.isDisplayFlag()
              && resourceControlTypeEnum.getValue().equalsIgnoreCase(s.getResourceControlType())
              && resourceControlTypeEnum.getValue().equalsIgnoreCase(s.getResourceControlType())
              && !CollectionUtils.isEmpty(sessionInfo.getFunctionOids())
              && sessionInfo.getFunctionOids().contains(s.getOid())
              ).collect(Collectors.toList());
         if(!treeQueryObject.isQueryAllLevel() && StringUtils.isNotBlank(treeQueryObject.getParentOid())){
            functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
            functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
         }
         return dos2Trees(functionVOList,treeQueryObject == null?null:treeQueryObject.getParentOid());
    }
@@ -517,7 +600,7 @@
                    conditionMap.put(key,value);
                });
                conditionMap.put("ploid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select plfuncoid from plroleright where plroleoid in (" + WebUtil.toInSql(roleOids.toArray(new String[0])) + ")");
                VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap,SmRoleForPlatform1.class);
                VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmRoleForPlatform1.class);
                List<SmFunctionForPlatform1> functionForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmFunctionForPlatform1.class);
                if(!CollectionUtils.isEmpty(functionForPlatform1s)){
                    functions.addAll(functionForPlatform1s);
@@ -569,12 +652,12 @@
            if(!CollectionUtils.isEmpty(functionVOS)){
                functionVOList.addAll(functionVOS);
                String sql = "select plfuncoid,plroleoid from plroleright where plroleoid in (" + WebUtil.toInSql(roleOids.toArray(new String[0])) + ")";
                List<com.vci.client.bof.ClientBusinessObject> cbos = boService.queryBySql(sql, null);
                List<BusinessObject> cbos = boService.queryBySql(sql, null);
                if(!CollectionUtils.isEmpty(cbos)){
                    cbos.stream().forEach(cbo->{
                        String roleOid = cbo.getAttributeValue("plroleoid");
                        String roleOid = ObjectTool.getBOAttributeValue(cbo,"plroleoid");
                        List<String> functionOids = roleFunctionOidMap.getOrDefault(roleOid,new ArrayList<>());
                        functionOids.add(cbo.getAttributeValue("plfuncoid"));
                        functionOids.add(ObjectTool.getBOAttributeValue(cbo,"plfuncoid"));
                        roleFunctionOidMap.put(roleOid,functionOids);
                    });
                }
@@ -678,7 +761,6 @@
     * 清除缓存
     */
    @Override
    @CacheEvict(value = VCI_OBJECT_SERVICE,key = ALL_FUNCTION)
    public void clearCache() {
    }