package com.vci.client.common.oq; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import com.vci.corba.query.data.KV; import com.vci.omd.dataType.VTDataType; import com.vci.omd.objects.OtherInfo; import com.vci.client.common.providers.ServiceProvider; import com.vci.common.qt.object.ChildrenInfo; import com.vci.common.qt.object.Condition; import com.vci.common.qt.object.ConditionItem; import com.vci.common.qt.object.Connector; import com.vci.common.qt.object.LeafInfo; import com.vci.common.qt.object.LeafValue; import com.vci.common.qt.object.Operator; import com.vci.common.qt.object.OrderInfo; import com.vci.common.qt.object.PageInfo; import com.vci.common.qt.object.QTConstants; import com.vci.common.qt.object.QueryTemplate; import com.vci.corba.common.VCIError; import com.vci.corba.omd.atm.AttribItem; public class OQTool { public static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); /** * 在根节点上循环增加qtNode * @param doc * @return */ public static Element addDoc(Element rootNode , QueryTemplate qt){ Element qtNode = rootNode.addElement(QTConstants.QUERYTEMPLATE); qtNode.addAttribute(QTConstants.ID, qt.getId()); qtNode.addAttribute(QTConstants.TYPE, qt.getType()); //设置clauseList List clauseList = qt.getClauseList(); String claValue = QTConstants.BLANK; for(int i = 0; i < clauseList.size(); i++){ claValue += clauseList.get(i); if(i < clauseList.size() - 1){ claValue += ","; } } Element claListNode = qtNode.addElement(QTConstants.CLAUSELIST); claListNode.setText(claValue); //设置查询的linkType String linkType = qt.getLinkType(); Element ltNode = qtNode.addElement(QTConstants.LINKTYPE); if(linkType != null){ ltNode.setText(linkType); } //设置查询的btmType String btmType = qt.getBtmType(); Element btmNode = qtNode.addElement(QTConstants.BTMTYPE); if(btmType != null){ btmNode.setText(btmType); } //查询业务对象时,是否查询子类型 if(qt.getType().equals(QTConstants.TYPE_BTM)){ boolean queryChildrenFlag = qt.isQueryChildren(); Element queryChildrenFlagNode = qtNode.addElement(QTConstants.QUERYCHILDRENFLAG); queryChildrenFlagNode.setText(String.valueOf(queryChildrenFlag)); } //是否查询是否包含下一级(链接查询) boolean isQueryIsLeaf = qt.isQueryISLeaf(); Element queryIsLeafNode = qtNode.addElement(QTConstants.QUERYISLEAF); queryIsLeafNode.setText(String.valueOf(isQueryIsLeaf)); //查询时是否加入权限,默认加权限 boolean rightFlag = qt.isRightFlag(); Element rightFlagNode = qtNode.addElement(QTConstants.RIGHTFlag); rightFlagNode.setText(String.valueOf(rightFlag)); //weidy@2018-06-19 增加密级控制 boolean secretFlag = qt.isSecretFlag(); Element secretFlagNode = qtNode.addElement(QTConstants.SECRETFLAG); secretFlagNode.setText(String.valueOf(secretFlag));//end weidy //设置版本版次信息 int version = qt.getVersion(); Element versionNode = qtNode.addElement(QTConstants.VERSION); versionNode.setText(String.valueOf(version)); //设置链接查询的递归层次 int levelRec = qt.getLevel(); Element levelRecNode = qtNode.addElement(QTConstants.LEVELREC); levelRecNode.setText(String.valueOf(levelRec)); //递归返回数据模式 int recReturnMode = qt.getRecReturnMode(); Element recReturnModeNode = qtNode.addElement(QTConstants.RECRETURNMODE); recReturnModeNode.setText(String.valueOf(recReturnMode)); if(qt.getType().equals(QTConstants.TYPE_LINK)){ //设置链接查询方向 String direction = qt.getDirection(); Element directionNode = qtNode.addElement(QTConstants.DIRECTION); directionNode.setText(direction); } //设置PageInfo PageInfo pageInfo = qt.getPageInfo(); if(pageInfo != null){ Element pageInfoNode = qtNode.addElement(QTConstants.PAGEINFO); Element pageNONode = pageInfoNode.addElement(QTConstants.PAGENO); int pageNO = pageInfo.getPageNO(); pageNONode.setText(String.valueOf(pageNO)); Element rowCountNode = pageInfoNode.addElement(QTConstants.ROWCOUNT); int rowCount = pageInfo.getRowCount(); rowCountNode.setText(String.valueOf(rowCount)); } //设置ORDER BY List orderInfoList = qt.getOrderInfoList(); if(orderInfoList != null && orderInfoList.size() > 0){ Element orderInfosNode = qtNode.addElement(QTConstants.ORDERINFOS); for(int i = 0; i < orderInfoList.size(); i++){ OrderInfo o = orderInfoList.get(i); if(o == null){ continue; } Element orderInfoNode = orderInfosNode.addElement(QTConstants.ORDERINFO); String orderField = o.getOrderField(); Element orderFieldNode = orderInfoNode.addElement(QTConstants.ORDERFIELD); orderFieldNode.setText(orderField == null ? QTConstants.BLANK : orderField); String orderMode = o.getOrderMode(); Element orderModeNode = orderInfoNode.addElement(QTConstants.ORDERMODE); orderModeNode.setText(orderMode == null ? QTConstants.BLANK : orderMode); int level = o.getLevel(); Element levelNode = orderInfoNode.addElement(QTConstants.LEVEL); levelNode.setText(String.valueOf(level)); } } //设置Condition Condition condition = qt.getCondition(); if(condition != null){ Element conditionNode = qtNode.addElement(QTConstants.CONDITION); conditionNode.addAttribute(QTConstants.ROOTCINAME, condition.getRootCIName()); Map ciMap = condition.getCIMap(); if(ciMap != null){ for(Iterator i = ciMap.keySet().iterator(); i.hasNext();){ String ciId = i.next(); //设置conditionItem ConditionItem cItem = ciMap.get(ciId); Element cItemNode = conditionNode.addElement(QTConstants.CONDITIONITEM); cItemNode.addAttribute(QTConstants.ID, cItem.getId()); //设置是否是叶子节点 boolean isLeaf = cItem.isLeaf(); Element leafFlagNode = cItemNode.addElement(QTConstants.LEAFFLAG); leafFlagNode.setText(String.valueOf(cItem.isLeaf())); //设置conditionItem的leafData if(isLeaf){ LeafInfo leafInfo = cItem.getLeafInfo(); Element leafInfoNode = cItemNode.addElement(QTConstants.LEAFINFO); Element clauseNode = leafInfoNode.addElement(QTConstants.CLAUSE); clauseNode.setText(leafInfo.getClause()); Element operatorNode = leafInfoNode.addElement(QTConstants.OPERATOR); String operator = leafInfo.getOperator(); /** * 因<, <= 在xml中不能正确存储, 故将查询模板的<, <=存为LT, LTE; * 从xml读取operator为LT, LTE时, 再转换成查询模板的<, <=. * 将>, >= 做相同处理. */ if(operator.equals(Operator.LT)){ operator = Operator.LTTEXT; }else if(operator.equals(Operator.LTE)){ operator = Operator.LTETEXT; }else if(operator.equals(Operator.GT)){ operator = Operator.GTTEXT; }else if(operator.equals(Operator.GTE)){ operator = Operator.GTETEXT; } operatorNode.setText(operator); //设置conditionItem的leafData的LDValue LeafValue lDValue = leafInfo.getValue(); Element valueNode = leafInfoNode.addElement(QTConstants.VALUE); Element ordinaryValueNode = valueNode.addElement(QTConstants.ORDINARYVALUE); String ordinaryValue = lDValue.getOrdinaryValue(); if(ordinaryValue != null){ ordinaryValueNode.setText(ordinaryValue); } Element queryTemplateNode = valueNode.addElement(QTConstants.REFQT); QueryTemplate refQt = lDValue.getQueryTemplate(); if(refQt != null){ addDoc(rootNode, refQt); queryTemplateNode.setText(lDValue.getQueryTemplate().getId()); } }else{ //设置conditionItem的childrenData Element childrenInfoNode = cItemNode.addElement(QTConstants.CHILDRENINFO); ChildrenInfo cdInfo = cItem.getChildrenInfo(); Element leftNode = childrenInfoNode.addElement(QTConstants.LEFT); leftNode.setText(cdInfo.getLeftCIName()); Element rightNode = childrenInfoNode.addElement(QTConstants.RIGHT); rightNode.setText(cdInfo.getRightCIName()); Element conncectorNode = childrenInfoNode.addElement(QTConstants.CONNECTOR); conncectorNode.setText(cdInfo.getConnector()); } } } } return rootNode; } /** * 将查询模板结构转化成查询模板text * @param qt * @return */ public static String getQTTextByQT(QueryTemplate qt){ return qtTOXMl(qt).asXML(); } /** * 将查询模板, 以及其关联的查询模板 * @param qt * @return */ public static Document qtTOXMl(QueryTemplate qt){ Document document = DocumentHelper.createDocument(); Element rootNode = document.addElement(QTConstants.DATA); addDoc(rootNode, qt); return document; } // public static void writeXml(Document document, String xmlPath_){ // try { // Writer fileWriter = new FileWriter(xmlPath_); // OutputFormat format = OutputFormat.createCompactFormat(); // format.setEncoding("utf-8"); // format.setIndent(true); // format.setNewlines(true); // XMLWriter xmlWriter = new XMLWriter(fileWriter, format); // xmlWriter.write(document); // xmlWriter.close(); // } catch (IOException e) { // e.printStackTrace(); // } // } /** * 将查询模板text转化成查询模板结构 * @param qtName : 查询模板name * @param qtText : 查询模板text * @return * @throws DocumentException * @throws VCIError */ public static QueryTemplate getQTByQTText(String qtName, String qtText) throws VCIError, DocumentException{ return getQTByDoc(DocumentHelper.parseText(qtText), qtName); } /** * 根据Document, Document中的模板名获取查询模板 * @throws VCIError */ public static QueryTemplate getQTByDoc(Document doc, String name) throws VCIError{ QueryTemplate qt = new QueryTemplate(); Element rootNode = doc.getRootElement(); List qtNodes = rootNode.elements(QTConstants.QUERYTEMPLATE); for(Iterator i = qtNodes.iterator(); i.hasNext();){ Element qtNode = i.next(); if(qtNode.attributeValue(QTConstants.ID).equals(name)){ //设置Id qt.setId(name); String type = qtNode.attributeValue(QTConstants.TYPE); if(type == null || (!type.equals(QTConstants.TYPE_BTM) && !type.equals(QTConstants.TYPE_LINK))){ throw new VCIError("P0010QT-00011", new String[]{"没有正确设置查询模板的类型"}); }else{ qt.setType(type); } //设置clauseList List clauseList = new ArrayList(); String[] clauses = qtNode.elementText(QTConstants.CLAUSELIST).split(","); for(int k = 0; k < clauses.length; k++){ clauseList.add(clauses[k]); } qt.setClauseList(clauseList); //设置查询的linkType String linkType = qtNode.elementText(QTConstants.LINKTYPE); qt.setLinkType(linkType == null ? QTConstants.BLANK : linkType); //设置查询的btmType String btmType = qtNode.elementText(QTConstants.BTMTYPE); qt.setBtmType(btmType == null ? QTConstants.BLANK : btmType); if(qt.getType().equals(QTConstants.TYPE_BTM)){ //是否查询业务类型的子类型 String queryChildrenFlag = qtNode.elementText(QTConstants.QUERYCHILDRENFLAG); qt.setQueryChildrenFlag(Boolean.valueOf(queryChildrenFlag)); } //是否查询是否包含下一级(链接查询) String queryIsLeaf = qtNode.elementText(QTConstants.QUERYISLEAF); if(queryIsLeaf == null || queryIsLeaf.equals("")){ queryIsLeaf = String.valueOf(Boolean.FALSE); } qt.setQueryISLeaf(Boolean.valueOf(queryIsLeaf)); //查询时是否加入权限,默认加权限 String rightFlag = qtNode.elementText(QTConstants.RIGHTFlag); if(rightFlag == null || rightFlag.equals("")){ rightFlag = String.valueOf(Boolean.TRUE); } qt.setRightFlag(Boolean.valueOf(rightFlag)); //weidy@2018-06-19 增加密级控制 String secretFlag = qtNode.elementText(QTConstants.SECRETFLAG); if(secretFlag == null || secretFlag.equals("")){ secretFlag = String.valueOf(Boolean.TRUE); } qt.setSecretFlag(Boolean.valueOf(secretFlag)); //设置版本版次信息 String versionStr = qtNode.elementText(QTConstants.VERSION); int version = Integer.valueOf(versionStr == null ? "0" : versionStr); qt.setVersion(version); //设置链接查询递归的层次 String levelRecStr = qtNode.elementText(QTConstants.LEVELREC); int levelRec = Integer.valueOf(levelRecStr == null ? "1" : levelRecStr); qt.setLevel(levelRec); //递归返回数据模式 String recReturnModeStr = qtNode.elementText(QTConstants.RECRETURNMODE); int recReturnMode = Integer.valueOf(recReturnModeStr == null ? "1" : recReturnModeStr); qt.setRecReturnMode(recReturnMode); //设置链接查询方向 if(qt.getType().equals(QTConstants.TYPE_LINK)){ String direction = qtNode.elementText(QTConstants.DIRECTION); if(direction == null || (!direction.equals(QTConstants.DIRECTION_POSITIVE) && !direction.equals(QTConstants.DIRECTION_OPPOSITE))){ qt.setDirection(QTConstants.DIRECTION_POSITIVE); }else{ qt.setDirection(direction); } } //设置PageInfo Element pageInfoNode = qtNode.element(QTConstants.PAGEINFO); if(pageInfoNode != null && pageInfoNode.element(QTConstants.PAGENO) != null && pageInfoNode.element(QTConstants.ROWCOUNT) != null){ PageInfo pageInfo = new PageInfo(); String pageNO = pageInfoNode.element(QTConstants.PAGENO).getText(); String rowCount = pageInfoNode.element(QTConstants.ROWCOUNT).getText(); if(pageNO != null && !pageNO.equals("")){ pageInfo.setPageNO(Integer.parseInt(pageNO)); } if(rowCount != null && !rowCount.equals("")){ pageInfo.setRowCount(Integer.parseInt(rowCount)); } qt.setPageInfo(pageInfo); } //设置orderInfoList Element orderInfosNode = qtNode.element(QTConstants.ORDERINFOS); if(orderInfosNode != null && orderInfosNode.elements(QTConstants.ORDERINFO) != null){ List orderInfoList = new ArrayList(); List orderInfoNodes = orderInfosNode.elements(QTConstants.ORDERINFO); for(Iterator ite = orderInfoNodes.iterator(); ite.hasNext();){ Element orderInfoNode = ite.next(); if(orderInfoNode.element(QTConstants.ORDERFIELD) != null && orderInfoNode.element(QTConstants.ORDERMODE) != null && orderInfoNode.element(QTConstants.LEVEL) != null){ OrderInfo obj = new OrderInfo(); obj.setOrderField(orderInfoNode.elementText((QTConstants.ORDERFIELD))); obj.setOrderMode(orderInfoNode.elementText((QTConstants.ORDERMODE))); if(orderInfoNode.elementText((QTConstants.LEVEL)) != null && !orderInfoNode.elementText((QTConstants.LEVEL)).equals("")){ obj.setLevel(Integer.valueOf(orderInfoNode.elementText((QTConstants.LEVEL)))); } orderInfoList.add(obj); } } qt.setOrderInfoList(orderInfoList); } Element conditionNode = qtNode.element(QTConstants.CONDITION); //设置condition if(conditionNode != null && !conditionNode.attributeValue(QTConstants.ROOTCINAME).equals(QTConstants.BLANK)){ Condition condition = new Condition(); qt.setCondition(condition); condition.setRootCIName(conditionNode.attributeValue(QTConstants.ROOTCINAME)); HashMap cIMap = new HashMap(); condition.setCIMap(cIMap); List ciNodes = conditionNode.elements(QTConstants.CONDITIONITEM); for(Iterator ite = ciNodes.iterator(); ite.hasNext();){ Element ciNode = ite.next(); //设置conditionItem ConditionItem conditionItem = new ConditionItem(); conditionItem.setId(ciNode.attributeValue(QTConstants.ID)); conditionItem.setLeafFlag(Boolean.valueOf(ciNode.elementText(QTConstants.LEAFFLAG))); //设置conditionItem的leafInfo Element ldNode = ciNode.element(QTConstants.LEAFINFO); if(ldNode != null && ldNode.element(QTConstants.CLAUSE) != null){ LeafInfo leafData = new LeafInfo(); conditionItem.setLeafInfo(leafData); leafData.setClause(ldNode.elementText(QTConstants.CLAUSE)); String operator = ldNode.elementText(QTConstants.OPERATOR); /** * 因<, <= 在xml中不能正确存储, 故将查询模板的<, <=存为LT, LTE; * 从xml读取operator为LT, LTE时, 再转换成查询模板的<, <=. * 将>, >= 做相同处理. */ if(operator.equals(Operator.LTTEXT)){ operator = Operator.LT; }else if(operator.equals(Operator.LTETEXT)){ operator = Operator.LTE; }else if(operator.equals(Operator.GTTEXT)){ operator = Operator.GT; }else if(operator.equals(Operator.GTETEXT)){ operator = Operator.GTE; } leafData.setOperator(operator); //设置conditionItem的leafData的LDValue Element valueNode = ldNode.element(QTConstants.VALUE); LeafValue ldValue = new LeafValue(); leafData.setValue(ldValue); ldValue.setOrdinaryValue(valueNode.elementText(QTConstants.ORDINARYVALUE)); String qtName = valueNode.elementText(QTConstants.REFQT); if(qtName != null && !qtName.equals(QTConstants.BLANK)){ ldValue.setQueryTemplate(getQTByDoc(doc, qtName)); } } //设置conditionItem的childrenInfo Element cdNode = ciNode.element(QTConstants.CHILDRENINFO); if(cdNode != null){ ChildrenInfo cdData = new ChildrenInfo(); conditionItem.setChildrenInfo(cdData); cdData.setLeftCIName(cdNode.elementText((QTConstants.LEFT))); cdData.setRightCIName(cdNode.elementText((QTConstants.RIGHT))); cdData.setConnector(cdNode.elementText((QTConstants.CONNECTOR))); } cIMap.put(conditionItem.getId(), conditionItem); } } } } return qt; } /** * Array ----> ArrayList * @param array * @return */ // public static List arrayToList(String[] array){ // List list = new ArrayList(); // for(int i = 0; i < array.length; i++){ // list.add(array[i]); // } // return list; // } /** * convert array to String append with ','. * @param array * @return */ // public static String arrayToString(String[] array){ // String str = QTConstants.BLANK; // if(array == null){ // return str; // } // for(int i = 0; i < array.length; i++){ // str += array[i]; // if(i < array.length - 1){ // str += ","; // } // } // return str; // } /** * 检查查询模板是否合法, 合法返回OK, 非法返回详细信息 * 1. 检查查询条件的值数据类型是否正确 * @param qt * @return */ public static String checkQT(QueryTemplate qt){ String ok = "OK"; if(qt == null){ return ok; } Condition condition = qt.getCondition(); if(condition == null){ return ok; } Map ciMap = condition.getCIMap(); if(ciMap == null){ return ok; } //1.检查查询条件的值数据类型是否正确 Iterator iterator = ciMap.keySet().iterator(); while(iterator.hasNext()){ String ciName = iterator.next(); ConditionItem ci = ciMap.get(ciName); if(ci.isLeaf()){ LeafInfo leafInfo = ci.getLeafInfo(); String attName = leafInfo.getClause(); if(attName.contains(".")){ attName = attName.substring(attName.lastIndexOf(".") + 1, attName.length()); } QueryTemplate refQT = leafInfo.getValue().getQueryTemplate(); String value = leafInfo.getValue().getOrdinaryValue(); if(value != null){ //#---#预置参数 if(!value.startsWith("#") || !value.endsWith("#")){ String dataType = getAbItemDataType(attName); boolean flag = checkDataType(dataType, value); if(!flag){ return attName + "数据类型应为: " + dataType; } } }else if(refQT != null){ checkQT(refQT); } } } return ok; } /** * 记录树的结构 * @return */ public static Document parseTreeToDoc(JTree tree){ if(tree == null){ return null; } Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("root"); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); root.setText((String)rootNode.getUserObject()); Enumeration children = rootNode.children(); while(children.hasMoreElements()){ DefaultMutableTreeNode childNode = children.nextElement(); Element child = root.addElement("child"); child.setText((String)childNode.getUserObject()); if(childNode.children().hasMoreElements()){ addElement(child, childNode); } } return doc; } /** * 将树的节点迭代增加到doc * @param element * @param node */ public static void addElement(Element element, DefaultMutableTreeNode node){ Enumeration children = node.children(); while(children.hasMoreElements()){ DefaultMutableTreeNode childNode = children.nextElement(); Element child = element.addElement("child"); child.setText((String)childNode.getUserObject()); if(childNode.children().hasMoreElements()){ addElement(child, childNode); } } } /** * 将doc转化成树 * @param doc * @return */ public static JTree parseDocToTree(Document doc){ if(doc == null){ return null; } Element root = doc.getRootElement(); DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(root.getText().trim()); JTree tree = new JTree(rootNode);; List children = root.elements(); for(Iterator i = children.iterator(); i.hasNext();){ Element child = i.next(); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child.getText().trim()); rootNode.add(childNode); if(child.elements().size() > 0){ addDefaultMutableTreeNode(childNode, child); } } return tree; } /** * 将doc的element迭代增加到treeNode * @param node * @param element */ public static void addDefaultMutableTreeNode(DefaultMutableTreeNode node, Element element){ List children = element.elements(); for(Iterator i = children.iterator(); i.hasNext();){ Element child = i.next(); DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child.getText().trim()); node.add(childNode); if(child.elements().size() > 0){ addDefaultMutableTreeNode(childNode, child); } } } /** * 将查询模板中查询条件的值参数, 替换为map中给定的值 * @param qt * @param map * @throws VCIError */ public static QueryTemplate replaceQTValues(QueryTemplate qt, Map map) throws VCIError{ try{ if(qt == null || map == null){ return qt; } Condition condition = qt.getCondition(); if(condition == null){ return qt; } Map ciMap = condition.getCIMap(); if(ciMap == null){ return qt; } for(Iterator i = ciMap.keySet().iterator(); i.hasNext();){ String ciId = i.next(); ConditionItem ci = ciMap.get(ciId); //当ConditionItem是叶子结点, 并且值参数在map中时, 替换。 if(ci.isLeaf()){ LeafInfo lInfo = ci.getLeafInfo(); String value = lInfo.getValue().getOrdinaryValue(); if(value != null && !value.equals("")){ if(map.containsKey(value)){ String value_ = map.get(value); lInfo.getValue().setOrdinaryValue(value_); //替换自定义查询(非嵌套)in (select oid from ff where #val1# #val2# ) }else if(value.contains("#")){ while(value.contains("#")){ int start = value.indexOf('#'); int end = value.indexOf('#', start + 1); String key = value.substring(start + 1, end); String val = map.get(key); value = value.replace('#' + key + '#', val == null ? "null" : val); } lInfo.getValue().setOrdinaryValue(value); } // add by xchao 2017.12.14 begin // replaceMap 处理增强 // 当查询模板中有类似如: oid in (select oid from platformbtm_xxx where oid not in('${oid}')) // 如果此时replaceMap中只有 key=${oid},value=xxx 时,也能正常解析 // 此时解析出的条件就是 oid in (select oid from platformbtm_xxx where oid not in('xxx')) // value = lInfo.getValue().getOrdinaryValue(); // Iterator> entrys = map.entrySet().iterator(); // while(entrys.hasNext()){ // Entry entry = entrys.next(); // String key = entry.getKey(); // String kval = entry.getValue(); // value = value.replace(key, kval); // } // lInfo.getValue().setOrdinaryValue(value); // add by xchao 2017.12.14 end }else{ QueryTemplate refQT = lInfo.getValue().getQueryTemplate(); QueryTemplate refQT_ = replaceQTValues(refQT, map); lInfo.getValue().setQueryTemplate(refQT_); } } } return qt; }catch(Throwable e){ e.printStackTrace(); throw new VCIError("P0010QT-00008", new String[]{e.getMessage()}); } } /** * 获取属性的数据类型, 属性: 业务类型和链接类型的系统属性, 属性池属性 * @param abUpperName * @return */ public static String getAbItemDataType(String abName){ String dataType = "VTString"; if(abName == null || abName.equals("")){ return dataType; } if(abName.contains(".")){ abName = abName.substring(abName.lastIndexOf(".") + 1); } // String abUpperName = abName.toUpperCase(); // //系统属性 // if(abUpperName.equals("OID") || abUpperName.equals("REVISIONOID") || abUpperName.equals("NAMEOID") || abUpperName.equals("BTMNAME") // || abUpperName.equals("CREATOR") || abUpperName.equals("LASTMODIFIER") || abUpperName.equals("REVISIONRULE") // || abUpperName.equals("VERSIONRULE") || abUpperName.equals("REVISIONVALUE") || abUpperName.equals("VERSIONVALUE") // || abUpperName.equals("LCTID") || abUpperName.equals("LCSTATUS") // || abUpperName.equals("ID") || abUpperName.equals("NAME") || abUpperName.equals("DESCRIPTION") // || abUpperName.equals("OWNER") || abUpperName.equals("CHECKINBY") // || abUpperName.equals("CHECKOUTBY") || abUpperName.equals("COPYFROMVERSION") // || abUpperName.equals("ISLASTR") || abUpperName.equals("ISFIRSTR") // || abUpperName.equals("ISLASTV") || abUpperName.equals("ISFIRSTV") // || abUpperName.equals("F_OID") || abUpperName.equals("F_REVISIONOID") || abUpperName.equals("F_NAMEOID") // || abUpperName.equals("F_BTMNAME") || abUpperName.equals("T_OID") || abUpperName.equals("T_REVISIONOID") // || abUpperName.equals("T_NAMEOID") || abUpperName.equals("T_BTMNAME") || abUpperName.equals("F_OID") // || abUpperName.equals("F_BTWNAME") || abUpperName.equals("T_BTWNAME")){ // dataType = "VTString"; // }else if(abUpperName.equals("REVISIONSEQ") || abUpperName.equals("VERSIONSEQ")){ // dataType = "VTInteger"; // }else if(abUpperName.equals("CREATETIME") || abUpperName.equals("LASTMODIFYTIME") // || abUpperName.equals("TS") || abUpperName.equals("CHECKINTIME") || abUpperName.equals("CHECKOUTTIME")){ // dataType = "VTDateTime"; // //属性池中属性 // }else{ // dataType = ApProvider.getInstance().getAbItemDataType(abName); // } try { dataType = ServiceProvider.getOMDService().getAttributeService().getAttribItemDataType(abName); } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } return dataType; } /** * 把key, Value 封装成查询模板的Condition * @param map * @return */ public static Condition getCondition(Map map){ Condition cond = new Condition(); Map ciMap = new HashMap(); Iterator ite = map.keySet().iterator(); List list = new ArrayList(); int idFlag = 1; while(ite.hasNext()){ String key = ite.next(); String value = map.get(key); if(value == null || value.equals("")){ continue; } List list_ = getCIList(key, value, idFlag); if(list.size() > 0){ ConditionItem lCI = list.get(list.size() - 1); ConditionItem rCI = list_.get(list_.size() - 1); list.addAll(list_); idFlag = idFlag + list_.size(); ConditionItem pCI = new ConditionItem(); pCI.setId("ci" + idFlag); pCI.setLeafFlag(false); pCI.setLeafInfo(null); ChildrenInfo cInfo = new ChildrenInfo(); cInfo.setLeftCIName(lCI.getId()); cInfo.setConnector(Connector.AND); cInfo.setRightCIName(rCI.getId()); pCI.setChildrenInfo(cInfo); list.add(pCI); idFlag++; }else{ list.addAll(list_); idFlag = idFlag + list_.size(); } } for(int i = 0; i < list.size(); i++){ ConditionItem ci = list.get(i); ciMap.put(ci.getId(), ci); } if(list.size() > 0){ ConditionItem rootCI = list.get(list.size() - 1); cond.setRootCIName(rootCI.getId()); cond.setCIMap(ciMap); return cond; }else{ return null; } } /** * 根据value中包含的AND/OR解析出conditionItem组 * @param key * @param value * @param idFlag * @return */ public static List getCIList(String key, String value, int idFlag){ List list = new ArrayList(); String connector = Connector.AND; while(value.length() > 0){ int indexAnd = value.indexOf("\\AND"); int indexOr = value.indexOf("\\OR"); ConditionItem ci = new ConditionItem(); if(indexAnd > 0 || indexOr > 0){ String nextConnector = Connector.AND; String value_ = null; if((indexAnd > 0 && indexAnd < indexOr) || indexOr < 0){ value_ = value.substring(0, indexAnd); nextConnector = Connector.AND; value = value.substring(indexAnd + 4); }else{ value_ = value.substring(0, indexOr); nextConnector = Connector.OR; value = value.substring(indexOr + 3); } ci = getConditionItem(key, value_, idFlag); if(list.size() > 0){ ConditionItem lCI = list.get(list.size() - 1); list.add(ci); idFlag++; ConditionItem pCI = new ConditionItem(); pCI.setId("ci" + idFlag); pCI.setLeafFlag(false); pCI.setLeafInfo(null); ChildrenInfo cInfo = new ChildrenInfo(); cInfo.setLeftCIName(lCI.getId()); cInfo.setConnector(connector); cInfo.setRightCIName(ci.getId()); pCI.setChildrenInfo(cInfo); list.add(pCI); idFlag++; }else{ list.add(ci); idFlag++; } connector = nextConnector; }else{ ci = getConditionItem(key, value, idFlag); if(list.size() > 0){ ConditionItem lCI = list.get(list.size() - 1); list.add(ci); idFlag++; ConditionItem pCI = new ConditionItem(); pCI.setId("ci" + idFlag); pCI.setLeafFlag(false); pCI.setLeafInfo(null); ChildrenInfo cInfo = new ChildrenInfo(); cInfo.setLeftCIName(lCI.getId()); cInfo.setConnector(connector); cInfo.setRightCIName(ci.getId()); pCI.setChildrenInfo(cInfo); list.add(pCI); idFlag++; }else{ list.add(ci); idFlag++; } value = ""; } } return list; } /** * 将原子value(不包含and/or)解析成单个ConditionItem * @param key * @param value * @param idFlag * @return */ private static ConditionItem getConditionItem(String key, String value, int idFlag){ ConditionItem ci = new ConditionItem(); ci.setId("ci" + idFlag); ci.setChildrenInfo(null); ci.setLeafFlag(true); LeafInfo lInfo = new LeafInfo(); String operator = null; if(value.startsWith("\\NOTLIKE")){ operator = Operator.NOTLIKE; value = value.substring(8); }else if (value.startsWith(Operator.STAR) || value.endsWith(Operator.STAR)) { operator = Operator.LIKE; }else if (value.startsWith(Operator.UNEQUAL)) { operator = Operator.UNEQUAL; value = value.substring(2); }else if(value.startsWith(Operator.GT)){ //add by caill 2016.4.7 为操作添加“大于”的判断 并在此判断中添加“大于等于”的判断 operator = Operator.GT; if(value.startsWith(Operator.GTE)){ operator = Operator.GTE; value = value.substring(2); }else{ value = value.substring(1); } }else if(value.startsWith(Operator.LT)){ //add by caill 2016.4.7 为操作添加“小于”的判断 并在此判断中添加“小于等于”的判断 operator = Operator.LT; if(value.startsWith(Operator.LTE)){ operator = Operator.LTE; value = value.substring(2); }else{ value = value.substring(1); } }/*else if(value.startsWith(Operator.LTE)){ operator = Operator.LTE; value = value.substring(2); }else if(value.startsWith(Operator.GTE)){ operator = Operator.GTE; value = value.substring(2); }*/else if(value.startsWith("\\IN")){ operator = Operator.IN; value = value.substring(3); }else if(value.startsWith("\\NOTIN")){ operator = Operator.NOTIN; value = value.substring(6); }else { operator = Operator.EQUAL; } lInfo.setOperator(operator); if(key.toUpperCase().contains("T_OID.") || key.toUpperCase().contains("F_OID.")){ //去掉T_OID.或者F_OID. String clause_ = key.substring(6); //属性为参照属性 if(clause_.contains(".")){ int fpIndex = clause_.indexOf("."); String refAbName = key.substring(0, fpIndex + 6); key = key.substring(fpIndex + 6 + 1); lInfo.setClause(refAbName); //去掉T_OID.或者F_OID. refAbName = refAbName.substring(6); lInfo.setOperator(Operator.IN); QueryTemplate qt = getRefQT(refAbName, key, operator, value); LeafValue lValue = new LeafValue(); lValue.setQueryTemplate(qt); lInfo.setValue(lValue); //属性为非参照属性 }else{ lInfo.setClause(key); LeafValue lValue = new LeafValue(); lInfo.setValue(lValue); lValue.setOrdinaryValue(value); } }else{ //属性为参照属性 if(key.contains(".")){ int fpIndex = key.indexOf("."); String refAbName = key.substring(0, fpIndex); key = key.substring(fpIndex + 1); lInfo.setClause(refAbName); lInfo.setOperator(Operator.IN); QueryTemplate qt = getRefQT(refAbName, key, operator, value); LeafValue lValue = new LeafValue(); lValue.setQueryTemplate(qt); lInfo.setValue(lValue); //属性为非参照属性 }else{ lInfo.setClause(key); LeafValue lValue = new LeafValue(); lInfo.setValue(lValue); lValue.setOrdinaryValue(value); } } ci.setLeafInfo(lInfo); return ci; } /** * 获取参照的查询模板 * @param refAbName: 参照属性名 * @param clause: 属性参照的业务类型中的属性 * @param operator * @param ordinaryValue * @return */ private static QueryTemplate getRefQT(String refAbName, String clause, String operator, String ordinaryValue) { QueryTemplate qt = new QueryTemplate(); try { List clauseList = new ArrayList(); clauseList.add("OID"); qt.setClauseList(clauseList); AttribItem refAb; refAb = ServiceProvider.getOMDService().getAttributeService().getAttribItemByName(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 ciMap = new HashMap(); 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); } catch (VCIError e) { // TODO Auto-generated catch block e.printStackTrace(); } return qt; } /** * * @param direction * @param oid * @param btmType * @param map * @return */ public static Condition getConditionForLink(String direction, String oid, String btmType, Map map){ Condition cond = new Condition(); cond.setRootCIName("ci3"); Map ciMap = new HashMap(); if(direction.equals(QTConstants.DIRECTION_POSITIVE)){ ConditionItem ci1 = new ConditionItem(); ci1.setId("ci1"); ci1.setChildrenInfo(null); ci1.setLeafFlag(true); LeafInfo lInfo = new LeafInfo(); lInfo.setClause("f_oid"); lInfo.setOperator(Operator.EQUAL); LeafValue lValue = new LeafValue(); lValue.setOrdinaryValue(oid); lInfo.setValue(lValue); ci1.setLeafInfo(lInfo); ciMap.put(ci1.getId(), ci1); ConditionItem ci2 = new ConditionItem(); ci2.setId("ci2"); ci2.setChildrenInfo(null); ci2.setLeafFlag(true); LeafInfo lInfo2 = new LeafInfo(); lInfo2.setClause("t_nameOId"); lInfo2.setOperator(Operator.IN); LeafValue lValue2 = new LeafValue(); //参照查询模板 QueryTemplate refQT = new QueryTemplate(); lValue2.setQueryTemplate(refQT); refQT.setId("refQT"); refQT.setBtmType(btmType); refQT.setType(QTConstants.TYPE_BTM); List list = new ArrayList(); list.add("nameOId"); refQT.setClauseList(list); Condition cond2 = getCondition(map); refQT.setCondition(cond2); lInfo2.setValue(lValue2); ci2.setLeafInfo(lInfo2); ciMap.put(ci2.getId(), ci2); ConditionItem ci3 = new ConditionItem(); ci3.setId("ci3"); ci3.setLeafFlag(false); ci3.setLeafInfo(null); ChildrenInfo cInfo = new ChildrenInfo(); ci3.setChildrenInfo(cInfo); cInfo.setLeftCIName(ci1.getId()); cInfo.setConnector(Connector.AND); cInfo.setRightCIName(ci2.getId()); ciMap.put(ci3.getId(), ci3); }else if(direction.equals(QTConstants.DIRECTION_OPPOSITE)){ ConditionItem ci1 = new ConditionItem(); ci1.setId("ci1"); ci1.setChildrenInfo(null); ci1.setLeafFlag(true); LeafInfo lInfo = new LeafInfo(); lInfo.setClause("t_oid"); lInfo.setOperator(Operator.EQUAL); LeafValue lValue = new LeafValue(); lValue.setOrdinaryValue(oid); lInfo.setValue(lValue); ci1.setLeafInfo(lInfo); ciMap.put(ci1.getId(), ci1); ConditionItem ci2 = new ConditionItem(); ci2.setId("ci2"); ci2.setChildrenInfo(null); ci2.setLeafFlag(true); LeafInfo lInfo2 = new LeafInfo(); lInfo2.setClause("f_oid"); lInfo2.setOperator(Operator.IN); LeafValue lValue2 = new LeafValue(); //参照查询模板 QueryTemplate refQT = new QueryTemplate(); lValue2.setQueryTemplate(refQT); refQT.setId("refQT"); refQT.setBtmType(btmType); refQT.setType(QTConstants.TYPE_BTM); List list = new ArrayList(); list.add("oid"); refQT.setClauseList(list); Condition cond2 = getCondition(map); refQT.setCondition(cond2); lInfo2.setValue(lValue2); ci2.setLeafInfo(lInfo2); ciMap.put(ci2.getId(), ci2); ConditionItem ci3 = new ConditionItem(); ci3.setId("ci3"); ci3.setLeafFlag(false); ci3.setLeafInfo(null); ChildrenInfo cInfo = new ChildrenInfo(); ci3.setChildrenInfo(cInfo); cInfo.setLeftCIName(ci1.getId()); cInfo.setConnector(Connector.AND); cInfo.setRightCIName(ci2.getId()); ciMap.put(ci3.getId(), ci3); } cond.setCIMap(ciMap); return cond; } /** * 合并Condition * 1.将con2中conditionItem的ID和非叶子结点的左右id都加上con1.size * 2.con1->con<-con2 * @param con1 * @param con2 * @param AND/OR */ public static Condition mergeCondition(Condition con1, Condition con2, String connector){ if(connector == null){ return null; } if(!connector.equalsIgnoreCase(Connector.AND) && !connector.equalsIgnoreCase(Connector.OR)){ return null; } if(con1 == null || con1.getCIMap() == null || con1.getCIMap().keySet().size() == 0){ return con2; } if(con2 == null || con2.getCIMap() == null || con2.getCIMap().keySet().size() == 0){ return con1; } Condition con = new Condition(); Map ciMap = con1.getCIMap(); int size = ciMap.keySet().size(); Map ciMap2 = con2.getCIMap(); for(Iterator i = ciMap2.keySet().iterator(); i.hasNext();){ String ciId = i.next(); ConditionItem ci = ciMap2.get(ciId); int id = Integer.valueOf(ciId.substring(2)) + size; ci.setId("ci" + id); if(!ci.isLeaf()){ ChildrenInfo cInfo = ci.getChildrenInfo(); String lCI = cInfo.getLeftCIName(); id = Integer.valueOf(lCI.substring(2)) + size; cInfo.setLeftCIName("ci" + id); String rCI = cInfo.getRightCIName(); id = Integer.valueOf(rCI.substring(2)) + size; cInfo.setRightCIName("ci" + id); } ciMap.put(ci.getId(), ci); } ConditionItem rootCI = new ConditionItem(); rootCI.setId("ci" + (ciMap.keySet().size() + 1)); rootCI.setLeafFlag(false); ChildrenInfo cInfo_ = new ChildrenInfo(); cInfo_.setLeftCIName(con1.getRootCIName()); String rightCI = con2.getRootCIName(); int id_ = Integer.valueOf(rightCI.substring(2)) + size; cInfo_.setRightCIName("ci" + id_); cInfo_.setConnector(connector); rootCI.setChildrenInfo(cInfo_); ciMap.put(rootCI.getId(), rootCI); con.setCIMap(ciMap); con.setRootCIName(rootCI.getId()); return con; } /** * 为每一个子节点的ConditinItem中LeafInfo的Clause加上str前缀 * F_OID./T_OID. * @param con * @param str * @return */ public static Condition conditionWrapper(Condition con, String str){ Map ciMap = con.getCIMap(); for(Iterator i = ciMap.keySet().iterator(); i.hasNext();){ String ciId = i.next(); ConditionItem ci = ciMap.get(ciId); if(ci.isLeaf()){ LeafInfo lInfo = ci.getLeafInfo(); String clause = str + lInfo.getClause(); lInfo.setClause(clause); } } return con; } /** * 克隆list * Object cloneable * @param list * @return */ public static List cloneOrderInfoList(List list){ List clone = new ArrayList(); if(list == null){ return clone; } for(OrderInfo o : list){ clone.add(o.clone()); } return clone; } // /** // * 获取链接类型TO端业务类型视图名 // * @param ltName // * @return // */ // public static String getToViewName(String ltName){ // return ltName + _TV; // } // // /** // * 获取链接类型From端业务类型视图名 // * @param ltName // * @return // */ // public static String getFromViewName(String ltName){ // return ltName + _FV; // } // // /** // * 获取业务类型视图名 // * @param ltName // * @return // */ // public static String getBtViewName(String btName){ // return btName + _V; // } /** * 获取创建链接类型TO端业务类型视图的sql * @param ltName * @return */ // public static String getBTSViewSql(String[] btNames, String viewName){ // if(btNames.length < 1){ // return ""; // } // StringBuilder stb = new StringBuilder("create or replace view "); // try { // Set allAttrName = getUserAttrNameSet(btNames); // Map sqlMap = getBTSqlMap(allAttrName, btNames); // stb.append(viewName); // stb.append(" as "); // for(String btName : sqlMap.keySet()){ // stb.append(sqlMap.get(btName)); // stb.append(" union all "); // } // } catch (Throwable e) { // e.printStackTrace(); // } // return stb.substring(0, stb.lastIndexOf(" union all ")); // } /** * 获取业务类型属性总集合 * @param btNames * @return */ private static Set getUserAttrNameSet(String[] btNames){ Set set = new LinkedHashSet(); try{ for(String btName : btNames){ String[] abNames = ServiceProvider.getOMDService().getBTMService().getBtmApNameArray(btName); for(String abName : abNames){ set.add(abName); } } } catch (Throwable e) { e.printStackTrace(); } return set; } /** * 获取各个业务类型查询属性总集合的sql * 当业务业务类型中不包含某个属性attrA时, '' as attrA * @param allAttrName * @param btNames * @return */ // private static Map getBTSqlMap(Set allAttrName, // String[] btNames) { // //记录业务类型和与其对应的属性列表 // Map> btAttrMap = new HashMap>(); // //记录业务类型和与其对应的查询sql // Map btSqlMap = new HashMap(); // //modify by weidy@2021-11-15,在沈飞的发现一个现象是,拆分了的视图可能某个字段全部为null,这样多个视图链接到一起的时候,会出现类型不一致问题 // String[] sysAbItems = OmdTools.getBtSysANames(); // String querySysAttrSql = "select " + arrayToString(sysAbItems); // for(String btName : btNames){ // try { // String[] abNames; // abNames = ServiceProvider.getOMDService().getBTMService().getBtmApNameArray(btName); // btAttrMap.put(btName, arrayToList(abNames)); // btSqlMap.put(btName, new StringBuilder(querySysAttrSql)); // } catch (VCIError e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // // } // // Map mapAttrNull = new HashMap(); // // for(String attrName : allAttrName){ // for(String btName : btNames){ // btSqlMap.get(btName).append(","); // if(btAttrMap.get(btName).contains(attrName)){ // btSqlMap.get(btName).append(attrName); // }else{ // String attrNull = ""; // // if (mapAttrNull.containsKey(attrName)) { // attrNull = mapAttrNull.get(attrName); // } else { // attrNull = CreateAttrNull(attrName); // mapAttrNull.put(attrName, attrNull); // } // btSqlMap.get(btName).append(attrNull); // } // } // } // // for(String btName : btNames){ // btSqlMap.get(btName).append(" from " + OmdTools.getBTTableName(btName)); // } // return btSqlMap; // } /** * 创建null AS 指定类型属性 * @param attrName * @return */ // private static String CreateAttrNull(String attrName) { // try { // // AttPoolServicePrx attrService = ServiceProvider.getOMDService().getAttributeService(); // // AttribItem ai = attrService.getAttribItemByName(attrName); // // String vtType = ai.vtDataType; // int length = 50; // String lengthStr = getOtherValueByType(ai.other, "length"); // // if ((lengthStr != null) && (!lengthStr.equals(""))) { // length = Integer.valueOf(lengthStr).intValue(); // } // // String sqlType = ""; // // if (VTDataType.VTSTRING.equalsIgnoreCase(vtType)) { // sqlType = "VARCHAR2(" + length + ")"; // } else if (VTDataType.VTLONG.equalsIgnoreCase(vtType) || VTDataType.VTINTEGER.equalsIgnoreCase(vtType)) { // sqlType = "NUMBER"; // } else if (VTDataType.VTDOUBLE.equalsIgnoreCase(vtType)) { // sqlType = "NUMBER"; // } else if (VTDataType.VTBOOLEAN.equalsIgnoreCase(vtType)) { // sqlType = "VARCHAR2(8)"; // } else if (VTDataType.VTIMAGE.equalsIgnoreCase(vtType)) { // sqlType = "VARCHAR2(255)"; // } else if (VTDataType.VTDATE.equalsIgnoreCase(vtType)) { // sqlType = "DATE"; // } else if (VTDataType.VTDATETIME.equalsIgnoreCase(vtType) || VTDataType.VTTIME.equalsIgnoreCase(vtType)) { // sqlType = "TIMESTAMP"; // } else if (VTDataType.VTFILEPATH.equalsIgnoreCase(vtType) || VTDataType.VTNOTE.equalsIgnoreCase(vtType)) { // sqlType = "VARCHAR2(255)"; // } else if (VTDataType.VTCLOB.equalsIgnoreCase(vtType)) { // sqlType = "CLOB"; // } else { // sqlType = "VARCHAR2(" + length + ")"; // } // // // btSqlMap.get(btName).append("cast(null as " + sqlType + " ) as " + attrName); // String attrNull = "cast(null as " + sqlType + " ) as " + attrName; // // return attrNull; // } catch (Throwable e) { // e.printStackTrace(); // } // // return ""; // } public static String getOtherValueByType(String other, String type) { String[] otherArray = other.split(";"); for (int i = 0; i < otherArray.length; i++) { String otherValue = otherArray[i]; if (otherValue.contains(type)) { return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length()); } } return null; } /** * 视图cols * viewName.col as col2 * @param ltName * @return */ // public static List getViewColsWithAlias(String[] btNames, String viewName) { // List cols = new ArrayList(); // String[] sysAbItems = OmdTools.getBtSysANames(); // for(String sysAbItem : sysAbItems){ // cols.add(viewName + "." + sysAbItem + " AS " + sysAbItem + "2"); // } // Set userAttrNameSet = getUserAttrNameSet(btNames); // for(String userAttrName : userAttrNameSet){ // cols.add(viewName + "." + userAttrName + " AS " + userAttrName + "2"); // } // return cols; // } // /** * 获取查询条件的 值 * @param con * @param key * @return */ // public static String getConditionItemVlaue(Condition con, String key){ // if(con == null){ // return null; // } // Map ciMap = con.getCIMap(); // for(String ciId : ciMap.keySet()){ // ConditionItem ci = ciMap.get(ciId); // if(ci.isLeaf()){ // LeafInfo leafInfo = ci.getLeafInfo(); // String clause = leafInfo.getClause(); // if(clause.equalsIgnoreCase(key)){ // return leafInfo.getValue().getOrdinaryValue(); // } // } // } // return null; // } /** * 根据leafInfo获取属性名和条件值, * 当有参照时, 加上参照路径 * @param leafInfo * @return */ public static Map getClauseAndValue(LeafInfo leafInfo){ Map map = new HashMap(); String attName = leafInfo.getClause(); QueryTemplate refQt = leafInfo.getValue().getQueryTemplate(); //add by zhangweiwei 2014/12/09 start String value = null; if(refQt != null){ List clauselist = refQt.getClauseList(); String attr = clauselist.get(0); value = refQt.getId()+";"+attr; }else{ value = leafInfo.getValue().getOrdinaryValue(); } map.put("value", value); if(refQt != null&&refQt.getId().startsWith("qt_")){ while(refQt != null){ Condition cond = refQt.getCondition(); if(cond != null){ ConditionItem ci = cond.getCIMap().get(cond.getRootCIName()); leafInfo = ci.getLeafInfo(); attName += "." + leafInfo.getClause(); refQt = leafInfo.getValue().getQueryTemplate(); }else{ break; } } } map.put("clause", attName); //add by zhangweiwei 2014/12/09 end return map; } /** * 为提高使用效率, 将KV[][]转化成List * @param array2D * @return */ public static List> parseKVArray2D(KV[][] array2D){ List> list = new ArrayList>(array2D.length); for(KV[] array : array2D){ Map map = new HashMap(array.length); for(KV kv : array){ map.put(kv.key, kv.value); } list.add(map); } return list; } /** * 检查属性类型与属性值是否匹配 * @param vtType * @param value * @return */ private static boolean checkDataType(String vtType, String value){ if(vtType.equals(VTDataType.VTSTRING)){ try{ String.valueOf(value); }catch(Exception e){ return false; } }else if(vtType.equals(VTDataType.VTINTEGER)){ try{ Integer.valueOf(value); }catch(Exception e){ return false; } }else if(vtType.equals(VTDataType.VTLONG)){ try{ Long.valueOf(value); }catch(Exception e){ return false; } }else if(vtType.equals(VTDataType.VTDOUBLE)){ try{ Double.valueOf(value); }catch(Exception e){ return false; } } return true; } }