From 2d7cef859d28aaf01b9871c595f5bee4f1b4d1b4 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期一, 18 十一月 2024 16:22:08 +0800
Subject: [PATCH] 业务类型树查询添加排序

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsBtmServiceImpl.java |  109 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 91 insertions(+), 18 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsBtmServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsBtmServiceImpl.java
index 2eff972..ce3999a 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsBtmServiceImpl.java
+++ b/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;
@@ -203,7 +204,7 @@
     @Override
     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 -> {
+        Optional.ofNullable(btmItems).orElseGet(() -> new ArrayList<>()).parallelStream().forEach(btmItem -> {
             OsBtmTypeVO vo = btmDO2VO(btmItem,attributeVOMap);
             VOS.add(vo);
         });
@@ -246,7 +247,7 @@
             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(",")));
@@ -290,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;
     }
@@ -307,12 +308,32 @@
      * @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);
+    }
+
     /**
      * 浣跨敤缂栧彿鑾峰彇涓氬姟绫诲瀷
      *
@@ -424,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());
@@ -603,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});
@@ -617,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<>();
@@ -638,7 +660,7 @@
      * @return 鎵ц缁撴灉
      */
     @Override
-    public OsERVO createERUsed(String btmId) {
+    public OsERVO createERUsed(String btmId) throws PLException {
         VciBaseUtil.alertNotNull(btmId, "涓氬姟绫诲瀷缂栧彿");
         OsBtmTypeVO btmTypeVO = getBtmById(btmId);
         //鑾峰彇浣跨敤褰撳墠绫诲瀷鐨勫睘鎬�
@@ -700,7 +722,7 @@
                 rootTreeList.add(tree);
             }
         }
-
+        rootTreeList = rootTreeList.stream().sorted((o1, o2) -> o1.getId().compareTo(o2.getId())).collect(Collectors.toList());
         return rootTreeList;
     }
 
@@ -1634,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);
@@ -1650,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());
@@ -1739,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);
@@ -1814,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());
@@ -2065,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;
+            }
+            //鑾峰彇鐨勬椂鍊欐墠璧歏O瀵硅薄锛岃繖鏍烽伩鍏嶄竴娆℃�у叏閮˙tm杞琕O澶參鐨勯棶棰�
+            return btmDO2VO(bizType,null);
+        }
+
+    }
+
 }

--
Gitblit v1.9.3