📄 expression.java
字号:
/*
* Created on 2005-4-20
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package cn.myapps.core.dynaform.document.util;
import cn.myapps.util.StringUtil;
/**
* @author ZhouTY
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class Expression implements Element {
private String text;
private String left;
private String right;
private String join;
public Expression() {
}
public Expression(String text) throws Exception {
this.text = text;
System.out.println("text123->" + text);
if (text != null && text.trim().length() > 0) {
if (text.indexOf(">=") > 0) {
String[] tmp = text.split(">=");
left = tmp[0].trim();
right = tmp[1].trim();
join = ">=";
} else if (text.indexOf("<=") > 0) {
String[] tmp = text.split("<=");
left = tmp[0].trim();
right = tmp[1].trim();
join = "<=";
} else if (text.indexOf("=>") > 0) {
String[] tmp = text.split("=>");
left = tmp[0].trim();
right = tmp[1].trim();
join = "=>";
} else if (text.indexOf("=<") > 0) {
String[] tmp = text.split("=<");
left = tmp[0].trim();
right = tmp[1].trim();
join = "=<";
} else if (text.indexOf("!=") > 0) {
String[] tmp = text.split("!=");
left = tmp[0].trim();
right = tmp[1].trim();
join = "!=";
} else if (text.indexOf("<>") > 0) {
String[] tmp = text.split("<>");
left = tmp[0].trim();
right = tmp[1].trim();
join = "<>";
} else if (text.indexOf("=") > 0) {
String[] tmp = text.split("=");
left = tmp[0].trim();
right = tmp[1].trim();
join = "=";
} else if (text.indexOf(">") > 0) {
String[] tmp = text.split(">");
left = tmp[0].trim();
right = tmp[1].trim();
join = ">";
} else if (text.indexOf("<") > 0) {
String[] tmp = text.split("<");
left = tmp[0].trim();
right = tmp[1].trim();
join = "<";
} else if (text.toLowerCase().indexOf(" like ") > 0) {
int pos = text.toLowerCase().indexOf(" like ");
left = text.substring(0, pos).trim();
right = text.substring(pos + 6, text.length()).trim();
join = "LIKE";
} else if (text.toLowerCase().indexOf(" in ") > 0) {
int pos = text.toLowerCase().indexOf(" in ");
left = text.substring(0, pos).trim();
right = "(" + text.substring(pos + 4, text.length()).trim()
+ ")";
join = "IN";
} else if (text.toLowerCase().indexOf(" is ") > 0) {
int pos = text.toLowerCase().indexOf(" is ");
left = text.substring(0, pos).trim();
right = "(" + text.substring(pos + 4, text.length()).trim()
+ ")";
join = "IS";
} else {
throw new Exception("Expression String Error!");
}
} else {
throw new Exception("Expression String Error!");
}
}
/**
* @return Returns the left.
*/
public String getLeft() {
return left;
}
/**
* @param left
* The left to set.
*/
public void setLeft(String left) {
this.left = left;
}
/**
* @return Returns the right.
*/
public String getRight() {
return right;
}
/**
* @param right
* The right to set.
*/
public void setRight(String right) {
this.right = right;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public boolean equals(Object obj) {
return false;
}
public static void main(String[] args) {
}
/**
* @return Returns the join.
*/
public String getJoin() {
return join;
}
/**
* @param join
* The join to set.
*/
public void setJoin(String join) {
this.join = join;
}
public String toString() {
StringBuffer tmp = new StringBuffer();
tmp.append(left);
tmp.append(" ");
tmp.append(join);
tmp.append(" ");
tmp.append(right);
return tmp.toString();
// return text;
}
public String toSqlString() {
StringBuffer sql = new StringBuffer();
if (left.trim().startsWith("$")) {// DOC 字段
if (left.trim().startsWith("$owner")) {
sql.append("SELECT authdocid id FROM "
+ Formula._AUTH_CLASSNAME + " WHERE authvalue IN (");
sql.append(right);
sql.append(")");
sql
.append(" AND authtype='OWNER' AND authfrom = 'T_DYNAFORM_DOCUMENT'");
} else {
sql.append("doc.");
sql.append(left.substring(1, left.length()));
sql.append(" ");
sql.append(join);
sql.append(" ");
sql.append(right);
}
} else {
if (join.equals("LIKE")) {
sql.append("doc.items.name='");
sql.append(left);
sql.append("' AND ");
sql.append("doc.items.varcharvalue LIKE ");
sql.append(right);
} else {
sql.append("doc.items.name='");
sql.append(left);
sql.append("' AND ");
sql.append("(");
sql.append("doc.items.varcharvalue ");
sql.append(join);
sql.append(" ");
sql.append(right);
sql.append(") ");
}
}
return sql.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -