package com.vci.common.qt.object;
|
|
import java.util.Iterator;
|
import java.util.Map;
|
|
public class Condition {
|
private String rootCIName;
|
private Map<String, ConditionItem> ciMap;
|
|
public String getRootCIName() {
|
return rootCIName;
|
}
|
public void setRootCIName(String rootCIName) {
|
this.rootCIName = rootCIName;
|
}
|
|
/**
|
* 根据CIMap解析出根节点
|
* @param ciMap
|
* @return
|
*/
|
public String getRootCINameByCIMap(Map<String, ConditionItem> ciMap){
|
String rootCIName = "";
|
if(ciMap != null){
|
for(Iterator<String> i = ciMap.keySet().iterator(); i.hasNext();){
|
String ciName = i.next();
|
if(rootCIName.equals("")){
|
rootCIName = ciName;
|
}else{
|
int rootInt = Integer.valueOf(rootCIName.substring(2));
|
int ciInt = Integer.valueOf(ciName.substring(2));
|
if(ciInt > rootInt){
|
rootCIName = ciName;
|
}
|
}
|
}
|
}
|
return rootCIName;
|
}
|
public Map<String, ConditionItem> getCIMap() {
|
return ciMap;
|
}
|
public void setCIMap(Map<String, ConditionItem> cIMap) {
|
this.ciMap = cIMap;
|
}
|
|
/**
|
* 将查询条件解析成sql
|
* @param qt
|
* @param addGrandRightFlag 是否加上权限的条件, 默认应为true
|
* 当权限开关开启(right.switch=on), 并且addGrandRightFlag=true时才会加权限条件
|
* @return
|
*/
|
// public String getSql(QueryTemplate qt, boolean addGrandRightFlag){
|
// StringBuilder strb = new StringBuilder("");
|
// ConditionItem rootCI = ciMap.get(this.getRootCIName());
|
// if(rootCI.isLeaf()){
|
// strb.append(rootCI.getSql(qt, addGrandRightFlag));
|
// }else{
|
// ConditionItem root = rootCI;
|
// ConditionItem left = ciMap.get(root.getChildrenInfo().getLeftCIName());
|
// ConditionItem right = ciMap.get(root.getChildrenInfo().getRightCIName());
|
// String treeSql = parseTree(left, root, right, qt, addGrandRightFlag);
|
// strb.append(treeSql);
|
// }
|
//
|
// return strb.toString();
|
// }
|
|
/**
|
* 将查询条件中的link条件解析成sql
|
* @param qt
|
* @return
|
*/
|
// public String getLinkConditionSql(QueryTemplate qt, boolean addGrandRightFlag){
|
// StringBuilder stb = new StringBuilder("");
|
// ConditionItem rootCI = ciMap.get(this.getRootCIName());
|
// if(rootCI.isLeaf()){
|
// if(!isBtmContidionItem(rootCI)){
|
// return rootCI.getSql(qt, addGrandRightFlag);
|
// }else{
|
// return stb.toString();
|
// }
|
// }else{
|
// ConditionItem root = rootCI;
|
// ConditionItem left = ciMap.get(root.getChildrenInfo().getLeftCIName());
|
// ConditionItem right = ciMap.get(root.getChildrenInfo().getRightCIName());
|
// if(!isBtmContidionItem(left) && !isBtmContidionItem(right)){
|
// String treeSql = parseTree(left, root, right, qt, addGrandRightFlag);
|
// stb.append(treeSql);
|
// }else if(!isBtmContidionItem(left)){
|
// String rootCIName = this.getRootCIName();
|
// this.setRootCIName(left.getId());
|
// String sql = getSql(qt, addGrandRightFlag);
|
// this.setRootCIName(rootCIName);
|
// return sql;
|
// }else if(!isBtmContidionItem(right)){
|
// String rootCIName = this.getRootCIName();
|
// this.setRootCIName(right.getId());
|
// String sql = getSql(qt, addGrandRightFlag);
|
// this.setRootCIName(rootCIName);
|
// return sql;
|
// }else{
|
// return stb.toString();
|
// }
|
// }
|
//
|
// return stb.toString();
|
// }
|
|
/**
|
* 将查询条件中的btm条件解析成sql
|
* @param qt
|
* @return
|
*/
|
// public String getBtmConditionSql(QueryTemplate qt, boolean addGrandRightFlag){
|
// StringBuilder stb = new StringBuilder("");
|
// ConditionItem rootCI = ciMap.get(this.getRootCIName());
|
// if(rootCI.isLeaf()){
|
// if(isBtmContidionItem(rootCI)){
|
// return rootCI.getSql(qt, addGrandRightFlag);
|
// }else{
|
// return stb.toString();
|
// }
|
// }else{
|
// ConditionItem root = rootCI;
|
// ConditionItem left = ciMap.get(root.getChildrenInfo().getLeftCIName());
|
// ConditionItem right = ciMap.get(root.getChildrenInfo().getRightCIName());
|
// if(isBtmContidionItem(left) && isBtmContidionItem(right)){
|
// String treeSql = parseTree(left, root, right, qt, addGrandRightFlag);
|
// stb.append(treeSql);
|
// }else if(isBtmContidionItem(left)){
|
// String rootCIName = this.getRootCIName();
|
// this.setRootCIName(left.getId());
|
// String sql = getSql(qt, addGrandRightFlag);
|
// this.setRootCIName(rootCIName);
|
// return sql;
|
// }else if(isBtmContidionItem(right)){
|
// String rootCIName = this.getRootCIName();
|
// this.setRootCIName(right.getId());
|
// String sql = getSql(qt, addGrandRightFlag);
|
// this.setRootCIName(rootCIName);
|
// return sql;
|
// }else{
|
// return stb.toString();
|
// }
|
// }
|
//
|
// return stb.toString();
|
// }
|
|
/**
|
* 递归解析ConditionItem树结构
|
* @param left
|
* @param root
|
* @param right
|
* @return
|
*/
|
// public String parseTree(ConditionItem left, ConditionItem root, ConditionItem right, QueryTemplate qt, boolean addGrandRightFlag){
|
// StringBuilder strb = new StringBuilder("");
|
// strb.append(Symbol.LEFT_PAREN);
|
// if(left.isLeaf()){
|
// strb.append(left.getSql(qt, addGrandRightFlag));
|
// }else{
|
// ConditionItem left_ = ciMap.get(left.getChildrenInfo().getLeftCIName());
|
// ConditionItem root_ = left;
|
// ConditionItem right_ = ciMap.get(left.getChildrenInfo().getRightCIName());
|
// String treeSql = parseTree(left_, root_, right_, qt, addGrandRightFlag);
|
// strb.append(treeSql);
|
// }
|
// strb.append(Symbol.SPACE);
|
// String connector = root.getChildrenInfo().getConnector();
|
// if(connector.equals(Connector.ANDCN)){
|
// connector = Connector.AND;
|
// }
|
// if(connector.equals(Connector.ORCN)){
|
// connector = Connector.OR;
|
// }
|
// strb.append(connector);
|
// strb.append(Symbol.SPACE);
|
// if(right.isLeaf()){
|
// strb.append(right.getSql(qt, addGrandRightFlag));
|
// }else{
|
// ConditionItem left_ = ciMap.get(right.getChildrenInfo().getLeftCIName());
|
// ConditionItem root_ = right;
|
// ConditionItem right_ = ciMap.get(right.getChildrenInfo().getRightCIName());
|
// String treeSql = parseTree(left_, root_, right_, qt, addGrandRightFlag);
|
// strb.append(treeSql);
|
// }
|
// strb.append(Symbol.RIGHT_PAREN);
|
// return strb.toString();
|
// }
|
|
// /**
|
// * 在链接查询的查询条件中
|
// * 判断查询条件项是否是约束业务对象的
|
// * @return
|
// */
|
// public boolean isBtmContidionItem(ConditionItem ci){
|
// while(!ci.isLeaf()){
|
// ci = ciMap.get(ci.getChildrenInfo().getRightCIName());
|
// }
|
// String clause = ci.getLeafInfo().getClause();
|
// if(clause.startsWith("T_OID.") || clause.startsWith("F_OID.")){
|
// return true;
|
// }
|
// return false;
|
// }
|
}
|