From 986aa62ed00bee39363bab41b4eeb8259d446efd Mon Sep 17 00:00:00 2001
From: ludc <ludc@vci-tech.com>
Date: 星期四, 16 一月 2025 18:20:32 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java |  590 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 577 insertions(+), 13 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
index d785735..a3c265f 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
@@ -1,20 +1,34 @@
 package com.vci.web.service.impl;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ZipUtil;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.vci.common.qt.object.QTConstants;
+import com.vci.constant.FrameWorkLangCodeConstant;
 import com.vci.corba.common.PLException;
 import com.vci.corba.omd.atm.AttributeDef;
+import com.vci.corba.omd.btm.BizType;
 import com.vci.corba.omd.data.BusinessObject;
 import com.vci.corba.omd.ltm.LinkType;
+import com.vci.model.OsLinkTypeDO;
+import com.vci.omd.constants.AttributeConstants;
 import com.vci.omd.utils.ObjectTool;
 import com.vci.pagemodel.*;
+import com.vci.po.OsLinkTypePO;
+import com.vci.starter.poi.bo.ReadExcelOption;
+import com.vci.starter.poi.bo.WriteExcelData;
+import com.vci.starter.poi.bo.WriteExcelOption;
+import com.vci.starter.poi.constant.ExcelLangCodeConstant;
+import com.vci.starter.poi.util.ExcelUtil;
 import com.vci.starter.web.annotation.log.VciUnLog;
 import com.vci.starter.web.enumpck.VciFieldTypeEnum;
+import com.vci.starter.web.exception.VciBaseException;
 import com.vci.starter.web.pagemodel.BaseQueryObject;
 import com.vci.starter.web.pagemodel.BaseResult;
 import com.vci.starter.web.pagemodel.DataGrid;
-import com.vci.starter.web.util.BeanUtil;
-import com.vci.starter.web.util.VciBaseUtil;
-import com.vci.starter.web.util.VciDateUtil;
-import com.vci.model.OsLinkTypeDO;
+import com.vci.starter.web.util.*;
+import com.vci.starter.web.util.Lcm.Func;
 import com.vci.web.service.*;
 import com.vci.web.util.PlatformClientUtil;
 import com.vci.web.util.WebUtil;
@@ -25,23 +39,38 @@
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
 /**
  * 閾炬帴绫诲瀷鏈嶅姟
  * @author weidy
- * @date 2021-2-15
+ * @date 2024-2-15
  */
 @Service
 public class OsLinkTypeServiceImpl implements OsLinkTypeServiceI {
+
+    private static final String OID = "oid";
+    private static final String NAME = "name";
+    private static final String LABEL = "label";
+    private static final String DESCRIPTION = "description";
+    private static final String TS = "ts";
+    private static final String CREATOR = "creator";
+    private static final String CREATETIME = "createTime";
+    private static final String MODIFIER = "modifier";
+    private static final String MODIFYTIME = "modifyTime";
 
     /**
      * 鏃ュ織
      */
     private Logger logger = LoggerFactory.getLogger(getClass());
-
 
     /**
      * 骞冲彴鐨勮皟鐢ㄥ伐鍏风被
@@ -144,7 +173,7 @@
             }
             vo.setDescription(linkType.description);
             vo.setId(linkType.name);
-            vo.setName(linkType.tag);
+            vo.setName(linkType.label);
             vo.setFromBtmTypeVOS(btmService.listBtmByIds(Arrays.stream(linkType.btmItemsFrom).collect(Collectors.toSet())));
             if(!CollectionUtils.isEmpty(vo.getFromBtmTypeVOS())){
                 vo.setFromBtmType(Arrays.stream(linkType.btmItemsFrom).collect(Collectors.joining(",")));
@@ -161,7 +190,7 @@
             List<OsLinkTypeAttributeVO> linkTypeAttributeVOS = new ArrayList<>();
             Optional.ofNullable(attributeVOS).orElseGet(()->new ArrayList<>()).stream().forEach(attributeVO->{
                 OsLinkTypeAttributeVO linkTypeAttributeVO = new OsLinkTypeAttributeVO();
-                BeanUtil.convert(attributeVO,linkTypeAttributeVO);
+                BeanUtilForVCI.convert(attributeVO,linkTypeAttributeVO);
                 linkTypeAttributeVO.setPkLinkType(vo.getOid());
                 if(StringUtils.isNotBlank(attributeVO.getBtmTypeId())){
                     linkTypeAttributeVO.setReferFlag(true);
@@ -206,11 +235,12 @@
      * @return 閾炬帴绫诲瀷
      */
     @Override
-    public OsLinkTypeVO getLinkTypeById(String id) {
+    public OsLinkTypeVO getLinkTypeById(String id) throws PLException {
         if(StringUtils.isBlank(id)){
             return null;
         }
-        return self.selectAllLinkMap().getOrDefault(id.toLowerCase(),null);
+        LinkType linkType = platformClientUtil.getLinkTypeService().getLinkType(id);
+        return this.linkTypeDO2VO(linkType);
     }
 
     /**
@@ -220,7 +250,7 @@
      * @return 閾炬帴绫诲瀷鐨勫睘鎬�
      */
     @Override
-    public List<OsLinkTypeAttributeVO> listAttributeByLinkId(String linkTypeId) {
+    public List<OsLinkTypeAttributeVO> listAttributeByLinkId(String linkTypeId) throws PLException {
         OsLinkTypeVO linkTypeVO = getLinkTypeById(linkTypeId);
         return linkTypeVO.getAttributes();
     }
@@ -284,7 +314,7 @@
                     }
                     OsBtmTypeAttributeVO attributeVO = attributeVOMap.getOrDefault(attrId.toLowerCase(Locale.ROOT), null);
                     if(attributeVO!=null){
-                        String vtType = attributeVO.getAttrDataType();
+                        String vtType = attributeVO.getAttributeDataType();
                         String attrType = "";
                         VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.forValue(vtType);
                         if(fieldTypeEnum == null) {
@@ -369,6 +399,495 @@
         platformClientUtil.getLinkTypeService().modifyLinkType(linkType);
         return BaseResult.success(null,"淇濆瓨鎴愬姛锛�");
     }
+    /**
+     * 閾炬帴绫诲瀷鍒犻櫎
+     * linkType 閾炬帴绫诲瀷瀵硅薄
+     * @return 鍒犻櫎缁撴灉
+     */
+    @Override
+    public BaseResult deleteLink(LinkType linkType) throws PLException {
+        if(platformClientUtil.getLinkTypeService().hasData(linkType.name)){
+            throw new PLException("500",new String[] {"绫诲瀷宸叉湁瀹炰緥, 涓嶈繘琛屽垹闄ゆ搷浣�"});
+        }
+        boolean flag = platformClientUtil.getLinkTypeService().deleteLinkType(linkType);
+        if(!flag){
+            throw new PLException("500",new String[] {"鍒犻櫎澶辫触"});
+        }else{
+            return BaseResult.success();
+        }
+    }
+    /**
+     * 涓�鑷存�ф鏌�
+     * @return 鍒犻櫎缁撴灉
+     */
+    @Override
+    public BaseResult checkLinkType() throws PLException {
+        String[] result = platformClientUtil.getLinkTypeService().linkTypeConsistencyCheck();
+        Map<String, String> dbCheckMap = new HashMap<String, String>();
+        for(int i = 0; i < result.length; i++){
+            String info = result[i];
+            if(info.equals("")){
+                continue;
+            }
+            String[] infos = info.split("/DML");
+            String typeName = infos[0];
+            String dml = infos[1];
+            dbCheckMap.put(typeName, dml);
+        }
+        Map<String, List<String>> btmCheckMap = usedBtmCheck();
+        if(dbCheckMap.size() < 1 && (btmCheckMap == null || btmCheckMap.size() < 1)){
+            return BaseResult.successMsg("鏁版嵁搴撲腑鐨勮〃缁撴瀯涓庣被鍨嬩竴鑷�, 閾炬帴绫诲瀷寮曠敤鐨勪笟鍔$被鍨嬪叏閮ㄦ纭瓨鍦�,鏃犻渶淇!!");
+        }else{
+            Map<String,Object> returnData = new HashMap<>();
+            returnData.put("dbCheckMap",dbCheckMap);
+            returnData.put("btmCheckMap",btmCheckMap);
+            List<Map> list = new ArrayList<>();
+            list.add(returnData);
+            BaseResult<List<Map>> listBaseResult = BaseResult.dataList(200, list, "闇�瑕佽繘琛屽垪鐨勪慨澶嶏紒锛�");
+            listBaseResult.setSuccess(false);
+            return listBaseResult;
+        }
+    }
+
+    /**
+     * 涓�鑷存�ф鏌ヤ慨澶嶆暟鎹簱琛�
+     * repairData 闇�瑕佷慨澶嶇殑鏁版嵁
+     * @return 淇缁撴灉
+     */
+    @Override
+    public BaseResult repairTable(String repairData) throws PLException, IOException {
+        Map<String, Object> map = new ObjectMapper().readValue(repairData, new TypeReference<Map<String,Object>>(){});
+        HashMap<String,Object> dbCheckMap = (HashMap<String, Object>) map.get("dbCheckMap");
+        HashMap<String,List<String>> btmCheckMap = (HashMap<String, List<String>>) map.get("btmCheckMap");
+        List returnList = new ArrayList<>();
+        Map returnMap = new HashMap();
+        if(dbCheckMap.size() > 0){
+            List<String> list = getRepairDML(dbCheckMap);
+            if(list.size() < 1){
+                return BaseResult.success();
+            }
+            String[] result = platformClientUtil.getLinkTypeService().executeRepair(list.toArray(new String[0]));
+            List<String> resultList = Arrays.asList(result);
+            for (String typeName : resultList) {
+                if(dbCheckMap.containsKey(typeName)){
+                    dbCheckMap.remove(typeName);
+                }else if(dbCheckMap.containsKey(typeName + "_ADD")){
+                    String sql = String.valueOf(dbCheckMap.get(typeName));
+                    sql = sql.substring(sql.indexOf(";") + 1, sql.length());
+                    dbCheckMap.put(typeName, sql);
+                }else if(dbCheckMap.containsKey(typeName + "_DROP")){
+                    String sql = String.valueOf(dbCheckMap.get(typeName));
+                    sql = sql.substring(0, sql.indexOf(";"));
+                    dbCheckMap.put(typeName, sql);
+                }
+            }
+            if(!dbCheckMap.isEmpty()){
+                returnMap.put("dbCheckMap",dbCheckMap);
+            }
+        }
+
+        if(btmCheckMap.size() > 0){
+            List<String> result = repairXml(btmCheckMap);
+            for(int i = 0; i < result.size(); i++){
+                String typeName = result.get(i);
+                if(btmCheckMap.containsKey(typeName)){
+                    btmCheckMap.remove(typeName);
+                }
+            }
+            if(!btmCheckMap.isEmpty()){
+                returnMap.put("btmCheckMap",btmCheckMap);
+            }
+        }
+        returnList.add(returnMap);
+        return BaseResult.success(returnList);
+    }
+    /**
+     * 鍒涘缓瑙嗗浘
+     * @return 鍒涘缓缁撴灉
+     */
+    @Override
+    public BaseResult createView() throws PLException {
+        boolean f = platformClientUtil.getLinkTypeService().createView();
+        if(f){
+            return BaseResult.success("鍒涘缓瑙嗗浘鎴愬姛");
+        }else{
+            return BaseResult.success("鍒涘缓瑙嗗浘澶辫触");
+        }
+    }
+
+    /**
+     * 瀵煎嚭閾炬帴绫诲瀷
+     * name 閾炬帴绫诲瀷鍚嶇О
+     * @return 鍒涘缓缁撴灉
+     */
+    @Override
+    public void expData(String names, HttpServletResponse response) throws PLException, IOException {
+        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
+        //鍐檈xcel
+        String excelPath = defaultTempFolder + File.separator + "lt.xls";
+        //璁剧疆鍒楀悕
+        List<String> columns = new ArrayList<>(
+                Arrays.asList("鍚嶇О", "鏍囩", "瀹炵幇绫�", "褰㈢姸", "From绔被鍨嬪垪琛�", "From绔富绫诲瀷", "From绔搴斿叧绯�",
+                        "To绔被鍨嬪垪琛�", "To绔富绫诲瀷", "To绔搴斿叧绯�", "灞炴�у垪琛�", "鎻忚堪")
+        );
+        try {
+            new File(excelPath).createNewFile();
+            //璁剧疆鍒�
+            List<WriteExcelData> excelDataList = new ArrayList<>();
+            //璁剧疆鍒楀ご
+            for (int index = 0; index < columns.size(); index++) {
+                excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
+            }
+            HashSet<String> attributes = new HashSet<>();
+            int i = 0;
+            for (String name : names.split(",")) {
+                LinkType lt = platformClientUtil.getLinkTypeService().getLinkType(name);
+                excelDataList.add(new WriteExcelData(i+1,0, lt.name));
+                excelDataList.add(new WriteExcelData(i+1,1, lt.label));
+                excelDataList.add(new WriteExcelData(i+1,2, lt.implClass));
+                excelDataList.add(new WriteExcelData(i+1,3, lt.shape));
+                excelDataList.add(new WriteExcelData(i+1,4, String.join(",",lt.btmItemsFrom)));
+                excelDataList.add(new WriteExcelData(i+1,5, lt.primitivesFrom));
+                excelDataList.add(new WriteExcelData(i+1,6, lt.relationFrom));
+                excelDataList.add(new WriteExcelData(i+1,7, String.join(",",lt.btmItemsTo)));
+                excelDataList.add(new WriteExcelData(i+1,8, lt.primitivesTo));
+                excelDataList.add(new WriteExcelData(i+1,9, lt.relationTo));
+                excelDataList.add(new WriteExcelData(i+1,10, String.join(",",lt.attributes)));
+                excelDataList.add(new WriteExcelData(i+1,11, lt.description));
+                attributes.addAll(Arrays.asList(lt.attributes));
+                i++;
+            }
+            WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
+            ExcelUtil.writeDataToFile(excelPath, excelOption);
+            //瀵煎嚭灞炴��
+            String attrPath = attributeService.exportAttributes("attr",
+                    String.valueOf(attributes.stream().collect(Collectors.joining(","))),true);
+            //绉诲姩灞炴�у埌閾炬帴绫诲瀷鏂囦欢澶归噷闈㈠幓
+            FileUtil.move(new File(attrPath), new File(defaultTempFolder),true);
+            FileUtil.del(attrPath.substring(0,attrPath.lastIndexOf("\\")));
+            //todo 瀵煎嚭涓氬姟绫诲瀷杩樻病鏈夊疄鐜�
+//            List<BizType> bts = new ArrayList<BizType>();
+//            for (String btName : btNameSet) {
+//                BizType bt = BtmProvider.getBtmItemByName(btName);
+//                bts.add(bt);
+//            }
+//            boolean btFlag = BtmProvider.expData(rootPath, bts.toArray(new BizType[0]));
+        }catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        File zip = ZipUtil.zip(defaultTempFolder);
+        FileUtil.del(defaultTempFolder + File.separator);
+        ControllerUtil.writeFileToResponse(response,zip.getAbsoluteFile());
+    }
+
+    /**
+     * 瀵煎叆閾炬帴绫诲瀷
+     * @param file 涓婁紶鐨勬枃浠�
+     * @return
+     */
+    @Override
+    public BaseResult impData(MultipartFile file) throws Exception {
+        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
+        String fileName = defaultTempFolder + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename());
+        file.transferTo(new File(fileName));
+        if (file == null) {
+            return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"});
+        }
+        if (!fileName.endsWith(".zip")) {
+            throw new VciBaseException("浠呰兘涓婁紶zip鍘嬬缉鏂囦欢锛岃閲嶆柊涓婁紶锛�");
+        }
+        File unzip = ZipUtil.unzip(fileName);
+        File ltExcel = new File(unzip.getAbsolutePath() + File.separator + "lt.xls");
+        File attrExcel = new File(unzip.getAbsolutePath() + File.separator + "attr.xls");
+        if (!attrExcel.exists()) {
+            //澧炲姞瑙e帇鐨勮矾寰勶紝鐪嬫枃浠惰繕鍦ㄦ病鏈�
+            attrExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "attr.xls");
+            if (!attrExcel.exists()) {
+                return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"娌℃湁瀵煎叆鐨勫睘鎬ф枃浠躲�傚鍏ョ粓姝紒"});
+            }
+        }
+        BaseResult baseResult = attributeService.importAttributes(attrExcel,true);
+        if(!baseResult.isSuccess()){
+            //鍒犻櫎涓婁紶鐨勬枃浠跺す
+            FileUtil.del(defaultTempFolder + File.separator);
+            return baseResult;
+        }
+        //todo 杩橀渶瀵煎叆涓氬姟绫诲瀷锛岀瓑寰呭姛鑳藉疄鐜�
+        if (!ltExcel.exists()) {
+            //澧炲姞瑙e帇鐨勮矾寰勶紝鐪嬫枃浠惰繕鍦ㄦ病鏈�
+            ltExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "lt.xls");
+            if (!ltExcel.exists()) {
+                //鍒犻櫎涓婁紶鐨勬枃浠跺す
+                FileUtil.del(defaultTempFolder + File.separator);
+                return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"娌℃湁瀵煎叆鐨勯摼鎺ユ枃浠躲�傚鍏ョ粓姝紒"});
+            }
+        }
+        try{
+            //1銆佽鍙杄xcel涓殑鏁版嵁锛岀粍鎴愬璞�
+            ReadExcelOption excelOption = new ReadExcelOption();
+            List<OsLinkTypePO> poList = ExcelUtil.readDataObjectFromExcel(ltExcel, OsLinkTypePO.class,excelOption,(value, po, fieldName)->{});
+            //鍘婚櫎閮芥槸绌虹殑鎯呭喌
+            if(CollectionUtils.isEmpty(poList)){
+                return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{});
+            }
+            //褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶅睘鎬э紝value锛氳鍙凤級
+            Map<String, String> excelReapeat = new HashMap<>();
+            int maxLength = platformClientUtil.getLinkTypeService().getLTNameMaxLength();
+
+            //鍒ゆ柇蹇呭~灞炴�ф槸鍚︿负绌猴紝鐢ㄦ埛鏄惁宸插瓨鍦紝浠ュ強閮ㄩ棬鏄惁濉敊绛夋牎楠岄�昏緫
+            poList.stream().forEach(osLinkTypePO -> {
+                if(Func.isBlank(osLinkTypePO.getName())){//灞炴�у悕鍒ょ┖
+                    throw new VciBaseException("绗��"+osLinkTypePO.getRowIndex()+"銆戣锛宯ame");
+                }else if(osLinkTypePO.getName().length() > maxLength){
+                    throw new VciBaseException("绗��"+osLinkTypePO.getRowIndex()+"銆戣锛岄摼鎺ョ被鍨嬪悕闀垮害涓嶈兘瓒呰繃" + maxLength);
+                }else if(!osLinkTypePO.getName().matches("^[A-Za-z]+$")){
+                    throw new VciBaseException("绗��"+osLinkTypePO.getRowIndex()+"銆戣锛岄摼鎺ョ被鍨嬪悕绉板彧鑳戒负鑻辨枃瀛楁瘝");
+                }else if(excelReapeat.containsKey(osLinkTypePO.getName())){//灞炴�у悕琛ㄦ牸涓垽閲�
+                    throw new VciBaseException("绗��"+excelReapeat.get(osLinkTypePO.getName())+"銆戣鍜岀銆�"+osLinkTypePO.getRowIndex()+"銆戣鏁版嵁锛岄摼鎺ョ被鍨嬪悕閲嶅");
+                }
+                try {
+                    LinkType historyLink = platformClientUtil.getLinkTypeService().getLinkType(osLinkTypePO.getName());
+                    //宸叉湁姝ゆ暟鎹繘琛屽垹闄よ鐩�
+                    if(historyLink != null && !historyLink.name.equals("")){
+                        platformClientUtil.getLinkTypeService().deleteLinkType(historyLink);
+                    }
+                } catch (PLException e) {
+                    throw new RuntimeException(e);
+                }
+
+                //灞炴�у悕excel涓垽閲嶅鐞�
+                excelReapeat.put(osLinkTypePO.getName(),osLinkTypePO.getRowIndex());
+                LinkType linkType = new LinkType();
+                linkType.name = osLinkTypePO.getName();
+                linkType.attributes = osLinkTypePO.getAttributes().split(",");
+                linkType.btmItemsFrom = osLinkTypePO.getBtmItemsFrom().split(",");
+                linkType.primitivesFrom = osLinkTypePO.getPrimitivesFrom();
+                linkType.relationFrom = osLinkTypePO.getRelationFrom();
+                linkType.btmItemsTo = osLinkTypePO.getBtmItemsTo().split(",");
+                linkType.primitivesTo = osLinkTypePO.getPrimitivesTo();
+                linkType.relationTo = osLinkTypePO.getRelationTo();
+                linkType.relation = osLinkTypePO.getRelationFrom() + ":" + osLinkTypePO.getRelationTo();
+                linkType.description = osLinkTypePO.getDescription();
+                linkType.label = osLinkTypePO.getTag();
+                linkType.shape = osLinkTypePO.getShape();
+                linkType.implClass = osLinkTypePO.getImplClass();
+                linkType.modifier = WebUtil.getCurrentUserId();
+                linkType.creator = WebUtil.getCurrentUserId();
+                try {
+                    platformClientUtil.getLinkTypeService().addLinkType(linkType);
+                } catch (PLException e) {
+                    throw new RuntimeException(e);
+                }
+
+            });
+        }catch (Exception e){
+            if(logger.isErrorEnabled()){
+                logger.error("璇诲彇excel鍐呭鏃舵垨淇濆瓨閾炬帴绫诲瀷淇℃伅鏃跺嚭鐜颁簡閿欒锛屽叿浣撳師鍥狅細",VciBaseUtil.getExceptionMessage(e));
+            }
+            e.printStackTrace();
+            return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e);
+        }
+        //鍒犻櫎涓婁紶鐨勬枃浠跺す
+        FileUtil.del(defaultTempFolder + File.separator);
+        return BaseResult.success("閾炬帴绫诲瀷瀵煎叆鎴愬姛锛�");
+    }
+    /**
+     * 鑾峰彇閾炬帴绫诲瀷鍖呭惈鐨勫睘鎬�
+     * @param name 閾炬帴绫诲瀷鐨勭紪鍙�
+     * @return 灞炴�х殑淇℃伅
+     */
+    @Override
+    public List<OsLinkTypeAttributeVO> getAllAttributeByLink(String name) throws PLException, ParseException {
+        AttributeDef[] attributes = platformClientUtil.getLinkTypeService().getAttributes(name);
+        Map<String, AttributeDef> collect = Arrays.stream(platformClientUtil.getLinkTypeService().getSysAttributeDefs())
+                .collect(Collectors.toMap(str -> str.name, str -> str));
+
+        List<OsLinkTypeAttributeVO> links = new ArrayList<>();
+        String[] sysAttibutes = { "OID", "Creator", "CreateTime", "LastModifier", "LASTMODIFYTIME", "F_OID",
+                "F_REVISIONOID", "F_NAMEOID", "F_BtwName", "T_OID", "T_REVISIONOID", "T_NAMEOID", "T_BtwName", "TS" };
+        for (String sysname : sysAttibutes) {
+            AttributeDef sysAttributeDef = collect.get(sysname.toLowerCase());
+            OsLinkTypeAttributeVO vo = new OsLinkTypeAttributeVO();
+            vo.setOid(sysAttributeDef.oid);
+            vo.setAttrDataType(sysAttributeDef.vtDataType);
+            vo.setPkLinkType(name);
+            vo.setCreateTime(new Date(sysAttributeDef.createTime));
+            vo.setCreator(sysAttributeDef.creator);
+            vo.setDefaultValue(sysAttributeDef.defValue);
+            vo.setDescription(sysAttributeDef.description);
+            vo.setRange(sysAttributeDef.rage);
+            vo.setId(sysname);
+            vo.setName(sysAttributeDef.label);
+            vo.setLastModifier(sysAttributeDef.modifier);
+            vo.setLastModifyTime(new Date(sysAttributeDef.modifyTime));
+            links.add(vo);
+        }
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        for (AttributeDef attribute : attributes) {
+            OsLinkTypeAttributeVO vo = new OsLinkTypeAttributeVO();
+            vo.setOid(attribute.oid);
+            vo.setAttrDataType(attribute.vtDataType);
+            vo.setPkLinkType(name);
+            vo.setCreateTime(new Date(attribute.createTime));
+            vo.setCreator(attribute.creator);
+            vo.setDefaultValue(attribute.defValue);
+            vo.setDescription(attribute.description);
+            vo.setRange(attribute.rage);
+            vo.setId(attribute.name);
+            vo.setName(attribute.label);
+            vo.setTs(formatter.parse(attribute.ts));
+            vo.setLastModifier(attribute.modifier);
+            vo.setOwner(attribute.creator);
+            vo.setLastModifyTime(new Date(attribute.modifyTime));
+            String maxLength = AttributeConstants.getOtherValueByType(attribute.other, AttributeConstants.LENGTH);
+            if(StringUtils.isNotBlank(maxLength)){
+                vo.setAttributeLength(Integer.valueOf(maxLength));
+            }
+            links.add(vo);
+        }
+        return links;
+    }
+    /**
+     * 鑾峰彇璁剧疆鎺掑簭瀛楁鐨勬帓搴忓瓧娈�
+     * @param linkType 閾炬帴绫诲瀷鐨勭紪鍙�
+     * @param btmType 涓氬姟绫诲瀷鐨勭紪鍙�
+     * @param direction 姝�/鍙嶅悜
+     * @return 灞炴�х殑淇℃伅
+     */
+    @Override
+    public List<String> getAllOrderbyAttributeByLink(String linkType, String btmType, String direction) throws PLException, ParseException {
+        List<String> abNames = new ArrayList<>(Arrays.asList("OID", "Creator", "CreateTime", "LastModifier", "LASTMODIFYTIME", "F_OID",
+                "F_REVISIONOID", "F_NAMEOID", "F_BtwName", "T_OID", "T_REVISIONOID", "T_NAMEOID", "T_BtwName", "TS" ));
+        AttributeDef[] attributes = platformClientUtil.getLinkTypeService().getAttributes(linkType);
+        for (AttributeDef attribute : attributes) {
+            abNames.add(String.valueOf(attribute.name));
+        }
+        String wrapper = "T_OID.";
+        if(direction.equals(QTConstants.DIRECTION_OPPOSITE)){
+            wrapper = "F_OID.";
+        }
+        List<OsBtmTypeAttributeVO> bizTypeQTDs = btmService.getBizTypeQTDs(btmType);
+        for (OsBtmTypeAttributeVO bizTypeQTD : bizTypeQTDs) {
+            abNames.add(wrapper + bizTypeQTD.getId());
+        }
+        return abNames;
+    }
+
+    /**
+     * 淇閾炬帴绫诲瀷鐨剎ml鏂囦欢
+     * @return
+     */
+    private List<String> repairXml(HashMap<String, List<String>> btmCheckMap){
+        List<String> result = new ArrayList<String>();
+        for(Iterator<String> ite = btmCheckMap.keySet().iterator(); ite.hasNext();){
+            String linkName = ite.next();
+            List<String> list = btmCheckMap.get(linkName);
+            LinkType link = null;
+            try {
+                link = platformClientUtil.getLinkTypeService().getLinkType(linkName);
+            } catch (PLException e1) {
+                // TODO Auto-generated catch block
+                e1.printStackTrace();
+                continue;
+            }
+            //灏唋ist涓寘鍚殑F_btm绉婚櫎, 閲嶆柊璁剧疆btmItemsFrom
+            String[] btms_ = link.btmItemsFrom;
+            List<String> btms = new ArrayList<String>();
+            for(int i = 0; i < btms_.length; i++){
+                if(!list.contains("F_" + btms_[i])){
+                    btms.add(btms_[i]);
+                }else{
+                    if(link.primitivesFrom.equals(btms_[i])){
+                        link.primitivesFrom = "";
+                    }
+                }
+            }
+            link.btmItemsFrom = btms.toArray(new String[0]);
+
+            //灏唋ist涓寘鍚殑T_btm绉婚櫎, 閲嶆柊璁剧疆btmItemsTo
+            btms_ = link.btmItemsTo;
+            btms = new ArrayList<String>();
+            for(int i = 0; i < btms_.length; i++){
+                if(!list.contains("T_" + btms_[i])){
+                    btms.add(btms_[i]);
+                }else{
+                    if(link.primitivesTo.equals(btms_[i])){
+                        link.primitivesTo = "";
+                    }
+                }
+            }
+            link.btmItemsTo = btms.toArray(new String[0]);
+            link.id = link.name;
+            try {
+                if(platformClientUtil.getLinkTypeService().modifyLinkType(link)){
+                    result.add(linkName);
+                }
+            } catch (PLException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+    /**
+     * 鑾峰彇闇�瑕佷慨澶嶇殑浼猻ql
+     * @return
+     */
+    private List<String> getRepairDML(HashMap<String, Object> dbCheckMap) {
+        List<String> list = new ArrayList<String>();
+        for(Iterator<String> ite = dbCheckMap.keySet().iterator(); ite.hasNext();){
+            String type = ite.next();
+            String dml = String.valueOf(dbCheckMap.get(type));
+            list.add(type + "/DML" + dml);
+        }
+        return list;
+    }
+    /**
+     * 妫�鏌ユ墍鏈夌殑閾炬帴绫诲瀷, 褰撻摼鎺ョ被鍨嬩腑寮曠敤鐨勪笟鍔$被鍨嬪凡缁忎笉瀛樺湪鏃�, 鍒犻櫎璇ラ摼鎺ョ被鍨嬩腑瀵逛笟鍔$被鍨嬬殑寮曠敤
+     * @return
+     */
+    private Map<String, List<String>> usedBtmCheck(){
+        try {
+            Map<String, List<String>> map = new HashMap<String, List<String>>();
+            LinkType[] links = platformClientUtil.getLinkTypeService().getLinkTypes();
+            for(int i = 0; i < links.length; i++){
+                LinkType link = links[i];
+                String[] btms = link.btmItemsFrom;
+                for(int k = 0; k < btms.length; k++){
+                    String btmName = btms[k];
+                    BizType btm = platformClientUtil.getBtmService().getBizTypeByName(btmName);
+                    if(btm == null || btm.name.equals("")){
+                        List<String> list = map.get(link.name);
+                        if(list == null){
+                            list = new ArrayList<String>();
+                            list.add("F_" + btmName);
+                        }else{
+                            list.add("F_" + btmName);
+                        }
+                        map.put(link.name, list);
+                    }
+                }
+                btms = link.btmItemsTo;
+                for(int k = 0; k < btms.length; k++){
+                    String btmName = btms[k];
+                    BizType btm = platformClientUtil.getBtmService().getBizTypeByName(btmName);
+                    if(btm == null || btm.name.equals("")){
+                        List<String> list = map.get(link.name);
+                        if(list == null){
+                            list = new ArrayList<String>();
+                            list.add("T_" + btmName);
+                        }else{
+                            list.add("T_" + btmName);
+                        }
+                        map.put(link.name, list);
+                    }
+                }
+            }
+            return map;
+        } catch (PLException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 
 
     /**
@@ -450,7 +969,7 @@
                 throw new PLException("500",new String[]{erreMsg});
             }
         }
-        return false;
+        return true;
     }
 
     /**
@@ -489,4 +1008,49 @@
         return null;
     }
 
+    /**
+     * 鑾峰彇浣跨敤璇ヤ笟鍔$被鍨嬬殑閾炬帴绫诲瀷鍚�
+     * @param btmName 涓氬姟绫诲瀷鍚嶇О
+     * @return
+     */
+    @Override
+    public List<String> getUsedBtmLinkList(String btmName) {
+        try {
+            List<String> list = new ArrayList<String>();
+            LinkType[] linkTypes = platformClientUtil.getLinkTypeService().getLinkTypes();
+            for(int i = 0; i < linkTypes.length; i++){
+                LinkType linkType = linkTypes[i];
+                if(this.containsBtm(linkType, btmName)){
+                    list.add(linkType.name);
+                }
+            }
+            return list;
+        } catch (PLException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 鎸囧畾鐨勯摼鎺ョ被鍨嬫槸鍚︿娇鐢ㄤ簡鎸囧畾鐨勪笟鍔$被鍨�
+     * @param link
+     * @param btmName
+     * @return
+     */
+    private boolean containsBtm(LinkType link, String btmName){
+        String[] btms = link.btmItemsFrom;
+        for(int i = 0; i < btms.length; i++){
+            if(btmName.equalsIgnoreCase(btms[i])){
+                return true;
+            }
+        }
+        btms = link.btmItemsTo;
+        for(int i = 0; i < btms.length; i++){
+            if(btmName.equalsIgnoreCase(btms[i])){
+                return true;
+            }
+        }
+        return false;
+    }
+
 }

--
Gitblit v1.9.3