From f49622515192a11878628b8eecbc7315671ae562 Mon Sep 17 00:00:00 2001
From: yuxc <yuxc@vci-tech.com>
Date: 星期四, 09 一月 2025 15:25:25 +0800
Subject: [PATCH] 在获取相关业务类型下的属性时,未在属性中定义的数据直接跳过

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsQueryTemplateImpl.java | 1740 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 1,709 insertions(+), 31 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsQueryTemplateImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsQueryTemplateImpl.java
index ca8ac52..666d847 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsQueryTemplateImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsQueryTemplateImpl.java
@@ -1,26 +1,48 @@
 package com.vci.web.service.impl;
 
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.vci.client.common.oq.OQTool;
-import com.vci.common.qt.object.QTConstants;
-import com.vci.common.qt.object.QueryTemplate;
+import com.vci.common.qt.object.*;
+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.data.LinkObject;
+import com.vci.corba.omd.ltm.LinkType;
 import com.vci.corba.omd.qtm.QTD;
 import com.vci.corba.omd.qtm.QTInfo;
-import com.vci.dto.QTInfoDTO;
+import com.vci.dto.*;
+import com.vci.omd.constants.SystemAttribute;
+import com.vci.omd.objects.OtherInfo;
+import com.vci.starter.web.exception.VciBaseException;
 import com.vci.starter.web.pagemodel.BaseResult;
-import com.vci.starter.web.util.*;
-import com.vci.web.service.*;
-import com.vci.web.util.DateUtil;
+import com.vci.starter.web.pagemodel.DataGrid;
+import com.vci.starter.web.util.ControllerUtil;
+import com.vci.starter.web.util.Lcm.DateUtil;
+import com.vci.starter.web.util.Lcm.Func;
+import com.vci.starter.web.util.LocalFileUtil;
+import com.vci.starter.web.util.VciBaseUtil;
+import com.vci.web.other.BtmQTExportData;
+import com.vci.web.other.LinkQTExportData;
+import com.vci.web.service.OsQuereyTemplateServiceI;
 import com.vci.web.util.PlatformClientUtil;
 import com.vci.web.util.WebUtil;
+import com.vci.web.utility.AttributeDataFetcher;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.dom4j.DocumentException;
 import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 鏌ヨ妯℃澘鏈嶅姟
@@ -37,6 +59,18 @@
     @Autowired
     private PlatformClientUtil platformClientUtil;
 
+    private final String EQUAL = "=";
+    private final String UNEQUAL = "!=";
+    private final String CONTAINS = "鍖呭惈";
+    private final String IN = "in";
+    private final String NOTIN = "not in";
+    private final String GT = ">";
+    private final String GTE = ">=";
+    private final String LT = "<";
+    private final String LTE = "<=";
+    private final String AND = "骞朵笖";
+    private final String OR = "鎴栬��";
+
     /**
      * 鏌ヨ妯℃澘鐨勫垪琛�
      * @param btmName 绫诲瀷
@@ -51,11 +85,12 @@
         }else {
             qtdArray = platformClientUtil.getQTDService().getBizTypeQTDs(btmName);
         }
-        return BaseResult.dataList(Arrays.asList(qtdArray));
+        List<QTD> qtdList = Arrays.asList(qtdArray).stream().sorted(Comparator.comparing(s -> s.name,String.CASE_INSENSITIVE_ORDER)).collect(Collectors.toList());
+        return BaseResult.dataList(qtdList);
     }
 
     /**
-     * 鏌ヨ妯℃澘
+     * 淇濆瓨鏌ヨ妯℃澘
      * @param qtd 鏌ヨ妯℃澘瀹炰綋绫�
      * @return 淇濆瓨缁撴灉
      */
@@ -75,6 +110,7 @@
             throw new PLException("500", new String[]{"澧炲姞涓氬姟绫诲瀷鏌ヨ妯℃澘澶辫触"});
         }
     }
+
     /**
      * 淇敼鏌ヨ妯℃澘
      * @param qtd 鏌ヨ妯℃澘瀹炰綋绫�
@@ -114,9 +150,9 @@
             return BaseResult.fail("鍒犻櫎鏌ヨ妯℃澘澶辫触");
         }
     }
+
     /**
-     *
-     * @param dataMap 浼犺緭鐨勬暟鎹璞★細
+     * @param qtInfoDTO 浼犺緭鐨勬暟鎹璞★細
      *                linkTypeName 閾炬帴绫诲瀷銆�
      *                rdPositive 鏂瑰悜锛宼rue姝e悜锛宖alse鍙嶅悜
      *                btmName 涓氬姟绫诲瀷鍚嶇О
@@ -127,8 +163,8 @@
      * @return 鏌ヨ缁撴灉
      */
     @Override
