Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsBtmServiceImpl.java
@@ -22,6 +22,7 @@
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.stm.StatePool;
import com.vci.corba.omd.vrm.VersionRule;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.dto.OsBtmTypeDTO;
import com.vci.dto.OsBtmTypeLinkAttributesDTO;
import com.vci.model.IndexObject;
@@ -152,7 +153,22 @@
    @VciUnLog
    public List<OsBtmTypeVO> selectAllBtm() {
        try {
            return btmDO2VOs(Arrays.stream(platformClientUtil.getBtmService().getBizTypes("")).collect(Collectors.toList()));
            return btmDO2VOs(Arrays.stream(platformClientUtil.getBtmService().getBizTypes("")).collect(Collectors.toList()),null);
        } catch (PLException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 查询所有的业务类型
     *
     * @return 业务类型对象
     */
    @Override
    @VciUnLog
    public List<OsBtmTypeVO> selectAllBtm(Map<String, OsAttributeVO> attributeVOMap) {
        try {
            return btmDO2VOs(Arrays.stream(platformClientUtil.getBtmService().getBizTypes("")).collect(Collectors.toList()),attributeVOMap);
        } catch (PLException e) {
            throw new RuntimeException(e);
        }
@@ -168,6 +184,16 @@
    public Map<String, OsBtmTypeVO> selectAllBtmMap() {
        return Optional.ofNullable(self.selectAllBtm()).orElseGet(() -> new ArrayList<OsBtmTypeVO>()).stream().collect(Collectors.toMap(s -> s.getId().toLowerCase(), t -> t, (o1, o2) -> o1));
    }
    /**
     * 查询所有的业务类型映射
     *
     * @return key 是业务的英文名称的小写
     */
    @Override
    @VciUnLog
    public Map<String, OsBtmTypeVO> selectAllBtmMap(Map<String, OsAttributeVO> attributeVOMap) {
        return Optional.ofNullable(self.selectAllBtm(attributeVOMap)).orElseGet(() -> new ArrayList<OsBtmTypeVO>()).stream().collect(Collectors.toMap(s -> s.getId().toLowerCase(), t -> t, (o1, o2) -> o1));
    }
    /**
     * 数据对象转换为显示对象
@@ -176,10 +202,10 @@
     * @return 显示对象
     */
    @Override
    public List<OsBtmTypeVO> btmDO2VOs(Collection<BizType> btmItems) {
    public List<OsBtmTypeVO> btmDO2VOs(Collection<BizType> btmItems,Map<String, OsAttributeVO> attributeVOMap) {
        List<OsBtmTypeVO> VOS = new ArrayList<>();
        Optional.ofNullable(btmItems).orElseGet(() -> new ArrayList<>()).stream().forEach(btmItem -> {
            OsBtmTypeVO vo = btmDO2VO(btmItem);
        Optional.ofNullable(btmItems).orElseGet(() -> new ArrayList<>()).parallelStream().forEach(btmItem -> {
            OsBtmTypeVO vo = btmDO2VO(btmItem,attributeVOMap);
            VOS.add(vo);
        });
        return VOS;
@@ -192,7 +218,7 @@
     * @return 显示对象
     */
    @Override
    public OsBtmTypeVO btmDO2VO(BizType btmItem) {
    public OsBtmTypeVO btmDO2VO(BizType btmItem, Map<String, OsAttributeVO> attributeVOMap) {
        OsBtmTypeVO vo = new OsBtmTypeVO();
        if (btmItem != null) {
            vo.setOid(btmItem.oid);
@@ -221,12 +247,12 @@
            vo.setDelimiter(btmItem.delimiter);
            vo.setfName(btmItem.fName);
            vo.setVersionRule(String.valueOf(btmItem.verRuleName));
            if (StringUtils.isNotBlank(vo.getRevisionRuleName()) || vo.isInputRevisionFlag()) {
            if (StringUtils.isNotBlank(vo.getRevisionRuleId()) || vo.isInputRevisionFlag()) {
                vo.setRevisionFlag(true);
            }
            vo.setLifeCycleIds(Arrays.stream(btmItem.lifeCycles).collect(Collectors.joining(",")));
            vo.setApNameArray(btmItem.apNameArray);
            List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(btmItem.apNameArray).collect(Collectors.toList()));
            List<OsAttributeVO> attributeVOS = attributeService.listAttrByIds(Arrays.stream(btmItem.apNameArray).collect(Collectors.toList()),attributeVOMap);
            List<OsBtmTypeAttributeVO> btmTypeAttributeVOS = new ArrayList<>();
            Optional.ofNullable(attributeVOS).orElseGet(() -> new ArrayList<>()).stream().forEach(attributeVO -> {
                OsBtmTypeAttributeVO btmTypeAttributeVO = new OsBtmTypeAttributeVO();
@@ -265,12 +291,12 @@
        if (CollectionUtils.isEmpty(btmIds)) {
            return null;
        }
        Map<String, OsBtmTypeVO> btmTypeVOMap = self.selectAllBtmMap();
        //Map<String, OsBtmTypeVO> btmTypeVOMap = self.selectAllBtmMap();
        BtmDataFetcher btmDataFetcher = new BtmDataFetcher();
        List<OsBtmTypeVO> btmTypeVOS = new ArrayList<>();
        btmIds.stream().forEach(id -> {
            if (btmTypeVOMap.containsKey(id.toLowerCase())) {
                btmTypeVOS.add(btmTypeVOMap.get(id.toLowerCase()));
            }
            OsBtmTypeVO btmType = btmDataFetcher.getBtmType(id);
            btmTypeVOS.add(btmType);
        });
        return btmTypeVOS;
    }
@@ -282,11 +308,44 @@
     * @return 业务类型
     */
    @Override
    public OsBtmTypeVO getBtmById(String id) {
    public OsBtmTypeVO getBtmById(String id) throws PLException {
        if (StringUtils.isBlank(id)) {
            return null;
        }
        return self.selectAllBtmMap().getOrDefault(id.toLowerCase(), null);
        BizType bizType = platformClientUtil.getBtmService().getBizTypeByName(id);
        return btmDO2VO(bizType,null);
    }
    /**
     * 使用类型名获取业务类型,查不到直接报错
     * @param btmName 类型名
     * @return 业务类型
     * @throws
     */
    @Override
    public OsBtmTypeVO getBtmByName(String btmName) throws PLException{
        if(Func.isBlank(btmName)){
            throw new PLException("500",new String[]{"查询条件类型名不能为空!"});
        }
        BizType bizType = platformClientUtil.getBtmService().getBizTypeByName(btmName);
        if(Func.isEmpty(bizType) || Func.isBlank(bizType.oid)){
            throw new PLException("500",new String[]{"根据【"+btmName+"】未查询到对应业务类型!"});
        }
        return btmDO2VO(bizType,null);
    }
    /**
     * 使用编号获取业务类型
     *
     * @param id 编号
     * @return 业务类型
     */
    @Override
    public OsBtmTypeVO getBtmById(String id,Map<String, OsAttributeVO> attributeVOMap) {
        if (StringUtils.isBlank(id)) {
            return null;
        }
        return self.selectAllBtmMap(attributeVOMap).getOrDefault(id.toLowerCase(), null);
    }
    /**
@@ -366,7 +425,7 @@
            return new ArrayList<>();
        }
        BizType bizType = bizTypes[0];
        OsBtmTypeVO btmTypeVO = btmDO2VO(bizType);
        OsBtmTypeVO btmTypeVO = btmDO2VO(bizType,null);
        List<OsBtmTypeAttributeVO> attributes = btmTypeVO.getAttributes();
        if (attributes == null) {
            attributes = new ArrayList<>();
@@ -386,9 +445,10 @@
        if (attrVOs == null) {
            attrVOs = new ArrayList<>();
        }
        if (!CollectionUtils.isEmpty(attributeService.getDefaultAttributeVOs())) {
        List<OsAttributeVO> defaultAttributeVOs = attributeService.getDefaultAttributeVOs();
        if (!CollectionUtils.isEmpty(defaultAttributeVOs)) {
            List<OsBtmTypeAttributeVO> finalAttrVOs = attrVOs;
            attributeService.getDefaultAttributeVOs().stream().forEach(attr -> {
            defaultAttributeVOs.stream().forEach(attr -> {
                OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO();
                BeanUtil.convert(attr, attributeVO);
                attributeVO.setAttributeDataType(attr.getAttributeDataType());
@@ -457,7 +517,6 @@
    /**
     * 判断该属性是否已经在业务类型中产生了数据
     *
     * @param abName
     * @return
     * @throws PLException
@@ -566,7 +625,7 @@
     * @return 枚举的名称
     */
    @Override
    public String getNameById(String id) {
    public String getNameById(String id) throws PLException {
        OsBtmTypeVO btmTypeVO = getBtmById(id);
        if (btmTypeVO == null) {
            throw new VciBaseException("业务类型[{0}]在系统里不存在", new String[]{id});
@@ -580,7 +639,7 @@
     * @param btmId 业务类型主键
     */
    @Override
    public OsERVO createERDiagram(String btmId) {
    public OsERVO createERDiagram(String btmId) throws PLException {
        VciBaseUtil.alertNotNull(btmId, "业务类型编号");
        OsBtmTypeVO btmTypeVO = getBtmById(btmId);
        List<OsERNodeVO> nodeVOList = new ArrayList<>();
@@ -601,7 +660,7 @@
     * @return 执行结果
     */
    @Override
    public OsERVO createERUsed(String btmId) {
    public OsERVO createERUsed(String btmId) throws PLException {
        VciBaseUtil.alertNotNull(btmId, "业务类型编号");
        OsBtmTypeVO btmTypeVO = getBtmById(btmId);
        //获取使用当前类型的属性
@@ -646,7 +705,7 @@
        List<Tree> rootTreeList = new ArrayList<>();
        BizType[] bizTypes = getBizTypes("");
        OsBtmTypeVO osBtmTypeVO = null;
        List<OsBtmTypeVO> osBtmTypeVOS = btmDO2VOs(Arrays.asList(bizTypes));
        List<OsBtmTypeVO> osBtmTypeVOS = btmDO2VOs(Arrays.asList(bizTypes),null);
        for (int i = 0; i < osBtmTypeVOS.size(); i++) {
            osBtmTypeVO = osBtmTypeVOS.get(i);
@@ -656,13 +715,14 @@
                tree.setParentName(null);
                tree.setParentId(null);
                tree.setLeaf(true);
                tree.setId(osBtmTypeVO.getId());
                tree.setText(osBtmTypeVO.getDescription());
                tree.setAttributes(WebUtil.objectToMapString(osBtmTypeVO));
                tree.setChildren(getChildren(osBtmTypeVOS, osBtmTypeVO));
                rootTreeList.add(tree);
            }
        }
        rootTreeList = rootTreeList.stream().sorted((o1, o2) -> o1.getId().compareTo(o2.getId())).collect(Collectors.toList());
        return rootTreeList;
    }
@@ -917,14 +977,14 @@
        String[] unRemovableFields = null;
        List<String> unRemovableFields_ = null;
        //需要移除的属性
        List<String> removableFields = null;
        List<String> removableFields = new ArrayList<>();
        //修改前业务类型在数据库中已存在的所有属性
        String[] apNameArray = btmTypeDTO.getApNameArray().split(",");
        List<String> apNameArray = Func.toStrList(btmTypeDTO.getApNameArray());
        Set<String> dbApNameArray = Arrays.stream(dbBizType.apNameArray)
                .collect(Collectors.toSet());
        //过滤出需要移除的属性
        removableFields = Arrays.stream(apNameArray)
                .filter(ap -> !dbApNameArray.contains(ap))   // 过滤不在 dbApSet 中的元素
        removableFields = dbApNameArray.stream()
                .filter(ap -> !apNameArray.contains(ap))   // 过滤不在 dbApSet 中的元素
                .collect(Collectors.toList());
        // 当业务类型表中某属性已经有值, 不删除该属性, 将已经移除的属性添加回来
        unRemovableFields = platformClientUtil.getBtmService().getUnRemovableFields(id, removableFields.toArray(new String[0]));
@@ -933,7 +993,9 @@
            if (this.hasInstanceByBtmName(id)) {
                //业务类型已有实例, 只能删除没有数据的列
                if (unRemovableFields != null && unRemovableFields.length > 0) {
                    unRemovableFields_ = Arrays.asList(unRemovableFields);
                    //移除了不可修改的属性直接报错,就不往下执行了
                    throw new VciBaseException("业务类型已有实例, 只能删除没有数据的列");
                    /*unRemovableFields_ = Arrays.asList(unRemovableFields);
                    for (int i = 0; i < removableFields.size(); i++) {
                        String abName = removableFields.get(i);
                        if (unRemovableFields_.contains(abName)) {
@@ -941,7 +1003,7 @@
                                lastAttrList.add(abName);
                            }
                        }
                    }
                    }*/
                }
            }
        }
@@ -1537,7 +1599,7 @@
        //boolean flag = DDLToolClient.getService().hasInstanceOralce(tableName);
        boolean flag = false;
        try {
            flag = ClientServiceProvider.getOMDService().getBTMService().hasData(btmName);
            flag = platformClientUtil.getBtmService().hasData(btmName);
        } catch (PLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
@@ -1594,7 +1656,14 @@
            itemList.add(nodePropertyVO);
            //判断参照
            if (hasRefer) {
                selectReferenceBtmType(attribute, btmTypeVO, nodeVOList, relationVOList);
                try {
                    selectReferenceBtmType(attribute, btmTypeVO, nodeVOList, relationVOList);
                } catch (PLException e) {
                    e.printStackTrace();
                    String exceptionMessage = "判断业务类型的属性是不是参照类型时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e);
                    logger.error(exceptionMessage);
                    throw new VciBaseException(exceptionMessage);
                }
            }
        });
        nodeVO.setItems(itemList);
@@ -1610,7 +1679,7 @@
     * @param relationVOList 关系信息
     */
    private void selectReferenceBtmType(OsBtmTypeAttributeVO attribute, OsBtmTypeVO btmTypeVO,
                                        List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) {
                                        List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) throws PLException {
        if (StringUtils.isNotBlank(attribute.getReferBtmTypeId())) {
            //是参照类型的
            OsBtmTypeVO referenceBtmType = getBtmById(attribute.getReferBtmTypeId());
@@ -1699,7 +1768,14 @@
                items.add(nodePropertyVO);
                //判断参照
                if (!used) {
                    selectReferenceLinkType(attr, link, nodeVOList, relationVOList);
                    try {
                        selectReferenceLinkType(attr, link, nodeVOList, relationVOList);
                    } catch (PLException e) {
                        e.printStackTrace();
                        String exceptionMessage = "断链接类型的属性是不是参照类型时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e);
                        logger.error(exceptionMessage);
                        throw new VciBaseException(exceptionMessage);
                    }
                }
            });
            nodeVO.setItems(items);
@@ -1774,7 +1850,7 @@
     * @param nodeVOList     节点对象
     * @param relationVOList 关系对象
     */
    private void selectReferenceLinkType(OsLinkTypeAttributeVO attr, OsLinkTypeVO linkTypeVO, List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) {
    private void selectReferenceLinkType(OsLinkTypeAttributeVO attr, OsLinkTypeVO linkTypeVO, List<OsERNodeVO> nodeVOList, List<OsERRelationVO> relationVOList) throws PLException {
        if (StringUtils.isNotBlank(attr.getReferBtmTypeId())) {
            //是参照类型的
            OsBtmTypeVO referenceBtmType = getBtmById(attr.getReferBtmTypeId());
@@ -2025,4 +2101,41 @@
    }
    private class BtmDataFetcher {
        //业务类型
        private Map<String, BizType> btmTypeVOMap = new HashMap<String, BizType>();
        public BtmDataFetcher() {
            initBtmDataFetcher();
        }
        private void initBtmDataFetcher(){
            try {
                BizType[] bizTypes = platformClientUtil.getBtmService().getBizTypes("");
                //List<OsBtmTypeVO> osBtmTypeVOS = btmDO2VOs(Arrays.asList(bizTypes), null);
                if(Func.isNotEmpty(bizTypes)){
                    btmTypeVOMap = Arrays.stream(bizTypes).collect(Collectors.toMap(btm -> btm.name, btm -> btm));
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        /**
         * 获取业务类型
         * @param id
         * @return
         */
        public OsBtmTypeVO getBtmType(String id) {
            BizType bizType = btmTypeVOMap.get(id);
            if(Func.isEmpty(bizType)){
                return null;
            }
            //获取的时候才赚VO对象,这样避免一次性全部Btm转VO太慢的问题
            return btmDO2VO(bizType,null);
        }
    }
}