From 214bfcb4f9f651a6707a857a5b902aa4984bf32d Mon Sep 17 00:00:00 2001
From: yuxc <yuxc@vci-tech.com>
Date: 星期二, 13 八月 2024 14:38:06 +0800
Subject: [PATCH] 1、对查询模板的的保存普通高级接口
---
Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/dto/QTInfoDTO.java | 33 +-
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsQueryTemplateController.java | 24 +
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsQueryTemplateImpl.java | 628 ++++++++++++++++++++++++++++++++++++++++++++++++++++
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsQuereyTemplateServiceI.java | 8
4 files changed, 677 insertions(+), 16 deletions(-)
diff --git a/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/dto/QTInfoDTO.java b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/dto/QTInfoDTO.java
index fa2f615..094b3db 100644
--- a/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/dto/QTInfoDTO.java
+++ b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/dto/QTInfoDTO.java
@@ -1,16 +1,12 @@
package com.vci.dto;
-import com.alibaba.fastjson.annotation.JSONField;
import com.vci.common.qt.object.QueryTemplate;
-import com.vci.model.BaseLinkModel;
-import com.vci.starter.web.annotation.Column;
import lombok.Data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
/**
* 鏌ヨ妯℃澘鍒楄〃浼犺緭瀵硅薄
@@ -19,13 +15,24 @@
*/
@Data
public class QTInfoDTO {
- public String qtName;
- public String btmName;
- public String creator;
- public long createTime;
- public String createTimeText;
- public short levelFlag;
- public String qtUIText;
- public String qtText;
- public QueryTemplate queryTemplate;
+ //鏌ヨ妯℃澘鍚�
+ private String qtName;
+ //绫诲瀷鍚�
+ private String btmName;
+ //鍒涘缓浜�
+ private String creator;
+ //鍒涘缓鏃堕棿
+ private long createTime;
+ private String createTimeText;
+ //"0:鏅�氭煡璇㈡ā鏉�; 1:楂樼骇鏌ヨ妯℃澘"
+ private short levelFlag;
+ //鏌ヨ妯℃澘鐣岄潰锛岃繖鏄珮绾ф煡璇㈢殑
+ private String qtUIText;
+ //鏌ヨ妯℃澘鍚�
+ private String qtText;
+ //鏌ヨ妯℃澘淇℃伅
+ private QueryTemplate queryTemplate;
+ //鏌ヨ鏉′欢锛屽悗绔繘琛岀浉鍏宠В鏋�
+ private List<HashMap<String,String>> condition;
+ private HashMap<String,Object> tree = new HashMap<>();
}
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsQueryTemplateController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsQueryTemplateController.java
index 8202ace..7eaabfb 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsQueryTemplateController.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsQueryTemplateController.java
@@ -3,6 +3,7 @@
import com.vci.corba.common.PLException;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.qtm.QTD;
+import com.vci.dto.QTInfoDTO;
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsBtmTypeVO;
import com.vci.pagemodel.OsLinkTypeAttributeVO;
@@ -160,7 +161,11 @@
objectBaseResult.setMsg(Arrays.toString(e.messages));
return objectBaseResult;
} catch (DocumentException e) {
- throw new RuntimeException(e);
+ e.printStackTrace();
+ BaseResult objectBaseResult = new BaseResult<>();
+ objectBaseResult.setCode(500);
+ objectBaseResult.setMsg(Arrays.toString(e.getMessage().toCharArray()));
+ return objectBaseResult;
}
}
@@ -180,4 +185,21 @@
return objectBaseResult;
}
}
+
+ /**
+ * 閾炬帴绫诲瀷鏌ヨ妯℃澘淇濆瓨
+ * @param qtInfoDTO 淇濆瓨浼犺緭瀵硅薄
+ * @return 淇濆瓨缁撴灉
+ */
+ @PostMapping("/linkSave")
+ public BaseResult linkSave(@RequestBody QTInfoDTO qtInfoDTO){
+ try {
+ return quereyTemplateServiceI.linkSave(qtInfoDTO);
+ } catch (PLException e) {
+ BaseResult objectBaseResult = new BaseResult<>();
+ objectBaseResult.setCode(Integer.parseInt(e.code));
+ objectBaseResult.setMsg(Arrays.toString(e.messages));
+ return objectBaseResult;
+ }
+ }
}
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsQuereyTemplateServiceI.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsQuereyTemplateServiceI.java
index e071a29..4cd367d 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsQuereyTemplateServiceI.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsQuereyTemplateServiceI.java
@@ -3,6 +3,7 @@
import com.vci.corba.common.PLException;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.qtm.QTD;
+import com.vci.dto.QTInfoDTO;
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeVO;
@@ -75,4 +76,11 @@
* @return 鏌ヨ缁撴灉
*/
BaseResult isExistsQT(String name) throws PLException;
+
+ /**
+ * 閾炬帴绫诲瀷鏌ヨ妯℃澘淇濆瓨
+ * @param qtInfoDTO 淇濆瓨浼犺緭瀵硅薄
+ * @return 淇濆瓨缁撴灉
+ */
+ BaseResult linkSave(QTInfoDTO qtInfoDTO) throws PLException;
}
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..44d39ff 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,13 +1,15 @@
package com.vci.web.service.impl;
+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.corba.common.PLException;
+import com.vci.corba.omd.atm.AttributeDef;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.omd.qtm.QTD;
import com.vci.corba.omd.qtm.QTInfo;
import com.vci.dto.QTInfoDTO;
+import com.vci.omd.objects.OtherInfo;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.util.*;
import com.vci.web.service.*;
@@ -18,6 +20,7 @@
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 java.util.*;
@@ -36,6 +39,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 = "鎴栬��";
/**
* 鏌ヨ妯℃澘鐨勫垪琛�
@@ -156,12 +171,68 @@
qtInfoDTO.setLevelFlag(obj.levelFlag);
// qtInfoDTO.setQtText(obj.qtText);
qtInfoDTO.setQtUIText(obj.qtUIText);
+ if(StringUtils.isNotBlank(obj.qtUIText)){
+ //灏嗙粰瀹氱殑String鏂囨湰瑙f瀽涓篨ML鏂囨。骞惰繑鍥炴柊鍒涘缓鐨刣ocument
+ qtInfoDTO.setTree(analysisXml(obj));
+ }
qtInfoDTO.setQueryTemplate(OQTool.getQTByDoc(DocumentHelper.parseText(obj.qtText), obj.qtName));
qtInfoDTO.setCreateTimeText(DateFormatUtils.format(new Date(obj.createTime), DateUtil.PATTERN_DATETIME));
dtos.add(qtInfoDTO);
}
return BaseResult.dataList(dtos);
}
+
+ /**
+ * 灏嗗鏈嶇鐣岄潰鏄剧ず鐨剎ml杞负hashMap
+ * @param obj 鐣岄潰瀵硅薄
+ * @return
+ * @throws DocumentException
+ */
+ private HashMap<String,Object> analysisXml(QTInfo obj) throws DocumentException {
+ org.dom4j.Document document = DocumentHelper.parseText(obj.qtUIText);
+ if(document == null){
+ return null;
+ }
+ //鑾峰彇鏍硅妭鐐�,鍦ㄤ緥瀛愪腑灏辨槸responsedata鑺傜偣
+ Element root = document.getRootElement();
+ List<HashMap<String,Object>> treeList = new ArrayList<>();
+ 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));
+ }else {
+ childList.add(child.getText().trim());
+ }
+ }
+ treeMap.put("child",childList);
+ return treeMap;
+ }
+
+ /**
+ * 灏嗗瓙鑺傜偣杞负map缁撴瀯
+ * @param element
+ */
+ public Map<String, Object> addDefaultMutableTree(Element element){
+ 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));
+ }else {
+ childList.add(child.getText().trim());
+ }
+ }
+ treeMap.put("child",childList);
+ return treeMap;
+ }
+
/**
* 妫�鏌ユ煡璇㈡ā鏉垮悕瀛楁槸鍚﹀瓨鍦�
* @param name 鏌ヨ妯℃澘鍚嶅瓧
@@ -174,6 +245,559 @@
}
/**
+ * 閾炬帴绫诲瀷鏌ヨ妯℃澘淇濆瓨
+ * @param qtInfoDTO 淇濆瓨浼犺緭瀵硅薄
+ * @return 淇濆瓨缁撴灉
+ */
+ @Override
+ public BaseResult linkSave(QTInfoDTO qtInfoDTO) throws PLException {
+ QueryTemplate qt = getQT(qtInfoDTO);
+ 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("淇濆瓨鏌ヨ妯℃澘澶辫触");
+ }
+ }
+
+ 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();
+
+ }
+ 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(QTInfoDTO qtInfoDTO) throws PLException {
+ QueryTemplate qt = new QueryTemplate();
+ qt.setType(QTConstants.TYPE_LINK);
+ //TODO String qtId =
+ 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());
+ List<String> clauseList = new ArrayList<String>();
+ //TODO 鏌ヨ鍒� 鏄剧ず鍒�
+ clauseList.add("*");
+ qt.setClauseList(clauseList);
+ 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);
+
+// OQTool.parseTreeToDoc(seniorTree);
+ }
+ 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;
+ }
+
+ /**
* 缁勮鏌ヨ妯℃澘
* @return
*/
--
Gitblit v1.9.3