-    public BaseResult getCriteria(HashMap<String,Object> dataMap) throws PLException {
-        QueryTemplate qt = getQT(dataMap);
+    public BaseResult getCriteria(QTInfoDTO qtInfoDTO) throws PLException {
+        QueryTemplate qt = getQT(qtInfoDTO,true);
         String checkInfo = OQTool.checkQT(qt);
         if(!checkInfo.equals("OK")){
             throw new PLException("500", new String[]{checkInfo});
@@ -147,21 +183,185 @@
     public BaseResult getObjTypeQTs(String btName) throws PLException, DocumentException {
         VciBaseUtil.alertNotNull(btName,"绫诲瀷鍚�");
         QTInfo[] objTypeQTs = platformClientUtil.getQTDService().getObjTypeQTs(btName);
+        if(Func.isEmpty(objTypeQTs)){
+            return BaseResult.success();
+        }
         List<QTInfoDTO> dtos = new ArrayList<>();
+        Map<String, AttributeDef> allSysAttr = Arrays.stream(platformClientUtil.getBtmService().getSysAttributeDefs()).collect(Collectors.toMap(e -> e.name, e -> e));
+        allSysAttr.putAll(Arrays.stream(platformClientUtil.getLinkTypeService().getSysAttributeDefs()).collect(Collectors.toMap(e -> e.name, e -> e)));
+
         for (QTInfo obj : objTypeQTs) {
             QTInfoDTO qtInfoDTO = new QTInfoDTO();
             qtInfoDTO.setCreator(obj.creator);
             qtInfoDTO.setBtmName(obj.btmName);
             qtInfoDTO.setQtName(obj.qtName);
             qtInfoDTO.setLevelFlag(obj.levelFlag);
-//            qtInfoDTO.setQtText(obj.qtText);
+            //qtInfoDTO.setQtText(obj.qtText);
             qtInfoDTO.setQtUIText(obj.qtUIText);
-            qtInfoDTO.setQueryTemplate(OQTool.getQTByDoc(DocumentHelper.parseText(obj.qtText), obj.qtName));
+            if(StringUtils.isNotBlank(obj.qtUIText)){
+                //灏嗙粰瀹氱殑String鏂囨湰瑙f瀽涓篨ML鏂囨。骞惰繑鍥炴柊鍒涘缓鐨刣ocument
+                qtInfoDTO.setTree(analysisXml(obj, allSysAttr));
+            }
+            QueryTemplate qtByDoc = OQTool.getQTByDoc(DocumentHelper.parseText(obj.qtText), obj.qtName);
+            qtInfoDTO.setQueryTemplate(queryTemplateToDto(qtByDoc, allSysAttr));
             qtInfoDTO.setCreateTimeText(DateFormatUtils.format(new Date(obj.createTime), DateUtil.PATTERN_DATETIME));
             dtos.add(qtInfoDTO);
         }
+        // TODO: 2024/12/2 Ludc 杩斿洖鍊兼帓搴�
+        dtos = dtos.stream().sorted(Comparator.comparing(QTInfoDTO::getQtName,String.CASE_INSENSITIVE_ORDER)).collect(Collectors.toList());
         return BaseResult.dataList(dtos);
     }
+
+    /**
+     * 瀵硅薄杞崲
+     * @param qtByDoc 妯℃澘瀵硅薄
+     * @param allSysAttr 鎵�鏈夌郴缁熷睘鎬�
+     * @return 妯℃澘浼犺緭瀵硅薄
+     * @throws PLException
+     */
+    private QueryTemplateDTO queryTemplateToDto(QueryTemplate qtByDoc, Map<String, AttributeDef> allSysAttr) throws PLException {
+        QueryTemplateDTO dto = new QueryTemplateDTO();
+        dto.setId(qtByDoc.getId());
+        dto.setBtmType(qtByDoc.getBtmType());
+        dto.setDirection(qtByDoc.getDirection());
+        dto.setLevel(qtByDoc.getLevel());
+        dto.setQueryChildrenFlag(qtByDoc.isQueryChildren());
+        dto.setQueryISLeaf(qtByDoc.isQueryISLeaf());
+        dto.setClauseList(qtByDoc.getClauseList());
+        dto.setPageInfo(qtByDoc.getPageInfo());
+        dto.setLinkType(qtByDoc.getLinkType());
+        dto.setVersion(qtByDoc.getVersion());
+        dto.setType(qtByDoc.getType());
+        dto.setSecretFlag(qtByDoc.isSecretFlag());
+        dto.setRightFlag(qtByDoc.isRightFlag());
+        dto.setOrderInfoList(qtByDoc.getOrderInfoList());
+        dto.setRecReturnMode(qtByDoc.getRecReturnMode());
+        Condition con = qtByDoc.getCondition();
+        if(con != null){
+            ConditionDTO conDto = new ConditionDTO();
+            conDto.setRootCIName(con.getRootCIName());
+            Map<String, ConditionItem> ciMap = con.getCIMap();
+            Map<String, ConditionItemDTO> ciMapDto = new HashMap<>();
+            for (String key : ciMap.keySet()) {
+                ConditionItem item = ciMap.get(key);
+                LeafInfo leafInfo = item.getLeafInfo();
+                ConditionItemDTO itemDTO = new ConditionItemDTO();
+                itemDTO.setChildrenInfo(item.getChildrenInfo());
+                itemDTO.setId(item.getId());
+                itemDTO.setLeafFlag(item.isLeaf());
+                ciMapDto.put(key, itemDTO);
+                if(leafInfo == null){
+                    continue;
+                }
+                LeafInfoDTO leafInfoDTO = new LeafInfoDTO();
+                itemDTO.setLeafInfo(leafInfoDTO);
+                //澶勭悊鏌ヨ瀛楁绫诲瀷
+                String column = leafInfo.getClause();
+                if(column.contains(".")){
+                    column = StringUtils.substringAfterLast(column, ".");
+                }
+                if(column.contains(" ")){
+                    column = StringUtils.substringBefore(column, " ");
+                }
+                AttributeDef att = platformClientUtil.getAttributeService().getAttributeDefByName(column);
+                if(att == null || "".equals(att.oid)){
+                    att = allSysAttr.get(column.toLowerCase());
+                }
+                if(att == null){
+                    throw new PLException("500", new String[]{"灞炴�у瓧娈碉細" + column + "鍦ㄥ睘鎬ф睜涓湭鏌ヨ鍒帮紝璇风‘璁わ紒锛�"});
+                }
+                leafInfoDTO.setClause(leafInfo.getClause());
+
+                leafInfoDTO.setOperator(leafInfo.getOperator());
+                leafInfoDTO.setType(att.vtDataType);
+                if(leafInfo.getValue() != null ){
+                    LeafValueDto valueDto = new LeafValueDto();
+                    valueDto.setOrdinaryValue(leafInfo.getValue().getOrdinaryValue());
+                    valueDto.setQueryTemplate(leafInfo.getValue().getQueryTemplate() != null ? queryTemplateToDto(leafInfo.getValue().getQueryTemplate(),allSysAttr) : null);
+                    leafInfoDTO.setValue(valueDto);
+                }
+
+            }
+            conDto.setCIMap(ciMapDto);
+            dto.setCondition(conDto);
+        }
+        return dto;
+    }
+
+    /**
+     * 灏嗗鏈嶇鐣岄潰鏄剧ず鐨剎ml杞负hashMap
+     * @param obj 鐣岄潰瀵硅薄
+     * @return
+     * @throws DocumentException
+     */
+    private HashMap<String,Object> analysisXml(QTInfo obj, Map<String, AttributeDef> allSysAttr) throws DocumentException, PLException {
+        org.dom4j.Document document = DocumentHelper.parseText(obj.qtUIText);
+        if(document == null){
+            return null;
+        }
+        //鑾峰彇鏍硅妭鐐�,鍦ㄤ緥瀛愪腑灏辨槸responsedata鑺傜偣
+        Element root = document.getRootElement();
+        HashMap<String,Object> treeMap = new HashMap<>();
+        treeMap.put("connector",root.getText());
+        List<Element> children = root.elements();
+        List<Object> childList = new ArrayList<>();
+        for(Iterator<Element> i = children.iterator(); i.hasNext();){
+            Element child = i.next();
+            if(AND.equals(child.getText()) || OR.equals(child.getText())){
+                childList.add(addDefaultMutableTree(child, allSysAttr));
+            }else {
+                String column = StringUtils.substringBefore(child.getText().trim(), " ");
+
+                if(column.contains(".")){
+                    column = StringUtils.substringAfterLast(column, ".");
+                }
+                AttributeDef att = platformClientUtil.getAttributeService().getAttributeDefByName(column);
+                if(att == null || "".equals(att.oid)){
+                    att = allSysAttr.get(column.toLowerCase());
+                }
+                HashMap<String, String> data = new HashMap<>();
+                data.put("column",child.getText().trim());
+                data.put("type",att.vtDataType);
+                childList.add(data);
+            }
+        }
+        treeMap.put("child",childList);
+        return treeMap;
+    }
+
+    /**
+     * 灏嗗瓙鑺傜偣杞负map缁撴瀯
+     * @param element
+     */
+    public Map<String, Object> addDefaultMutableTree(Element element, Map<String, AttributeDef> allSysAttr) throws PLException {
+        List<Object> childList = new ArrayList<>();
+        List<Element> children = element.elements();
+        HashMap<String,Object> treeMap = new HashMap<>();
+        treeMap.put("connector",element.getText());
+        for(Iterator<Element> i = children.iterator(); i.hasNext();){
+            Element child = i.next();
+            if(AND.equals(child.getText()) || OR.equals(child.getText())){
+                childList.add(addDefaultMutableTree(child, allSysAttr));
+            }else {
+                String column = StringUtils.substringBefore(child.getText().trim(), " ");
+
+                if(column.contains(".")){
+                    column = StringUtils.substringAfterLast(column, ".");
+                }
+                AttributeDef att = platformClientUtil.getAttributeService().getAttributeDefByName(column);
+                if(att == null || "".equals(att.oid)){
+                    att = allSysAttr.get(column.toLowerCase());
+                }
+                HashMap<String, String> data = new HashMap<>();
+                data.put("column",child.getText().trim());
+                data.put("type",att.vtDataType);
+                childList.add(data);
+            }
+        }
+        treeMap.put("child",childList);
+        return treeMap;
+    }
+
     /**
      * 妫�鏌ユ煡璇㈡ā鏉垮悕瀛楁槸鍚﹀瓨鍦�
      * @param name 鏌ヨ妯℃澘鍚嶅瓧
@@ -174,34 +374,631 @@
     }
 
     /**
+     * 閾炬帴绫诲瀷鏌ヨ妯℃澘淇濆瓨
+     * @param qtInfoDTO 淇濆瓨浼犺緭瀵硅薄
+     * @return 淇濆瓨缁撴灉
+     */
+    @Override
+    public BaseResult linkSave(QTInfoDTO qtInfoDTO) throws PLException {
+        QueryTemplate qt = getQT(qtInfoDTO,true);
+        String checkInfo = OQTool.checkQT(qt);
+        if(!checkInfo.equals("OK")){
+            throw new PLException("500", new String[]{checkInfo});
+        }
+        boolean saveFlag ;
+        qt.setId(qtInfoDTO.getQtName());
+        qt.setOrderInfoList(qtInfoDTO.getQueryTemplate().getOrderInfoList());
+        QTInfo qtWrapper = new QTInfo();
+        qtWrapper.qtName = qt.getId();
+        qtWrapper.btmName = qt.getLinkType();
+        qtWrapper.creator = WebUtil.getCurrentUserId();
+        qtWrapper.createTime = System.currentTimeMillis();
+        if(qtInfoDTO.getTree() == null){
+            qtWrapper.qtUIText = "";
+        }else{
+            qtWrapper.qtUIText = getSeniorXML(qtInfoDTO);
+        }
+        qtWrapper.levelFlag = qtInfoDTO.getLevelFlag();
+        qtWrapper.qtText = OQTool.qtTOXMl(qt).asXML();
+        saveFlag = platformClientUtil.getQTDService().saveQT(qtWrapper);
+        if(saveFlag){
+            return BaseResult.success();
+        }else{
+            return BaseResult.fail("淇濆瓨鏌ヨ妯℃澘澶辫触");
+        }
+    }
+
+    /**
+     * 閾炬帴绫诲瀷鏌ヨ妯℃澘鏍戞煡璇紝鐢ㄤ簬鐣岄潰鐨勫鍑哄姛鑳�
+     * @return 鏌ヨ缁撴灉
+     */
+    @Override
+    public BaseResult getLinkTree() throws PLException {
+        LinkType[] linkTypes= null;
+        QTInfo[] qts = null;
+        HashMap<String,Object> tree = new HashMap();
+        tree.put("text","涓氬姟绫诲瀷");
+        if (linkTypes == null) {
+            List<LinkType> es = new ArrayList<LinkType>();
+            linkTypes = platformClientUtil.getLinkTypeService().getLinkTypes();
+            for (LinkType lt : linkTypes) {
+                QTInfo[] qtWrappers = platformClientUtil.getQTDService().getObjTypeQTs(lt.name);
+                if (qtWrappers.length!=0) {
+                    es.add(lt);
+                }
+            }
+            linkTypes = es.toArray(new LinkType[es.size()]);
+            //TODO:闇�淇娌℃湁鍏宠仈鏌ヨ妯℃澘涓氬姟绫诲瀷鍘绘帀
+            qts = platformClientUtil.getQTDService().getAllQTs();//鑾峰彇鎵�鏈夋煡璇㈡ā鏉�
+        }
+        List<HashMap<String,Object>> childList = new ArrayList<>();
+        //娣诲姞涓氬姟绫诲瀷鏍硅妭鐐�
+        for (LinkType plAction : linkTypes) {
+            HashMap<String,Object> childTree = new HashMap();
+            childTree.put("text", plAction.label + "/" +plAction.name);
+            childTree.put("oid", plAction.oid);
+//            tree.put("children", childTree);
+            addExportTreeNode(plAction, qts, childTree);
+            childList.add(childTree);
+        }
+        tree.put("children", childList);
+        return BaseResult.success(tree);
+    }
+
+    /**
+     * 鐢熸垚瀵煎嚭鏍戦�夋嫨浠ュ強瀵煎叆鏍戞樉绀�
+     * @param linkType
+     * @param qts
+     * @param tree
+     */
+    private void addExportTreeNode(LinkType linkType/*涓氬姟绫诲瀷*/,QTInfo[] qts/*鏌ヨ妯℃澘瀵硅薄*/,HashMap<String,Object> tree) {
+        List<String> childList = new ArrayList<>();
+        // 娣诲姞鏌ヨ妯℃澘瀵硅薄瀛愯妭鐐�
+        for (QTInfo qtItem : qts) {
+            //澶勭悊瀵煎叆鏃舵棤娉曡繘琛岀被鍨嬪垽鏂�
+            int splitLength = linkType.name.indexOf("銆�");
+            if(splitLength == -1){
+                splitLength = linkType.name.length();
+            }
+            if (qtItem.btmName.equals(linkType.name.substring(0,
+                    splitLength))) {
+                childList.add(qtItem.qtName);
+            }
+        }
+        tree.put("children",childList);
+    }
+
+    /**
+     * 灏嗛珮绾ф潯浠舵暟鎹浆涓簒ml
+     * @param qtInfoDTO 鏌ヨ妯℃澘鍒楄〃浼犺緭瀵硅薄
+     * @return xml鏁版嵁
+     */
+    private String getSeniorXML(QTInfoDTO qtInfoDTO){
+        HashMap<String, Object> tree = qtInfoDTO.getTree();
+        if(tree.isEmpty()){
+            return "";
+        }
+        StringBuilder xmlStr = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>");
+        xmlStr.append(tree.get("connector"));
+        List<Object> childrens = (List<Object>) tree.get("child");
+        Iterator<Object> children = childrens.iterator();
+        while (children.hasNext()) {
+            Object obj = children.next();
+            if(obj instanceof JSONObject && (((JSONObject) obj).get("connector").equals(AND)
+                    || ((JSONObject) obj).get("connector").equals(OR))){
+                xmlStr.append(getSeniorChildXML((JSONObject) obj));
+            }else{
+                xmlStr.append("<child>").append(obj).append("</child>");
+            }
+        }
+        return xmlStr.append("</root>").toString();
+
+    }
+
+    /**
+     * 灏嗛珮绾ф潯浠舵暟鎹浆涓簒ml
+     * @param childs 楂樼骇鏉′欢鏁版嵁
+     * @return xml鏁版嵁
+     */
+    private String getSeniorChildXML(JSONObject childs){
+
+        StringBuilder xmlStr = new StringBuilder("<child>" + childs.get("connector"));
+        List<Object> childrens = (List<Object>) childs.get("child");
+        if(childrens == null){
+            return "";
+        }
+        Iterator<Object> child = childrens.iterator();
+        while (child.hasNext()) {
+            Object obj = child.next();
+            if(obj instanceof JSONObject && (((JSONObject) obj).get("connector").equals(AND)
+                    || ((JSONObject) obj).get("connector").equals(OR))){
+                xmlStr.append(getSeniorChildXML((JSONObject) obj));
+            }else{
+                xmlStr.append("<child>").append(obj).append("</child>");
+            }
+        }
+        return xmlStr.append("</child>").toString();
+    }
+
+    /**
      * 缁勮鏌ヨ妯℃澘
      * @return
      */
-    public QueryTemplate getQT(HashMap<String,Object> dataMap){
+    public QueryTemplate getQT(QTInfoDTO qtInfoDTO,boolean isLinkType) throws PLException {
         QueryTemplate qt = new QueryTemplate();
-        qt.setType(QTConstants.TYPE_LINK);
-        //TODO String qtId =
-        qt.setLinkType((String) dataMap.get("linkTypeName"));
-        qt.setDirection( (Boolean)dataMap.get("rdPositive") ? QTConstants.DIRECTION_POSITIVE : QTConstants.DIRECTION_OPPOSITE);
-        qt.setBtmType((String) dataMap.get("btmName"));
-        if("鎵�鏈夌被鍨�".equals(dataMap.get("combRelaType"))){
-            qt.setBtmType("*");
+
+        if(isLinkType){
+            qt.setType(QTConstants.TYPE_LINK);
+            qt.setLinkType(qtInfoDTO.getBtmName());
+            qt.setDirection(qtInfoDTO.getQueryTemplate().getDirection());
+            qt.setBtmType(qtInfoDTO.getQueryTemplate().getBtmType());
+            qt.setVersion(qtInfoDTO.getQueryTemplate().getVersion());
+            qt.setQueryISLeaf(qtInfoDTO.getQueryTemplate().isQueryISLeaf());
+            qt.setLevel(qtInfoDTO.getQueryTemplate().getLevel());
+        }else{
+            qt.setType(QTConstants.TYPE_BTM);
+            qt.setBtmType(qtInfoDTO.getBtmName());
         }
-        qt.setVersion(getVersion((String) dataMap.get("versionValue")));
-        qt.setQueryISLeaf((Boolean) dataMap.get("isQueryIsLeaf"));
-        qt.setLevel(StringUtils.isBlank((CharSequence) dataMap.get("level")) ? 1 : Integer.valueOf(String.valueOf(dataMap.get("level"))));
+
         List<String> clauseList = new ArrayList<String>();
         //TODO 鏌ヨ鍒� 鏄剧ず鍒�
         clauseList.add("*");
         qt.setClauseList(clauseList);
-//        Condition con = new Condition();
-//        qt.setCondition(con);
-//        HashMap<String, ConditionItem> ciMap = getCIMap();
-//        con.setCIMap(ciMap);
-//        con.setRootCIName(con.getRootCINameByCIMap(ciMap));
+        Condition con = new Condition();
+        qt.setCondition(con);
+        HashMap<String, ConditionItem> ciMap = getCIMap(qtInfoDTO);
+        con.setCIMap(ciMap);
+        con.setRootCIName(con.getRootCINameByCIMap(ciMap));
         return qt;
     }
 
+    /**
+     * 鑾峰彇鏌ヨ鏉′欢
+     * @return
+     */
+    private HashMap<String, ConditionItem> getCIMap(QTInfoDTO qtInfoDTO) throws PLException {
+        HashMap<String, ConditionItem> ciMap = new HashMap<>();
+        //鏅�氭煡璇㈡潯浠�
+        if(qtInfoDTO.getLevelFlag() == 0){
+            /**
+             * 鍔犲叆鍙跺瓙鑺傜偣
+             */
+            for(int i = 0; i < qtInfoDTO.getCondition().size(); i++){
+                ConditionItem ci = new ConditionItem();
+                String id = "ci" + (i + 1);
+                ci.setId(id);
+                ci.setLeafFlag(true);
+                HashMap<String, String> condition = qtInfoDTO.getCondition().get(i);
+                String clause = condition.get("clause");
+                String operator = condition.get("operator");
+                String ordinaryValue = condition.get("ordinaryValue");
+                //add by zhangweiwei 2014/12/09  end  鍥犲鍔犻�夋嫨鏌ヨ妯℃澘鎸夐挳灏嗘瘡琛岀粍浠舵暟鐢�4鏀规垚5
+                LeafInfo leafInfo = new LeafInfo();
+                if(clause.contains("T_OID.") || clause.contains("F_OID.")){
+                    //鍘绘帀T_OID.鎴栬�匜_OID.
+                    String clause_ = clause.substring(6);
+                    //灞炴�т负鍙傜収灞炴��
+                    if(clause_.contains(".")){
+                        int fpIndex = clause_.indexOf(".");
+                        String refAbName = clause.substring(0, fpIndex + 6);
+                        clause = clause.substring(fpIndex + 6 + 1);
+                        leafInfo.setClause(refAbName);
+                        //鍘绘帀T_OID.鎴栬�匜_OID.
+                        refAbName = refAbName.substring(6);
+                        leafInfo.setOperator(Operator.IN);
+                        QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
+                        LeafValue lValue = new LeafValue();
+                        lValue.setQueryTemplate(qt);
+                        leafInfo.setValue(lValue);
+                        //灞炴�т负闈炲弬鐓у睘鎬�
+                    }else{
+                        leafInfo.setClause(clause);
+                        leafInfo.setOperator(operator);
+                        LeafValue lValue = new LeafValue();
+                        leafInfo.setValue(lValue);
+                        //add by zhangweiwei 2014/12/09 start
+                        //濡傛灉宓屽Link
+                        if(ordinaryValue.contains(";")){
+                            leafInfo.setOperator(Operator.IN);
+                            String[] values = ordinaryValue.split(";");
+                            String  QTname = values[0];
+                            String  attr = values[1].substring(0, values[1].length());
+                            try {
+                                QTInfo qt = platformClientUtil.getQTDService().getQT(QTname);
+                                String qtText = qt.qtText;
+                                QueryTemplate qt_ = OQTool.getQTByQTText(qt.qtName, qtText);
+                                List<String> clauseList = new ArrayList<String>();
+                                clauseList.add(attr);
+                                qt_.setClauseList(clauseList);
+                                lValue.setQueryTemplate(qt_);
+                                //lValue.setAttr(attr);
+                            } catch (PLException e) {
+                                e.printStackTrace();
+                            }
+                            catch (DocumentException e1) {
+                                e1.printStackTrace();
+                            }
+                        }else{
+                            lValue.setOrdinaryValue(ordinaryValue);
+                        }
+                        //add by zhangweiwei 2014/12/09 end
+                    }
+                }else{
+                    //灞炴�т负鍙傜収灞炴��
+                    if(clause.contains(".")){
+                        int fpIndex = clause.indexOf(".");
+                        String refAbName = clause.substring(0, fpIndex);
+                        clause = clause.substring(fpIndex + 1);
+                        leafInfo.setClause(refAbName);
+                        leafInfo.setOperator(Operator.IN);
+                        QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
+                        LeafValue lValue = new LeafValue();
+                        lValue.setQueryTemplate(qt);
+                        leafInfo.setValue(lValue);
+                        //灞炴�т负闈炲弬鐓у睘鎬�
+                    }else{
+                        leafInfo.setClause(clause);
+                        leafInfo.setOperator(operator);
+                        LeafValue lValue = new LeafValue();
+                        leafInfo.setValue(lValue);
+                        //add by zhangweiwei 2014/12/09 start
+                        //濡傛灉宓屽Link
+                        if(ordinaryValue.contains(";")){
+                            leafInfo.setOperator(Operator.IN);
+                            String[] values = ordinaryValue.split(";");
+                            String  QTname = values[0];
+                            String  attr = values[1].substring(0, values[1].length());
+                            try {
+                                QTInfo qt = platformClientUtil.getQTDService().getQT(QTname);
+                                String qtText = qt.qtText;
+                                QueryTemplate qt_ = OQTool.getQTByQTText(qt.qtName, qtText);
+                                List<String> clauseList = new ArrayList<String>();
+                                clauseList.add(attr);
+                                qt_.setClauseList(clauseList);
+                                lValue.setQueryTemplate(qt_);
+                                //lValue.setAttr(attr);
+                            } catch (PLException e) {
+                                e.printStackTrace();
+                            } catch (DocumentException e1) {
+                                e1.printStackTrace();
+                            }
+
+                        }else{
+                            lValue.setOrdinaryValue(ordinaryValue);
+                        }
+                        //add by zhangweiwei 2014/12/09 end
+                    }
+                }
+
+                ci.setLeafInfo(leafInfo);
+                ciMap.put(ci.getId(), ci);
+            }
+
+            Iterator<String> iterator = ciMap.keySet().iterator();
+            ArrayList<ConditionItem> ciList = new ArrayList<ConditionItem>();
+            String lCIId = null;
+            while(iterator.hasNext()){
+                lCIId = iterator.next();
+                break;
+            }
+            int count = ciMap.size();
+            while(iterator.hasNext()){
+                String rCIId = iterator.next();
+                ConditionItem pCI = new ConditionItem();
+                String pId = "ci" + ++count;
+                pCI.setId(pId);
+                pCI.setLeafFlag(false);
+                ChildrenInfo pChildrenInfo = new ChildrenInfo();
+                pChildrenInfo.setLeftCIName(lCIId);
+                pChildrenInfo.setConnector(Connector.AND);
+                pChildrenInfo.setRightCIName(rCIId);
+                pCI.setChildrenInfo(pChildrenInfo);
+                ciList.add(pCI);
+                lCIId = pId;
+            }
+            for(Iterator<ConditionItem> i = ciList.iterator(); i.hasNext();){
+                ConditionItem ci = i.next();
+                ciMap.put(ci.getId(), ci);
+            }
+            //楂樼骇鏌ヨ鏉′欢
+        }else if(qtInfoDTO.getLevelFlag() == 1){
+            ciMap = getCIMapForSeniorTree(qtInfoDTO);
+        }
+        return ciMap;
+    }
+
+    /**
+     * 鑾峰彇楂樼骇鏌ヨ鐨勬煡璇㈡潯浠堕泦鍚�
+     * @return
+     */
+    private HashMap<String, ConditionItem> getCIMapForSeniorTree(QTInfoDTO qtInfoDTO) throws PLException {
+        HashMap<String, ConditionItem> ciMap = new HashMap<>();
+        HashMap<String, Object> tree = qtInfoDTO.getTree();
+        if (tree.isEmpty()) {
+            // 鏃犳煡璇㈡潯浠剁殑鏌ヨ
+            return null;
+        }
+        ArrayList<ConditionItem> ciList = new ArrayList<ConditionItem>();
+        String connector = String.valueOf(tree.get("connector"));
+        List<Object> childrens = (List<Object>) tree.get("child");
+        Iterator<Object> children = childrens.iterator();
+        while (children.hasNext()) {
+            Object obj = children.next();
+            if(obj instanceof JSONObject && (((JSONObject) obj).get("connector").equals(AND)
+                    || ((JSONObject) obj).get("connector").equals(OR))){
+                List<ConditionItem> subCIList = getCIList((JSONObject) obj, ciList.size() + 1);
+                if(subCIList == null){
+                    continue;
+                }
+                if(ciList.size() > 0){
+                    ConditionItem leftCI = ciList.get(ciList.size() - 1);
+                    ConditionItem rightCI = subCIList.get(subCIList.size() - 1);
+                    ciList.addAll(subCIList);
+                    ConditionItem pCI = new ConditionItem();
+                    pCI.setId("ci" + (ciList.size() + 1));
+                    ciList.add(pCI);
+                    pCI.setLeafFlag(false);
+                    ChildrenInfo cInfo = new ChildrenInfo();
+                    pCI.setChildrenInfo(cInfo);
+                    cInfo.setLeftCIName(leftCI.getId());
+                    cInfo.setConnector(connector);
+                    cInfo.setRightCIName(rightCI.getId());
+                }else{
+                    ciList.addAll(subCIList);
+                }
+            }else{
+                String text = String.valueOf(obj);
+                if(text == null || text.equals("")){
+                    continue;
+                }
+                if(!text.contains(Operator.EQUAL) && !text.contains(Operator.UNEQUAL) && !text.contains(Operator.CONTAINS)
+                        && !text.contains(Operator.IN) && !text.contains(Operator.NOTIN) &&!text.contains(Operator.GTE) && !text.contains(Operator.GT)
+                        && !text.contains(Operator.LTE) && !text.contains(Operator.LT)){
+                    continue;
+                }
+                if(ciList.size() > 0){
+                    ConditionItem leftCI = ciList.get(ciList.size() - 1);
+                    ConditionItem rightCI = getCIByNode(text, ciList.size() + 1);
+                    ciList.add(rightCI);
+                    ConditionItem pCI = new ConditionItem();
+                    pCI.setId("ci" + (ciList.size() + 1));
+                    ciList.add(pCI);
+                    pCI.setLeafFlag(false);
+                    ChildrenInfo cInfo = new ChildrenInfo();
+                    pCI.setChildrenInfo(cInfo);
+                    cInfo.setLeftCIName(leftCI.getId());
+                    cInfo.setConnector(connector);
+                    cInfo.setRightCIName(rightCI.getId());
+                }else{
+                    ConditionItem ci = getCIByNode(text, ciList.size() + 1);
+                    ciList.add(ci);
+                }
+            }
+        }
+
+        for(int i = 0; i < ciList.size(); i++){
+            ConditionItem ci = ciList.get(i);
+            ciMap.put(ci.getId(), ci);
+        }
+        return ciMap;
+    }
+
+    /**
+     * 鏍戝寲涓�涓煡璇㈡潯浠剁粍鑺傜偣
+     * @param children
+     * @param beginId
+     * @return
+     */
+    private List<ConditionItem> getCIList(JSONObject children, int beginId) throws PLException {
+        List<ConditionItem> ciList = new ArrayList<>();
+        String connector = String.valueOf(children.get("connector"));
+        List<Object> childrens = (List<Object>) children.get("child");
+        if(childrens == null){
+            return null;
+        }
+        Iterator<Object> child = childrens.iterator();
+        while (child.hasNext()) {
+            Object obj = child.next();
+            if(obj instanceof JSONObject && (((JSONObject) obj).get("connector").equals(AND)
+                    || ((JSONObject) obj).get("connector").equals(OR))){
+                List<ConditionItem> subCIList = getCIList((JSONObject) obj, beginId);
+                if(ciList.size() > 0){
+                    ConditionItem leftCI = ciList.get(ciList.size() - 1);
+                    ConditionItem rightCI = subCIList.get(subCIList.size() - 1);
+                    ciList.addAll(subCIList);
+                    beginId = beginId + subCIList.size();
+                    ConditionItem pCI = new ConditionItem();
+                    pCI.setId("ci" + beginId);
+                    ciList.add(pCI);
+                    beginId = beginId + 1;
+                    pCI.setLeafFlag(false);
+                    ChildrenInfo cInfo = new ChildrenInfo();
+                    pCI.setChildrenInfo(cInfo);
+                    cInfo.setLeftCIName(leftCI.getId());
+                    cInfo.setConnector(connector);
+                    cInfo.setRightCIName(rightCI.getId());
+                }else{
+                    ciList.addAll(subCIList);
+                    beginId = beginId + subCIList.size();
+                }
+            }else{
+                String text = String.valueOf(obj);
+                if(text == null || text.equals("")){
+                    continue;
+                }
+                if(!text.contains(Operator.EQUAL) && !text.contains(Operator.UNEQUAL) && !text.contains(Operator.CONTAINS)
+                        && !text.contains(Operator.IN) && !text.contains(Operator.NOTIN) &&!text.contains(Operator.GTE) && !text.contains(Operator.GT)
+                        && !text.contains(Operator.LTE) && !text.contains(Operator.LT)){
+                    continue;
+                }
+                if(ciList.size() > 0){
+                    ConditionItem leftCI = ciList.get(ciList.size() - 1);
+                    ConditionItem rightCI = getCIByNode(text, beginId);
+                    ciList.add(rightCI);
+                    beginId = beginId + 1;
+                    ConditionItem pCI = new ConditionItem();
+                    pCI.setId("ci" + beginId);
+                    ciList.add(pCI);
+                    beginId = beginId + 1;
+                    pCI.setLeafFlag(false);
+                    ChildrenInfo cInfo = new ChildrenInfo();
+                    pCI.setChildrenInfo(cInfo);
+                    cInfo.setLeftCIName(leftCI.getId());
+                    cInfo.setConnector(connector);
+                    cInfo.setRightCIName(rightCI.getId());
+                }else{
+                    ConditionItem ci = getCIByNode(text, beginId);
+                    ciList.add(ci);
+                    beginId = beginId + 1;
+                }
+            }
+        }
+        return ciList;
+    }
+
+    /**
+     * 楂樼骇鏌ヨ
+     * 鎶奛ode鍐呭瑙f瀽鎴怌onditionItem
+     * @param text
+     * @param id
+     * @return
+     */
+    private ConditionItem getCIByNode(String text, int id) throws PLException {
+        ConditionItem ci = new ConditionItem();
+        ci.setId("ci" + id);
+        ci.setLeafFlag(true);
+        LeafInfo leafInfo = new LeafInfo();
+        ci.setLeafInfo(leafInfo);
+        String operator = null;
+        if(text.contains(Operator.EQUAL)){
+            operator = Operator.EQUAL;
+        }else if(text.contains(Operator.CONTAINS)){
+            operator = Operator.CONTAINS;
+        }else if(text.contains(Operator.UNEQUAL)){
+            operator = Operator.UNEQUAL;
+        }else if(text.contains(Operator.IN)){
+            operator = Operator.IN;
+        }else if(text.contains(Operator.NOTIN)){
+            operator = Operator.NOTIN;
+        }else if(text.contains(Operator.GTE)){
+            operator = Operator.GTE;
+        }else if(text.contains(Operator.GT)){
+            operator = Operator.GT;
+        }else if(text.contains(Operator.LTE)){
+            operator = Operator.LTE;
+        }else if(text.contains(Operator.LT)){
+            operator = Operator.LT;
+        }
+        int operatorIndex = text.indexOf(operator);
+        String clause = text.substring(0, operatorIndex).trim();
+        String ordinaryValue = text.substring(operatorIndex + 2).trim();
+        if(clause.contains("T_OID.") || clause.contains("F_OID.")){
+            //鍘绘帀T_OID.鎴栬�匜_OID.
+            String clause_ = clause.substring(6);
+            //灞炴�т负鍙傜収灞炴��
+            if(clause_.contains(".")){
+                int fpIndex = clause_.indexOf(".");
+                String refAbName = clause.substring(0, fpIndex + 6);
+                clause = clause.substring(fpIndex + 6 + 1);
+                leafInfo.setClause(refAbName);
+                //鍘绘帀T_OID.鎴栬�匜_OID.
+                refAbName = refAbName.substring(6);
+                leafInfo.setOperator(Operator.IN);
+                QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
+                LeafValue lValue = new LeafValue();
+                lValue.setQueryTemplate(qt);
+                leafInfo.setValue(lValue);
+                //灞炴�т负闈炲弬鐓у睘鎬�
+            }else{
+                leafInfo.setClause(clause);
+                leafInfo.setOperator(operator);
+                LeafValue lValue = new LeafValue();
+                leafInfo.setValue(lValue);
+                lValue.setOrdinaryValue(ordinaryValue);
+            }
+        }else{
+            //灞炴�т负鍙傜収灞炴��
+            if(clause.contains(".")){
+                int fpIndex = clause.indexOf(".");
+                String refAbName = clause.substring(0, fpIndex);
+                clause = clause.substring(fpIndex + 1);
+                leafInfo.setClause(refAbName);
+                leafInfo.setOperator(Operator.IN);
+                QueryTemplate qt = getRefQT(refAbName, clause, operator, ordinaryValue);
+                LeafValue lValue = new LeafValue();
+                lValue.setQueryTemplate(qt);
+                leafInfo.setValue(lValue);
+                //灞炴�т负闈炲弬鐓у睘鎬�
+            }else{
+                leafInfo.setClause(clause);
+                leafInfo.setOperator(operator);
+                LeafValue lValue = new LeafValue();
+                leafInfo.setValue(lValue);
+                lValue.setOrdinaryValue(ordinaryValue);
+            }
+        }
+
+        return ci;
+    }
+
+    /**
+     * 鑾峰彇鍙傜収鐨勬煡璇㈡ā鏉�
+     * @param refAbName: 鍙傜収灞炴�у悕
+     * @param clause: 灞炴�у弬鐓х殑涓氬姟绫诲瀷涓殑灞炴��
+     * @param operator
+     * @param ordinaryValue
+     * @return
+     */
+    private QueryTemplate getRefQT(String refAbName, String clause,
+                                   String operator, String ordinaryValue) throws PLException {
+        QueryTemplate qt = new QueryTemplate();
+        List<String> clauseList = new ArrayList<String>();
+        clauseList.add("OID");
+        qt.setClauseList(clauseList);
+        AttributeDef refAb = platformClientUtil.getAttributeService().getAttributeDefByName(refAbName);
+        OtherInfo otherInfo = OtherInfo.getOtherInfoByText(refAb.other);
+        int refFlag = otherInfo.getRefFlag();
+        String type = otherInfo.getRefTypeName();
+        if(refFlag == 0){
+            qt.setType(QTConstants.TYPE_BTM);
+            qt.setBtmType(type);
+        }else if(refFlag == 1){
+            qt.setType(QTConstants.TYPE_LINK);
+            qt.setLinkType(type);
+        }
+        Condition condition = new Condition();
+        qt.setCondition(condition);
+        condition.setRootCIName("ci1");
+        HashMap<String, ConditionItem> ciMap = new HashMap<String, ConditionItem>();
+        condition.setCIMap(ciMap);
+        ConditionItem ci = new ConditionItem();
+        ci.setId("ci1");
+        ciMap.put(ci.getId(), ci);
+        ci.setLeafFlag(true);
+        LeafInfo leafInfo = new LeafInfo();
+        if(clause.contains(".")){
+            int fpIndex = clause.indexOf(".");
+            String refAbName_ = clause.substring(0, fpIndex);
+            clause = clause.substring(fpIndex + 1);
+            leafInfo.setClause(refAbName_);
+            leafInfo.setOperator(Operator.IN);
+            QueryTemplate qt_ = getRefQT(refAbName_, clause, operator, ordinaryValue);
+            LeafValue lValue = new LeafValue();
+            lValue.setQueryTemplate(qt_);
+            leafInfo.setValue(lValue);
+            qt.setId("qt_" + refAbName + "_" + refAbName_);
+        }else{
+            leafInfo.setClause(clause);
+            leafInfo.setOperator(operator);
+            LeafValue lValue = new LeafValue();
+            lValue.setOrdinaryValue(ordinaryValue);
+            leafInfo.setValue(lValue);
+            qt.setId("qt_" + refAbName + "_" + clause);
+        }
+        ci.setLeafInfo(leafInfo);
+        condition.setCIMap(ciMap);
+        return qt;
+    }
 
     /**
      * 杩斿洖鏌ヨ鐨勭増鏈�
@@ -227,7 +1024,6 @@
         return version;
     }
 
-
     /**
      * 鏍¢獙鍙傛暟
      * @param qtd
@@ -244,4 +1040,886 @@
             throw new PLException("500", new String[]{"璇ユā鏉垮畾涔夊悕宸茬粡琚娇鐢�, 璇锋洿鎹�"});
         }
     }
+
+    /**
+     * 瀵煎嚭閾炬帴绫诲瀷鏌ヨ妯℃澘
+     * names 鏌ヨ妯℃澘鍚�
+     * @return
+     */
+    @Override
+    public void expLinkTemplate(String names, HttpServletResponse response) throws PLException, IOException {
+        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
+        String vciqtmfFileName = defaultTempFolder + File.separator + "LinkTemplateExp" + new Date().getTime() + ".vciqtf";
+        LinkQTExportData exportData = new LinkQTExportData();
+        String[] splits = names.split(",");
+        for (String name : splits) {
+            QTInfo qt = platformClientUtil.getQTDService().getQT(name);
+            exportData.getAllQTs().put(qt.qtName,qt);
+            LinkType linkType = platformClientUtil.getLinkTypeService().getLinkType(qt.btmName);
+            if(linkType != null && !linkType.oid.equals("")){
+                exportData.getSelectedBtmItems().put(linkType.name, linkType);
+                exportData.getSelectedBtmAttrs().put(linkType.name, linkType.attributes);
+                exportData.getAllQTDs().put(linkType.name, platformClientUtil.getQTDService().getLinkTypeQTDs(linkType.name));
+            }
+        }
+        ObjectOutputStream vciamfFileStream = null;
+        try {
+            File vciqtmfFile = new File(vciqtmfFileName);
+            vciamfFileStream = new ObjectOutputStream(new FileOutputStream(vciqtmfFile));
+            vciamfFileStream.writeObject(exportData);
+        }finally {
+            try {
+                if (vciamfFileStream != null) {
+                    vciamfFileStream.flush();
+                    vciamfFileStream.close();
+                }
+            } catch (Exception e) {
+                throw new PLException("500",new String[]{"瀵煎嚭娴佸叧闂紓甯革紒"});
+            }
+        }
+        ControllerUtil.writeFileToResponse(response,vciqtmfFileName);
+        FileUtil.del(defaultTempFolder + File.separator);
+    }
+
+    /**
+     * 瀵煎叆閾炬帴绫诲瀷鏌ヨ妯℃澘
+     * @param file 涓婁紶鐨勬枃浠�
+     * @return 瀵煎叆缁撴灉
+     */
+    @Override
+    public BaseResult impLinkTemplate(MultipartFile file) throws IOException, ClassNotFoundException {
+
+        if (file == null) {
+            return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"});
+        }
+        if (!file.getOriginalFilename().endsWith(".vciqtf")) {
+            throw new VciBaseException("浠呰兘涓婁紶.vciqtf鏍煎紡鏂囦欢锛岃閲嶆柊涓婁紶锛�");
+        }
+        ObjectInputStream obj = new ObjectInputStream(
+                file.getInputStream());
+        LinkQTExportData qtExportData = (LinkQTExportData) obj.readObject();
+        List<LinkType> ltsNew = new ArrayList<>();
+        List<QTInfo> qTWrapperNew = new ArrayList<>();
+        Map<String/* 绫诲瀷鍚嶇О */, QTD[]/* 鏌ヨ妯℃澘瀹氫箟 */> norepQTDs = new HashMap<String, QTD[]>();
+        addImportData(qtExportData, ltsNew, qTWrapperNew, norepQTDs);
+        QTInfo[] qts = qTWrapperNew
+                .toArray(new QTInfo[qTWrapperNew.size()]);
+        //澶勭悊鏍戠殑杩斿洖
+        HashMap<String,Object> tree = new HashMap();
+        tree.put("text","閾炬帴绫诲瀷");
+        List<HashMap<String,Object>> childList = new ArrayList<>();
+        //娣诲姞涓氬姟绫诲瀷鏍硅妭鐐�
+        for (LinkType plAction : ltsNew) {
+            HashMap<String,Object> childTree = new HashMap();
+            childTree.put("text", plAction.label + "/" +plAction.name);
+            childTree.put("oid", plAction.oid);
+            addExportTreeNode(plAction, qts, childTree);
+            childList.add(childTree);
+        }
+        tree.put("children", childList);
+        return BaseResult.success(tree);
+    }
+
+    // 鏁版嵁杩囨护
+    private void addImportData(LinkQTExportData qtExportData, List<LinkType> ltsNew, List<QTInfo> qTWrapperNew,
+                               Map<String/* 绫诲瀷鍚嶇О */, QTD[]/* 鏌ヨ妯℃澘瀹氫箟 */> norepQTDs) {
+        Map<String/* 绫诲瀷鍚嶇О */, QTD[]/* 鏌ヨ妯℃澘瀹氫箟 */> allQTDs = qtExportData
+                .getAllQTDs();
+        Map<String/* 绫诲瀷鍚嶇О */, LinkType/* 绫诲瀷瀵硅薄 */> selectedBtmItems = qtExportData
+                .getSelectedBtmItems();
+        Map<String/* 绫诲瀷鍚嶇О */, String[]/* 绫诲瀷鎵�灞炲睘鎬� */> selectedBtmAttrs = qtExportData
+                .getSelectedBtmAttrs();
+        Map<String/* 鏌ヨ妯℃澘鍚嶇О */, QTInfo/* 鏌ヨ妯℃澘瀵硅薄 */> allSelectedQTs = qtExportData
+                .getAllQTs();
+        if (allQTDs.size() == 0 || allQTDs == null
+                || selectedBtmItems.size() == 0 || selectedBtmItems == null
+                || selectedBtmAttrs.size() == 0 || selectedBtmAttrs == null
+                || allSelectedQTs.size() == 0 || allSelectedQTs == null) {
+            throw new VciBaseException("瀵煎叆鐨勬ā鏉挎暟鎹湁璇�!!!");
+        }
+        Set<Map.Entry<String, QTD[]>> pLActions = allQTDs.entrySet();
+        Set<Map.Entry<String, QTInfo>> pLQts = allSelectedQTs.entrySet();
+        Set<Map.Entry<String, LinkType>> LinkpLQts = selectedBtmItems.entrySet();
+        for (Map.Entry<String, QTD[]> entry : pLActions) {
+            String string = entry.getKey();
+            QTD[] qtds = entry.getValue();
+            getPLQtIsInDB(string, qtds, norepQTDs);
+        }
+        for (Map.Entry<String, LinkType> entry : LinkpLQts) {
+            String string = entry.getKey();
+            LinkType LinkType = entry.getValue();
+            getPLQtBtmItem(string, LinkType, ltsNew);
+        }
+        Map<String/*绫诲瀷鍚嶇О*/, QTD[]/*鏌ヨ妯℃澘瀹氫箟*/> newNorepQTDs = getnewNorepQTDs(norepQTDs,allSelectedQTs);
+        for (Map.Entry<String, QTInfo> entry : pLQts) {
+            String string = entry.getKey();
+            QTInfo qtWrapper = entry.getValue();
+            getPLQtWrapper(string, qtWrapper, ltsNew, qTWrapperNew, newNorepQTDs);
+        }
+
+    }
+
+    /**
+     * 鏌ヨ妯℃澘瀹氫箟鐨勫鐞�
+     * @param string
+     * @param qtds
+     */
+    private void getPLQtIsInDB(String string, QTD[] qtds, Map<String/* 绫诲瀷鍚嶇О */, QTD[]/* 鏌ヨ妯℃澘瀹氫箟 */> norepQTDs) {
+        // TODO Auto-generated method stub
+        try {
+            QTD[] qtds2 = platformClientUtil.getQTDService().getBizTypeQTDs(string);
+            QTD[] qtdsNewQtds = null;
+            List<QTD> es = new ArrayList<>();
+            for (QTD qtd : qtds) {
+                boolean isleat = true;
+                for (int i = 0; i < qtds2.length; i++) {
+                    if (qtd.name.equals(qtds2[i].name)) {
+                        isleat = false;
+                        break;
+                    }
+                }
+                if (isleat) {
+                    es.add(qtd);
+                }
+            }
+            if (es.size() != 0) {
+                qtdsNewQtds = es.toArray(new QTD[es.size()]);
+                norepQTDs.put(string, qtdsNewQtds);
+            }
+        } catch (PLException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    private void getPLQtBtmItem(String string, LinkType linkType, List<LinkType> ltsNew) {
+        // TODO Auto-generated method stub
+        try {
+            LinkType queryLinkType = platformClientUtil.getLinkTypeService().getLinkType(string);
+            LinkType[] btmArray = platformClientUtil.getLinkTypeService().getLinkTypes();
+            String[] strings = queryLinkType.attributes;
+            String[] stringsFrom = queryLinkType.btmItemsFrom;
+            String[] stringsTo = queryLinkType.btmItemsTo;
+            boolean b = true;
+            for (int i = 0; i < btmArray.length; i++) {
+                if (btmArray[i].name.equals(string)) {
+                    b = false;
+                    if (Arrays.equals(linkType.attributes, strings)
+                            && Arrays
+                            .equals(linkType.btmItemsFrom, stringsFrom)
+                            && Arrays.equals(linkType.btmItemsTo, stringsTo)) {
+                        btmArray[i].name += "銆愰摼鎺ョ被鍨嬪凡瀛樺湪銆�";
+                        /* this.btmArray[i] = btmArray[i]; */
+                        ltsNew.add(btmArray[i]);
+                    } else {
+                        btmArray[i].name += "銆愰摼鎺ョ被鍨嬪瓨鍦ㄤ絾灞炴�т笉涓�鑷淬��";
+                        ltsNew.add(btmArray[i]);
+                    }
+                }
+            }
+            if (b) {
+                linkType.name += "銆愰摼鎺ョ被鍨嬩笉瀛樺湪銆�";
+                ltsNew.add(linkType);
+            }
+        } catch (PLException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    private void getPLQtBtmItem2(String string, BizType bizType, List<BizType> ltsNew) {
+        // TODO Auto-generated method stub
+        try {
+            BizType queryBizType = platformClientUtil.getBtmService().getBizTypes(string)[0];
+            BizType[] btmArray = platformClientUtil.getBtmService().getBizTypes("");
+            String[] strings = queryBizType.apNameArray;
+            boolean b = true;
+            for (int i = 0; i < btmArray.length; i++) {
+                if (btmArray[i].name.equals(string)) {
+                    b = false;
+                    if (Arrays.equals(bizType.apNameArray, strings)) {
+                        btmArray[i].name += "銆愪笟鍔$被鍨嬪凡瀛樺湪銆�";
+                        ltsNew.add(btmArray[i]);
+                    } else {
+                        btmArray[i].name += "銆愪笟鍔$被鍨嬪瓨鍦ㄤ絾灞炴�т笉涓�鑷淬��";
+                        ltsNew.add(btmArray[i]);
+                    }
+                }
+            }
+            if (b) {
+                bizType.name += "銆愪笟鍔$被鍨嬩笉瀛樺湪銆�";
+                ltsNew.add(bizType);
+            }
+        } catch (PLException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    private void getPLQtWrapper(String string, QTInfo qtWrapper, List<LinkType> ltsNew, List<QTInfo> qTWrapperNew, Map<String/*绫诲瀷鍚嶇О*/, QTD[]/*鏌ヨ妯℃澘瀹氫箟*/> newNorepQTDs) {
+        try {
+            QTInfo[] qtws = platformClientUtil.getQTDService().getAllQTs();
+            boolean islaet = true;
+            for (int i = 0; i < qtws.length; i++) {
+                if (string.equals(qtws[i].qtName)) {
+                    islaet = false;
+                    for (LinkType lt : ltsNew) {
+                        if (qtWrapper.btmName.equals(lt.name.substring(0,
+                                lt.name.indexOf("銆�")))) {
+                            if (lt.name.endsWith("銆愰摼鎺ョ被鍨嬪凡瀛樺湪銆�")) {
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉垮凡瀛樺湪锛屼笉瀵煎叆銆�";
+                                qTWrapperNew.add(qtWrapper);
+                            }else if(lt.name.endsWith("銆愰摼鎺ョ被鍨嬪瓨鍦ㄤ絾灞炴�т笉涓�鑷淬��")){
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞為摼鎺ョ被鍨嬪睘鎬т笉涓�鑷达紝涓嶅鍏ャ��";
+                                qTWrapperNew.add(qtWrapper);
+                            }else{
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞為摼鎺ョ被鍨嬩笉瀛樺湪锛屼笉瀵煎叆銆�";
+                                qTWrapperNew.add(qtWrapper);
+                            }
+                        }
+                    }
+                }
+            }
+            if (islaet) {
+                for (LinkType btmItem : ltsNew) {
+                    if (qtWrapper.btmName.equals(btmItem.name.substring(0,
+                            btmItem.name.indexOf("銆�")))) {
+                        if (btmItem.name.endsWith("銆愰摼鎺ョ被鍨嬪凡瀛樺湪銆�")) {
+                            //鍒ゆ柇鏌ヨ妯℃澘瀹氫箟鏄惁瀛樺湪锛岃繘琛屼繚瀛�
+                            QTD[] qtds = newNorepQTDs.get(qtWrapper.btmName);
+                            if(qtds != null){
+                                for (QTD qtd : qtds) {
+                                    QTD qtdByName = platformClientUtil.getQTDService().getQTDByName(qtd.name);
+                                    if(!(qtdByName != null && StringUtils.isNotBlank(qtdByName.name))){
+                                        boolean b = platformClientUtil.getQTDService().addQTD(qtd);
+                                        if(!b){
+                                            qtWrapper.qtName += qtWrapper.qtName+"瀵煎叆鏌ヨ妯℃澘瀹氫箟銆�" + qtdByName.name + "銆戝け璐ワ紒";
+                                        }
+                                    }
+                                }
+                                newNorepQTDs.remove(qtWrapper.btmName);
+                            }
+                            boolean success = platformClientUtil.getQTDService().saveQT(qtWrapper);
+                            if(!success){
+                                qtWrapper.qtName += qtWrapper.qtName+"瀵煎叆澶辫触锛�";
+                            }else {
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉垮鍏ユ垚鍔燂紒銆�";
+                            }
+                            qTWrapperNew.add(qtWrapper);
+                        }else if(btmItem.name.endsWith("銆愰摼鎺ョ被鍨嬪瓨鍦ㄤ絾灞炴�т笉涓�鑷淬��")){
+                            qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞為摼鎺ョ被鍨嬪睘鎬т笉涓�鑷达紝涓嶅鍏ャ��";
+                            qTWrapperNew.add(qtWrapper);
+                        }else{
+                            qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞為摼鎺ョ被鍨嬩笉瀛樺湪锛屼笉瀵煎叆銆�";
+                            qTWrapperNew.add(qtWrapper);
+                        }
+                    }
+                }
+            }
+        } catch (PLException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void getPLBtmQtWrapper(String string, QTInfo qtWrapper, List<BizType> ltsNew, List<QTInfo> qTWrapperNew, Map<String/*绫诲瀷鍚嶇О*/, QTD[]/*鏌ヨ妯℃澘瀹氫箟*/> newNorepQTDs) {
+        try {
+            QTInfo[] qtws = platformClientUtil.getQTDService().getAllQTs();
+            boolean islaet = true;
+            for (int i = 0; i < qtws.length; i++) {
+                if (string.equals(qtws[i].qtName)) {
+                    islaet = false;
+                    for (BizType lt : ltsNew) {
+                        if (qtWrapper.btmName.equals(lt.name.substring(0,
+                                lt.name.indexOf("銆�")))) {
+                            if (lt.name.endsWith("銆愪笟鍔$被鍨嬪凡瀛樺湪銆�")) {
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉垮凡瀛樺湪锛屼笉瀵煎叆銆�";
+                                qTWrapperNew.add(qtWrapper);
+                            }else if(lt.name.endsWith("銆愪笟鍔$被鍨嬪瓨鍦ㄤ絾灞炴�т笉涓�鑷淬��")){
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞炰笟鍔$被鍨嬪睘鎬т笉涓�鑷达紝涓嶅鍏ャ��";
+                                qTWrapperNew.add(qtWrapper);
+                            }else{
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞炰笟鍔$被鍨嬩笉瀛樺湪锛屼笉瀵煎叆銆�";
+                                qTWrapperNew.add(qtWrapper);
+                            }
+                        }
+                    }
+                }
+            }
+            if (islaet) {
+                for (BizType btmItem : ltsNew) {
+                    if (qtWrapper.btmName.equals(btmItem.name.substring(0,
+                            btmItem.name.indexOf("銆�")))) {
+                        if (btmItem.name.endsWith("銆愪笟鍔$被鍨嬪凡瀛樺湪銆�")) {
+                            //鍒ゆ柇鏌ヨ妯℃澘瀹氫箟鏄惁瀛樺湪锛岃繘琛屼繚瀛�
+                            QTD[] qtds = newNorepQTDs.get(qtWrapper.btmName);
+                            if(qtds != null){
+                                for (QTD qtd : qtds) {
+                                    QTD qtdByName = platformClientUtil.getQTDService().getQTDByName(qtd.name);
+                                    if(!(qtdByName != null && StringUtils.isNotBlank(qtdByName.name))){
+                                        boolean b = platformClientUtil.getQTDService().addQTD(qtd);
+                                        if(!b){
+                                            qtWrapper.qtName += qtWrapper.qtName+"瀵煎叆鏌ヨ妯℃澘瀹氫箟銆�" + qtdByName.name + "銆戝け璐ワ紒";
+                                        }
+                                    }
+                                }
+                                newNorepQTDs.remove(qtWrapper.btmName);
+                            }
+                            boolean success = platformClientUtil.getQTDService().saveQT(qtWrapper);
+                            if(!success){
+                                qtWrapper.qtName += qtWrapper.qtName+"瀵煎叆澶辫触锛�";
+                            }else {
+                                qtWrapper.qtName += "銆愭煡璇㈡ā鏉垮鍏ユ垚鍔燂紒銆�";
+                            }
+                            qTWrapperNew.add(qtWrapper);
+                        }else if(btmItem.name.endsWith("銆愪笟鍔$被鍨嬪瓨鍦ㄤ絾灞炴�т笉涓�鑷淬��")){
+                            qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞炰笟鍔$被鍨嬪睘鎬т笉涓�鑷达紝涓嶅鍏ャ��";
+                            qTWrapperNew.add(qtWrapper);
+                        }else{
+                            qtWrapper.qtName += "銆愭煡璇㈡ā鏉挎墍灞炰笟鍔$被鍨嬩笉瀛樺湪锛屼笉瀵煎叆銆�";
+                            qTWrapperNew.add(qtWrapper);
+                        }
+                    }
+                }
+            }
+        } catch (PLException e) {
+            e.printStackTrace();
+        }
+    }
+
+    //鏍规嵁閫夋嫨鐨勬煡璇㈡ā鏉胯繃婊ゆā鏉垮畾涔�
+    private Map<String, QTD[]> getnewNorepQTDs(Map<String, QTD[]> norepQTDs,
+                                               Map<String, QTInfo> allQTs) {
+        // TODO Auto-generated method stub
+        Map<String, QTD[]> map = new HashMap<String, QTD[]>();
+        Set<Map.Entry<String, QTInfo>> pLQts = allQTs.entrySet();
+        Set<Map.Entry<String, QTD[]>> pLActions = norepQTDs.entrySet();
+        for (Map.Entry<String, QTD[]> entrys : pLActions) {
+            for (Map.Entry<String, QTInfo> entry : pLQts) {
+                if(entry.getValue().btmName.equals(entrys.getKey())){
+                    map.put(entrys.getKey(), entrys.getValue());
+                }
+            }
+        }
+        return map;
+    }
+    /**
+     * 鏌ヨ鏂规鍒犻櫎
+     * @param names 鏌ヨ鏂规鍚�
+     * @return 鎿嶄綔缁撴灉
+     */
+    @Override
+    public BaseResult deleteLinkTemplate(String names) throws PLException {
+        if(StringUtils.isBlank(names)){
+            return BaseResult.fail("璇烽�夋嫨鏌ヨ鏂规锛�");
+        }
+        String[] nameSplit = names.split(",");
+        boolean b = platformClientUtil.getQTDService().deleteQTs(nameSplit);
+        if(!b){
+            return BaseResult.fail("鍒犻櫎澶辫触锛侊紒锛�");
+        }
+        return BaseResult.success("鏌ヨ妯℃澘鍒犻櫎鎴愬姛锛�");
+    }
+
+    /**
+     * @param qtInfoDTO 浼犺緭鐨勬暟鎹璞★細
+     *                linkTypeName 閾炬帴绫诲瀷銆�
+     *                rdPositive 鏂瑰悜锛宼rue姝e悜锛宖alse鍙嶅悜
+     *                btmName 涓氬姟绫诲瀷鍚嶇О
+     *                combRelaType 涓氬姟绫诲瀷閫夋嫨鍊�
+     *                versionValue 鐗堟湰鐝鍊�
+     *                isQueryIsLeaf 鏄惁閫夋嫨涓嬬骇
+     *                level 瀛愯妭鐐瑰眰鏁�
+     * @return 鏌ヨ缁撴灉
+     */
+    @Override
+    public BaseResult getCriteriaBtm(QTInfoDTO qtInfoDTO) throws PLException {
+        QueryTemplate qt = getQT(qtInfoDTO,false);
+        String checkInfo = OQTool.checkQT(qt);
+        if(!checkInfo.equals("OK")){
+            throw new PLException("500", new String[]{checkInfo});
+        }
+        qt.setId("qt1");
+        try {
+            BusinessObject[] result = platformClientUtil.getQueryService().findBTMObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML());
+            return BaseResult.dataList(Arrays.asList(result));
+        }catch (Exception e){
+            String errorLog = "鏌ヨ鏃跺嚭鐜伴棶棰橈紝璇锋鏌ラ厤缃殑鏉′欢鏄惁瀛樺湪闂锛屽叿浣撳師鍥狅細"+VciBaseUtil.getExceptionMessage(e);
+            throw new VciBaseException(errorLog);
+        }
+    }
+
+    /**
+     * 涓氬姟绫诲瀷鏌ヨ妯℃澘淇濆瓨
+     * @param qtInfoDTO 淇濆瓨浼犺緭瀵硅薄
+     * @return 淇濆瓨缁撴灉
+     */
+    @Override
+    public BaseResult btmSave(QTInfoDTO qtInfoDTO) throws PLException {
+        VciBaseUtil.alertNotNull(
+                qtInfoDTO,"淇濆瓨鐨勪笟鍔$被鍨嬫ā鏉垮璞�",
+                qtInfoDTO.getBtmName(),"璇烽�夋嫨涓氬姟绫诲瀷鍜屾煡璇㈡ā鏉垮畾涔夋潵鍒涘缓鏌ヨ妯℃澘"
+        );
+
+        //add by caill start 閬嶅巻鏅�氭煡璇㈡ā鏉胯緭鍏ユ涓殑鍊煎仛鏍¢獙
+        //		ArrayList<String> list = cpm_centerPanel.getList();
+        //		for(int i=0;i<list.size();i++){
+        //			String text = (String) list.get(i);
+        //			if(text.contains("'")){
+        //				JOptionPane.showMessageDialog(cp_mainPanel, "鏉′欢鍊间腑鍖呭惈浜嗛潪娉曞瓧绗�", "闈炴硶瀛楃", JOptionPane.ERROR_MESSAGE);
+        //				return;
+        //			}
+        //		}
+        //淇濆瓨涔嬪墠甯﹀嚭宸查�夋嫨鐨剄tName
+        QueryTemplate qt = getQT(qtInfoDTO,false);
+        //鍓嶇璋冪敤杩欎釜鏂规硶isExistsQT()
+        /*if(isExists(qtName)){
+            return BaseResult.success("","璇ユ煡璇㈡ā鏉垮悕宸茬粡瀛樺湪,鏄惁瑕嗙洊锛�");
+        }*/
+        String checkInfo = OQTool.checkQT(qt);
+        if(!checkInfo.equals("OK")){
+            throw new PLException("500", new String[]{checkInfo});
+        }
+        qt.setId(qtInfoDTO.getQtName());
+        //璁剧疆鎺掑簭淇℃伅
+        qt.setOrderInfoList(qtInfoDTO.getQueryTemplate().getOrderInfoList());
+        QTInfo qtWrapper = new QTInfo();
+        qtWrapper.qtName = qtInfoDTO.getQtName();
+        qtWrapper.btmName = qt.getBtmType();
+        qtWrapper.creator = WebUtil.getCurrentUserId();
+        qtWrapper.createTime = System.currentTimeMillis();
+        if(qtInfoDTO.getTree() == null){
+            qtWrapper.qtUIText = "";
+        }else{
+            //褰撳嬀閫変簡楂樼骇鏌ヨ鏃堕渶瑕佸鐞嗛珮绾ф煡璇㈢殑鐩稿叧鏉′欢
+            qtWrapper.qtUIText = getSeniorXML(qtInfoDTO);
+        }
+        qtWrapper.levelFlag = qtInfoDTO.getLevelFlag();
+        qtWrapper.qtText = OQTool.qtTOXMl(qt).asXML();
+        boolean saveFlag = platformClientUtil.getQTDService().saveQT(qtWrapper);
+        if(saveFlag){
+            return BaseResult.success("淇濆瓨鏌ヨ妯℃澘鎴愬姛");
+        }else{
+            return BaseResult.fail("淇濆瓨鏌ヨ妯℃澘澶辫触");
+        }
+    }
+
+    /**
+     * 鏇存柊鏁版嵁搴撶粨鏋�
+     * @return 淇濆瓨缁撴灉
+     */
+    @Override
+    public BaseResult updateDBStructure() throws PLException {
+        boolean f = platformClientUtil.getQTDService().updateQT();
+        if(f){
+            return BaseResult.success("鏇存柊鎴愬姛");
+        }else{
+            return BaseResult.fail("鏇存柊澶辫触");
+        }
+    }
+
+    /**
+     * 涓氬姟绫诲瀷鏌ヨ妯℃澘鏍戞煡璇紝鐢ㄤ簬鐣岄潰鐨勫鍑哄姛鑳�
+     * @return 鏌ヨ缁撴灉
+     */
+    @Override
+    public BaseResult getBtmQtTree() throws PLException {
+        BizType[] bizTypes= null;
+        QTInfo[] qts = null;
+        HashMap<String,Object> tree = new HashMap();
+        tree.put("text","涓氬姟绫诲瀷");
+        if (bizTypes == null) {
+            List<BizType> es = new ArrayList<>();
+            bizTypes = platformClientUtil.getBtmService().getBizTypes("");
+            for (BizType lt : bizTypes) {
+                QTInfo[] qtWrappers = platformClientUtil.getQTDService().getObjTypeQTs(lt.name);
+                if (qtWrappers.length!=0) {
+                    es.add(lt);
+                }
+            }
+            bizTypes = es.toArray(new BizType[es.size()]);
+            //TODO:闇�淇娌℃湁鍏宠仈鏌ヨ妯℃澘涓氬姟绫诲瀷鍘绘帀
+            qts = platformClientUtil.getQTDService().getAllQTs();//鑾峰彇鎵�鏈夋煡璇㈡ā鏉�
+        }
+        List<HashMap<String,Object>> childList = new ArrayList<>();
+        //娣诲姞涓氬姟绫诲瀷鏍硅妭鐐�
+        for (BizType plAction : bizTypes) {
+            HashMap<String,Object> childTree = new HashMap();
+            childTree.put("text", plAction.label + "/" +plAction.name);
+            childTree.put("oid", plAction.oid);
+            //tree.put("children", childTree);
+            addExportTreeNode(plAction, qts, childTree);
+            childList.add(childTree);
+        }
+        tree.put("children", childList);
+        return BaseResult.success(tree);
+    }
+
+    /**
+     * 瀵煎嚭涓氬姟绫诲瀷鏌ヨ妯℃澘
+     * names 鏌ヨ妯℃澘鍚�
+     * @return
+     */
+    @Override
+    public String expBtmQTTemplate(String qtNames) throws PLException, IOException {
+        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
+        String vciqtmfFileName = defaultTempFolder + File.separator + "BtmTemplateExp" + new Date().getTime() + ".vciqtf";
+        String[] names = qtNames.split(",");
+        BtmQTExportData exportData = new BtmQTExportData();
+        for (String name : names) {
+            QTInfo qt = platformClientUtil.getQTDService().getQT(name);
+            exportData.getAllQTs().put(qt.qtName,qt);
+            BizType[] bizTypes = platformClientUtil.getBtmService().getBizTypes(qt.btmName);
+            for (int i = 0; i < bizTypes.length; i++) {
+                BizType bizType = bizTypes[i];
+                if(bizTypes != null && !bizType.oid.equals("")){
+                    exportData.getSelectedBtmItems().put(bizType.name, bizType);
+                    exportData.getSelectedBtmAttrs().put(bizType.name, bizType.apNameArray);
+                    exportData.getAllQTDs().put(bizType.name, platformClientUtil.getQTDService().getBizTypeQTDs(bizType.name));
+                }
+            }
+        }
+        ObjectOutputStream vciamfFileStream = null;
+        try {
+            File vciqtmfFile = new File(vciqtmfFileName);
+            vciamfFileStream = new ObjectOutputStream(new FileOutputStream(vciqtmfFile));
+            vciamfFileStream.writeObject(exportData);
+        }finally {
+            try {
+                if (vciamfFileStream != null) {
+                    vciamfFileStream.flush();
+                    vciamfFileStream.close();
+                }
+            } catch (Exception e) {
+                throw new PLException("500",new String[]{"瀵煎嚭娴佸叧闂紓甯革紒"});
+            }
+        }
+        //ControllerUtil.writeFileToResponse(response,vciqtmfFileName);
+        //FileUtil.del(defaultTempFolder + File.separator);
+        return vciqtmfFileName;
+    }
+
+    /**
+     * 鏌ヨ鏉′欢涓嬬殑閫夋嫨鏌ヨ妯℃澘瀵硅瘽妗嗭紙鏌ヨ鍏ㄩ儴妯℃澘鍜屾墍瀵瑰簲鐨勪笟鍔$被鍨嬫垨閾炬帴绫诲瀷鍚嶏級
+     * @return
+     */
+    @Override
+    public BaseResult getAllQTs() throws PLException {
+        QTInfo[] allQTs = platformClientUtil.getQTDService().getAllQTs();
+        List<QTInfo> allQTList = Arrays.stream(allQTs).sorted(Comparator.comparing(o -> o.qtName, String.CASE_INSENSITIVE_ORDER)).collect(Collectors.toList());
+        DataGrid<QTInfo> dataGrid = new DataGrid<>();
+        dataGrid.setData(allQTList);
+        dataGrid.setTotal(allQTs.length);
+        return BaseResult.dataGrid(dataGrid);
+    }
+
+    /**
+     * 瀵煎叆涓氬姟绫诲瀷鏌ヨ妯℃澘
+     * @param file 涓婁紶鐨勬枃浠�
+     * @return 瀵煎叆缁撴灉
+     */
+    @Override
+    public BaseResult impBtmTemplate(MultipartFile file) throws IOException, ClassNotFoundException {
+        if (file == null) {
+            return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"});
+        }
+        if (!file.getOriginalFilename().endsWith(".vciqtf")) {
+            throw new VciBaseException("浠呰兘涓婁紶.vciqtf鏍煎紡鏂囦欢锛岃閲嶆柊涓婁紶锛�");
+        }
+        ObjectInputStream obj = new ObjectInputStream(
+                file.getInputStream());
+        BtmQTExportData qtExportData = (BtmQTExportData) obj.readObject();
+        List<BizType> ltsNew = new ArrayList<>();
+        List<QTInfo> qTWrapperNew = new ArrayList<>();
+        Map<String/* 绫诲瀷鍚嶇О */, QTD[]/* 鏌ヨ妯℃澘瀹氫箟 */> norepQTDs = new HashMap<String, QTD[]>();
+        addImportBtmData(qtExportData, ltsNew, qTWrapperNew, norepQTDs);
+        QTInfo[] qts = qTWrapperNew
+                .toArray(new QTInfo[qTWrapperNew.size()]);
+        //澶勭悊鏍戠殑杩斿洖
+        HashMap<String,Object> tree = new HashMap();
+        tree.put("text","涓氬姟绫诲瀷");
+        List<HashMap<String,Object>> childList = new ArrayList<>();
+        //娣诲姞涓氬姟绫诲瀷鏍硅妭鐐�
+        for (BizType plAction : ltsNew) {
+            HashMap<String,Object> childTree = new HashMap();
+            childTree.put("text", plAction.label + "/" +plAction.name);
+            childTree.put("oid", plAction.oid);
+            addExportTreeNode(plAction, qts, childTree);
+            childList.add(childTree);
+        }
+        tree.put("children", childList);
+        return BaseResult.success(tree);
+    }
+
+    /**
+     * 鏌ヨ妯℃澘鐨勫垪琛ㄦ坊鍔犱簡瀛楁鐨勭浉鍏冲睘鎬�
+     * @param btmName 绫诲瀷
+     * @param linkFlag 鏄惁閾炬帴绫诲瀷 锛歵rue 閾炬帴绫诲瀷 锛宖alse 涓氬姟绫诲瀷
+     * @param direction 姝e弽鏂瑰悜
+     * @return 鏌ヨ妯℃澘鐨勫垪琛�
+     */
+    @Override
+    public BaseResult queryTemplateListByAttr(String btmName, Boolean linkFlag, String direction) throws PLException {
+        //杩斿洖鐨勭晫闈笅鎷夋鏄剧ず鏍�
+        List<QTDDTO> qtddtos = new ArrayList<>();
+        //灏嗛摼鎺ョ被鍨嬩笌涓氬姟绫诲瀷鐨勬墍鏈夐粯璁ゅ瓧娈垫煡璇㈠嚭鏉ユ斁鍒癿ap閲岄潰鏂逛究鍚庣画璋冪敤
+        Map<String, AttributeDef> allSysAttr = Arrays.stream(platformClientUtil.getBtmService().getSysAttributeDefs()).collect(Collectors.toMap(e -> e.name, e -> e));
+        allSysAttr.putAll(Arrays.stream(platformClientUtil.getLinkTypeService().getSysAttributeDefs()).collect(Collectors.toMap(e -> e.name, e -> e)));
+        QTD[] qtdArray = null;
+        //鏌ヨ鐩稿叧绫诲瀷鐨勬煡璇㈡ā鏉胯繘琛屽鐞�
+        if(linkFlag){
+            qtdArray = platformClientUtil.getQTDService().getLinkTypeQTDs(btmName);
+        }else {
+            qtdArray = platformClientUtil.getQTDService().getBizTypeQTDs(btmName);
+        }
+        //鑾峰彇灞炴�х殑鏁版嵁鍔犺浇绫�
+        AttributeDataFetcher attrDataFetcher = new AttributeDataFetcher();
+        for (QTD qtd : qtdArray) {
+            QTDDTO qtddto = new QTDDTO();
+            qtddto.setName(qtd.name);
+            qtddto.setCreateTime(qtd.createTime);
+            qtddto.setLinkTypeName(qtd.linkTypeName);
+            qtddto.setBtmName(qtd.btmName);
+            qtddto.setCreator(qtd.creator);
+            for (String abName : qtd.abNames) {
+                //AttributeDef att = platformClientUtil.getAttributeService().getAttributeDefByName(abName);
+                AttributeDef att = attrDataFetcher.getAttributeDef(abName);
+                //濡傛灉鍦ㄥ睘鎬ф帴鍙d腑娌℃湁鏌ュ埌鐩稿叧瀛楁搴旇灏卞湪榛樿瀛楁涓�
+                if(att == null || "".equals(att.oid)){
+                    att = allSysAttr.get(abName.toLowerCase());
+                }
+                if(direction != null) {
+                    if (direction.equals(QTConstants.DIRECTION_POSITIVE)) {
+                        if(att == null ){
+                            continue;
+//                            throw new PLException("500",new String[]{"灞炴�у瓧娈�:"+ abName +"鏈煡璇㈠埌锛岃纭锛�"});
+                        }
+                        att.name = "T_OID." + abName;
+                    } else if (direction.equals(QTConstants.DIRECTION_OPPOSITE)) {
+                        if(att == null ){
+                            continue;
+//                            throw new PLException("500",new String[]{"灞炴�у瓧娈�:"+ abName +"鏈煡璇㈠埌锛岃纭锛�"});
+                        }
+                        att.name = "F_OID." + abName;
+                    }
+                }else{
+                    att.name = abName;
+                }
+                AttributeDefDTO attrDto = new AttributeDefDTO();
+                attrDto.setDescription(att.description);
+                attrDto.setLabel(att.label);
+                attrDto.setOid(att.oid);
+                attrDto.setCreator(att.creator);
+                attrDto.setName(att.name);
+                attrDto.setDefValue(att.defValue);
+                attrDto.setLayersNum(1);
+                attrDto.setRage(att.rage);
+                attrDto.setVtDataType(att.vtDataType);
+                attrDto.setOther(att.other);
+                qtddto.getAttrs().add(attrDto);
+                addNode(attrDto, allSysAttr);
+            }
+            qtddtos.add(qtddto);
+        }
+        return BaseResult.dataList(qtddtos);
+    }
+
+    /**
+     * 瀛愯妭鐐瑰鐞�
+     * @param attributeDefByName 鐖惰妭鐐圭殑灞炴�т俊鎭�
+     * @param allSysAttr 鎵�鏈夐粯璁ゅ瓧娈�
+     */
+    private void addNode(AttributeDefDTO attributeDefByName, Map<String, AttributeDef> allSysAttr){
+
+        if(attributeDefByName.getLayersNum() >= 3){
+            return;
+        }
+        String abName = attributeDefByName.name;
+        //鍙杗ode涓婄殑鏈�鍚庝竴涓睘鎬у悕
+        if(abName.contains(".")){
+            abName = abName.substring(abName.lastIndexOf(".") + 1);
+        }
+        if(SystemAttribute.sysAttList().contains(abName.toUpperCase())){
+            return;
+        }
+        AttributeDef abItem = null;
+        try {
+            abItem = platformClientUtil.getAttributeService().getAttributeDefByName(abName);
+            String other = abItem.other;
+//			String btmName = ApProvider.getInstance().getOtherValueByType(other, BTM);
+            OtherInfo otherInfo = OtherInfo.getOtherInfoByText(other);
+            int refFlag = otherInfo.getRefFlag();
+            String refTypeName = otherInfo.getRefTypeName();
+            if(refFlag != -1){
+                //鍙傜収涓氬姟绫诲瀷
+                if(refFlag == 0){
+                    //pName: 涓哄弬鐓у睘鎬у悕鍔犱笂璺緞
+                    String pName = attributeDefByName.name + ".";
+                    String[] abNames = platformClientUtil.getBtmService().getAttributeNames(refTypeName);
+                    for(int i = 0; i < abNames.length; i++){
+                        String abName_ = abNames[i];
+                        AttributeDef att = platformClientUtil.getAttributeService().getAttributeDefByName(abName_);
+                        if(att == null || "".equals(att.oid)){
+                            att = allSysAttr.get(abName_.toLowerCase());
+                            if(att == null || "".equals(att.oid)){
+                                continue;
+                            }
+                        }
+                        att.name = pName + abName_ ;
+                        AttributeDefDTO attrDto = new AttributeDefDTO();
+                        attrDto.setDescription(att.description);
+                        attrDto.setLabel(att.label);
+                        attrDto.setOid(att.oid);
+                        attrDto.setLayersNum(attributeDefByName.getLayersNum() + 1);
+                        attrDto.setCreator(att.creator);
+                        attrDto.setName(att.name);
+                        attrDto.setDefValue(att.defValue);
+                        attrDto.setRage(att.rage);
+                        attrDto.setVtDataType(att.vtDataType);
+                        attrDto.setOther(att.other);
+                        attributeDefByName.getAttrs().add(attrDto);
+                        addNode(attrDto, allSysAttr);
+                    }
+                    //绯荤粺灞炴�D,NAME,DESCRIPTION
+                    for (int i = 0; i < SystemAttribute.bosysAttList().size(); i++) {
+                        AttributeDef attributeDef = allSysAttr.get(SystemAttribute.bosysAttList().get(i).toLowerCase());
+                        if(Func.isEmpty(attributeDef)){
+                            break;
+                        }
+                        AttributeDefDTO attrDto = new AttributeDefDTO();
+                        attrDto.setDescription(attributeDef.description);
+                        attrDto.setLabel(attributeDef.label);
+                        attrDto.setOid(attributeDef.oid);
+                        attrDto.setLayersNum(attributeDefByName.getLayersNum() + 1);
+                        attrDto.setCreator(attributeDef.creator);
+                        attrDto.setName(pName + SystemAttribute.bosysAttList().get(i));
+                        attrDto.setDefValue(attributeDef.defValue);
+                        attrDto.setRage(attributeDef.rage);
+                        attrDto.setVtDataType(attributeDef.vtDataType);
+                        attrDto.setOther(attributeDef.other);
+                        attributeDefByName.getAttrs().add(attrDto);
+                        addNode(attrDto, allSysAttr);
+                    }
+                    //鍙傜収閾炬帴绫诲瀷
+                }else if(refFlag == 1){
+                    //pName: 涓哄弬鐓у睘鎬у悕鍔犱笂璺緞
+                    String pName = attributeDefByName.name + ".";
+                    LinkType link = null;
+                    try {
+                        link = platformClientUtil.getLinkTypeService().getLinkType(refTypeName);
+                    } catch (Exception e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    } catch (Throwable e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                    if(link != null){
+                        String[] abNames = link.attributes;
+                        for(int i = 0; i < abNames.length; i++){
+                            String abName_ = abNames[i];
+                            AttributeDef att = platformClientUtil.getAttributeService().getAttributeDefByName(abName_);
+                            if(att == null || att.oid.equals("")){
+                                att = allSysAttr.get(abName_.toLowerCase());
+                            }
+                            AttributeDefDTO attrDto = new AttributeDefDTO();
+                            attrDto.setDescription(att.description);
+                            attrDto.setLabel(att.label);
+                            attrDto.setOid(att.oid);
+                            attrDto.setLayersNum(attributeDefByName.getLayersNum() + 1);
+                            attrDto.setCreator(att.creator);
+                            attrDto.setName(pName + abName_);
+                            attrDto.setDefValue(att.defValue);
+                            attrDto.setRage(att.rage);
+                            attrDto.setVtDataType(att.vtDataType);
+                            attrDto.setOther(att.other);
+                            attributeDefByName.getAttrs().add(attrDto);
+                            addNode(attrDto, allSysAttr);
+                        }
+                        //绯荤粺灞炴�D,NAME,DESCRIPTION
+                        for (int i = 0; i < SystemAttribute.losysAttList().size(); i++) {
+                            AttributeDef sysAttributeDefs = allSysAttr.get(SystemAttribute.losysAttList().get(i).toLowerCase());
+                            AttributeDefDTO attrDto = new AttributeDefDTO();
+                            attrDto.setDescription(sysAttributeDefs.description);
+                            attrDto.setLabel(sysAttributeDefs.label);
+                            attrDto.setOid(sysAttributeDefs.oid);
+                            attrDto.setLayersNum(attributeDefByName.getLayersNum() + 1);
+                            attrDto.setCreator(sysAttributeDefs.creator);
+                            attrDto.setName(pName + SystemAttribute.losysAttList().get(i));
+                            attrDto.setDefValue(sysAttributeDefs.defValue);
+                            attrDto.setRage(sysAttributeDefs.rage);
+                            attrDto.setVtDataType(sysAttributeDefs.vtDataType);
+                            attrDto.setOther(sysAttributeDefs.other);
+                            attributeDefByName.getAttrs().add(attrDto);
+                            addNode(attrDto, allSysAttr);
+                        }
+                    }
+                }
+            }
+        } catch (PLException e) {
+            e.printStackTrace();
+        }
+    }
+
+    // 鏁版嵁杩囨护
+    private void addImportBtmData(BtmQTExportData qtExportData, List<BizType> ltsNew, List<QTInfo> qTWrapperNew,
+                               Map<String/* 绫诲瀷鍚嶇О */, QTD[]/* 鏌ヨ妯℃澘瀹氫箟 */> norepQTDs) {
+        Map<String/* 绫诲瀷鍚嶇О */, QTD[]/* 鏌ヨ妯℃澘瀹氫箟 */> allQTDs = qtExportData
+                .getAllQTDs();
+        Map<String/* 绫诲瀷鍚嶇О */, BizType/* 绫诲瀷瀵硅薄 */> selectedBtmItems = qtExportData
+                .getSelectedBtmItems();
+        Map<String/* 绫诲瀷鍚嶇О */, String[]/* 绫诲瀷鎵�灞炲睘鎬� */> selectedBtmAttrs = qtExportData
+                .getSelectedBtmAttrs();
+        Map<String/* 鏌ヨ妯℃澘鍚嶇О */, QTInfo/* 鏌ヨ妯℃澘瀵硅薄 */> allSelectedQTs = qtExportData
+                .getAllQTs();
+        if (allQTDs.size() == 0 || allQTDs == null
+                || selectedBtmItems.size() == 0 || selectedBtmItems == null
+                || selectedBtmAttrs.size() == 0 || selectedBtmAttrs == null
+                || allSelectedQTs.size() == 0 || allSelectedQTs == null) {
+            throw new VciBaseException("瀵煎叆鐨勬ā鏉挎暟鎹湁璇�!!!");
+        }
+        Set<Map.Entry<String, QTD[]>> pLActions = allQTDs.entrySet();
+        Set<Map.Entry<String, QTInfo>> pLQts = allSelectedQTs.entrySet();
+        Set<Map.Entry<String, BizType>> btmpLQts = selectedBtmItems.entrySet();
+        for (Map.Entry<String, QTD[]> entry : pLActions) {
+            String string = entry.getKey();
+            QTD[] qtds = entry.getValue();
+            getPLQtIsInDB(string, qtds, norepQTDs);
+        }
+        for (Map.Entry<String, BizType> entry : btmpLQts) {
+            String string = entry.getKey();
+            BizType bizType = entry.getValue();
+            getPLQtBtmItem2(string, bizType, ltsNew);
+        }
+        Map<String/*绫诲瀷鍚嶇О*/, QTD[]/*鏌ヨ妯℃澘瀹氫箟*/> newNorepQTDs = getnewNorepQTDs(norepQTDs,allSelectedQTs);
+        for (Map.Entry<String, QTInfo> entry : pLQts) {
+            String string = entry.getKey();
+            QTInfo qtWrapper = entry.getValue();
+            getPLBtmQtWrapper(string, qtWrapper, ltsNew, qTWrapperNew, newNorepQTDs);
+        }
+
+    }
+
+    /**
+     * 鐢熸垚瀵煎嚭鏍戦�夋嫨浠ュ強瀵煎叆鏍戞樉绀�
+     * @param bizType
+     * @param qts
+     * @param tree
+     */
+    private void addExportTreeNode(BizType bizType/*涓氬姟绫诲瀷*/,QTInfo[] qts/*鏌ヨ妯℃澘瀵硅薄*/,HashMap<String,Object> tree) {
+        List<String> childList = new ArrayList<>();
+        // 娣诲姞鏌ヨ妯℃澘瀵硅薄瀛愯妭鐐�
+        for (QTInfo qtItem : qts) {
+            //澶勭悊瀵煎叆鏃舵棤娉曡繘琛岀被鍨嬪垽鏂�
+            int splitLength = bizType.name.indexOf("銆�");
+            if(splitLength == -1){
+                splitLength = bizType.name.length();
+            }
+            if (qtItem.btmName.equals(bizType.name.substring(0,
+                    splitLength))) {
+                childList.add(qtItem.qtName);
+            }
+        }
+        tree.put("children",childList);
+    }
+
 }

--
Gitblit v1.9.3