From 24fa2e63f7c155c87457980e6c656f3891132a47 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期三, 14 八月 2024 16:28:26 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsQueryTemplateImpl.java | 779 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 746 insertions(+), 33 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 50b8418..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,50 +1,29 @@ package com.vci.web.service.impl; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.ZipUtil; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.vci.constant.FrameWorkLangCodeConstant; +import com.alibaba.fastjson.JSONObject; +import com.vci.client.common.oq.OQTool; +import com.vci.common.qt.object.*; import com.vci.corba.common.PLException; import com.vci.corba.omd.atm.AttributeDef; -import com.vci.corba.omd.btm.BizType; -import com.vci.corba.omd.data.BusinessObject; -import com.vci.corba.omd.ltm.LinkType; +import com.vci.corba.omd.data.LinkObject; import com.vci.corba.omd.qtm.QTD; -import com.vci.model.OsLinkTypeDO; -import com.vci.omd.utils.ObjectTool; -import com.vci.pagemodel.*; -import com.vci.po.OsLinkTypePO; -import com.vci.starter.poi.bo.ReadExcelOption; -import com.vci.starter.poi.bo.WriteExcelData; -import com.vci.starter.poi.bo.WriteExcelOption; -import com.vci.starter.poi.constant.ExcelLangCodeConstant; -import com.vci.starter.poi.util.ExcelUtil; -import com.vci.starter.web.annotation.log.VciUnLog; -import com.vci.starter.web.enumpck.VciFieldTypeEnum; -import com.vci.starter.web.exception.VciBaseException; -import com.vci.starter.web.pagemodel.BaseQueryObject; +import com.vci.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.pagemodel.DataGrid; import com.vci.starter.web.util.*; import com.vci.web.service.*; -import com.vci.web.util.Func; +import com.vci.web.util.DateUtil; import com.vci.web.util.PlatformClientUtil; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +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.context.annotation.Lazy; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; -import org.springframework.web.multipart.MultipartFile; - -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; import java.util.*; -import java.util.stream.Collectors; /** * 鏌ヨ妯℃澘鏈嶅姟 @@ -60,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 = "鎴栬��"; /** * 鏌ヨ妯℃澘鐨勫垪琛� @@ -138,6 +129,728 @@ return BaseResult.fail("鍒犻櫎鏌ヨ妯℃澘澶辫触"); } } + /** + * + * @param dataMap 浼犺緭鐨勬暟鎹璞★細 + * linkTypeName 閾炬帴绫诲瀷銆� + * rdPositive 鏂瑰悜锛宼rue姝e悜锛宖alse鍙嶅悜 + * btmName 涓氬姟绫诲瀷鍚嶇О + * combRelaType 涓氬姟绫诲瀷閫夋嫨鍊� + * versionValue 鐗堟湰鐝鍊� + * isQueryIsLeaf 鏄惁閫夋嫨涓嬬骇 + * level 瀛愯妭鐐瑰眰鏁� + * @return 鏌ヨ缁撴灉 + */ + @Override + public BaseResult getCriteria(HashMap<String,Object> dataMap) throws PLException { + QueryTemplate qt = getQT(dataMap); + String checkInfo = OQTool.checkQT(qt); + if(!checkInfo.equals("OK")){ + throw new PLException("500", new String[]{checkInfo}); + } + qt.setId("qt1"); + LinkObject[] result = platformClientUtil.getQueryService().findLTObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML()); + return BaseResult.dataList(Arrays.asList(result)); + } + + /** + * 鏌ヨ妯℃澘鍒楄〃 + * @param btName 绫诲瀷鍚嶇О + * @return 鏌ヨ缁撴灉 + */ + @Override + public BaseResult getObjTypeQTs(String btName) throws PLException, DocumentException { + VciBaseUtil.alertNotNull(btName,"绫诲瀷鍚�"); + QTInfo[] objTypeQTs = platformClientUtil.getQTDService().getObjTypeQTs(btName); + List<QTInfoDTO> dtos = new ArrayList<>(); + 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.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 鏌ヨ妯℃澘鍚嶅瓧 + * @return 鏌ヨ缁撴灉 + */ + @Override + public BaseResult isExistsQT(String name) throws PLException { + VciBaseUtil.alertNotNull(name,"璇㈡ā鏉垮悕"); + return BaseResult.success(platformClientUtil.getQTDService().isExistsQT(name)); + } + + /** + * 閾炬帴绫诲瀷鏌ヨ妯℃澘淇濆瓨 + * @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 + */ + public QueryTemplate getQT(HashMap<String,Object> dataMap){ + 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("*"); + } + 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)); + return qt; + } + + + /** + * 杩斿洖鏌ヨ鐨勭増鏈� + * @return + */ + public int getVersion(String versionValue){ + int version = 0; + if(versionValue.equals("褰撳墠鐗堟湰褰撳墠鐗堟")){ + version = 1; + }else if(versionValue.equals("褰撳墠鐗堟湰鏈�鏂扮増娆�")){ + version = 2; + }else if(versionValue.equals("鏈�鏂扮増鏈渶鏂扮増娆�")){ + version = 3; + }else if(versionValue.equals("褰撳墠鐗堟")){ + version = 4; + }else if(versionValue.equals("褰撳墠鐗堟湰")){ + version = 5; + }else if(versionValue.equals("褰撳墠鍛藉悕瀵硅薄")){ + version = 6; + }else if(versionValue.equals("宸插彂甯冪殑鏈�鏂扮増鏈�")){ + version = 7; + } + return version; + } + /** * 鏍¢獙鍙傛暟 -- Gitblit v1.9.3