提交 a524557b 编写于 作者: O o2sword

查询语句动态条件支持or

上级 aef556cb
......@@ -50,6 +50,9 @@ class ActionExecuteV2 extends BaseAction {
private static final String[] pageKeys = { "GROUP BY", " COUNT(" };
private static final String JOIN_KEY = " JOIN ";
private static final String JOIN_ON_KEY = " ON ";
private static final String SQL_WHERE = "WHERE";
private static final String SQL_AND = "AND";
private static final String SQL_OR = "OR";
ActionResult<Object> execute(EffectivePerson effectivePerson, String flag, String mode, Integer page, Integer size,
JsonElement jsonElement) throws Exception {
......@@ -123,8 +126,6 @@ class ActionExecuteV2 extends BaseAction {
}
CompiledScript cs = ScriptingFactory.functionalizationCompile(scriptText);
String jpql = JsonScriptingExecutor.evalString(cs, scriptContext);
// Object o = ScriptFactory.scriptEngine.eval(ScriptFactory.functionalization(), scriptContext);
// String jpql = ScriptFactory.asString(o);
Class<? extends JpaObject> cls = this.clazz(business, statement);
EntityManager em;
if (StringUtils.equalsIgnoreCase(statement.getEntityCategory(), Statement.ENTITYCATEGORY_DYNAMIC)
......@@ -263,13 +264,13 @@ class ActionExecuteV2 extends BaseAction {
String rightSql = "";
String leftSql = "";
boolean hasWhere = false;
if (sql.indexOf("where") > -1) {
whereSql = StringUtils.substringAfter(sql, "where");
leftSql = StringUtils.substringBefore(sql, "where");
if (sql.indexOf(SQL_WHERE.toLowerCase()) > -1) {
whereSql = StringUtils.substringAfter(sql, SQL_WHERE.toLowerCase());
leftSql = StringUtils.substringBefore(sql, SQL_WHERE.toLowerCase());
hasWhere = true;
} else if (sql.indexOf("WHERE") > -1) {
whereSql = StringUtils.substringAfter(sql, "WHERE");
leftSql = StringUtils.substringBefore(sql, "WHERE");
} else if (sql.indexOf(SQL_WHERE) > -1) {
whereSql = StringUtils.substringAfter(sql, SQL_WHERE);
leftSql = StringUtils.substringBefore(sql, SQL_WHERE);
hasWhere = true;
}
String matchKey = "";
......@@ -281,34 +282,39 @@ class ActionExecuteV2 extends BaseAction {
break;
}
}
List<String> filterList = new ArrayList<>();
for (FilterEntry filterEntry : wi.getFilterList()) {
if (StringUtils.isNotBlank(filterEntry.path) && StringUtils.isNotBlank(filterEntry.value)) {
StringBuilder sb = new StringBuilder();
sb.append(filterEntry.path);
sb.append(" ");
sb.append(Comparison.getMatchCom(filterEntry.comparison));
sb.append(" ");
sb.append(":" + filterEntry.value);
filterList.add(sb.toString());
}
}
if (hasWhere) {
list.add(leftSql);
list.add("WHERE");
list.add(SQL_WHERE);
} else {
list.add(whereSql);
if (!filterList.isEmpty()) {
list.add("WHERE");
if (!wi.getFilterList().isEmpty()) {
list.add(SQL_WHERE);
}
}
if (!filterList.isEmpty()) {
int size = wi.getFilterList().size();
if (size > 0) {
if (size > 1) {
list.add("(");
list.add(StringUtils.join(filterList, " AND "));
}
for(int i=0; i < size; i++){
FilterEntry filterEntry = wi.getFilterList().get(i);
if(i > 0){
String joinTag = filterEntry.logic;
if(StringUtils.isEmpty(joinTag) || !joinTag.equalsIgnoreCase(SQL_OR)){
joinTag = SQL_AND;
}
list.add(joinTag.toUpperCase());
}
list.add(filterEntry.path);
list.add(Comparison.getMatchCom(filterEntry.comparison));
list.add(":" + filterEntry.value);
}
if (size > 1) {
list.add(")");
}
}
if (hasWhere) {
list.add("AND");
list.add(SQL_AND);
list.add("(");
list.add(whereSql);
list.add(")");
......
......@@ -6,12 +6,10 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.processplatform.core.entity.content.Task_;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import com.x.base.core.entity.dataitem.ItemCategory;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.tools.DateTools;
import com.x.query.core.entity.Item;
......@@ -93,31 +91,14 @@ public class FilterEntry extends GsonPropertyObject {
return true;
}
case FORMAT_DATETIMEVALUE:
if (DateTools.isDateTimeOrDateOrTime(value) || StringUtils.equalsIgnoreCase(DEFINE_TIME, value)
|| StringUtils.equalsIgnoreCase(DEFINE_DATE, value)
|| StringUtils.equalsIgnoreCase(DEFINE_MONTH, value)
|| StringUtils.equalsIgnoreCase(DEFINE_SEASON, value)
|| StringUtils.equalsIgnoreCase(DEFINE_YEAR, value)) {
return true;
} else {
return false;
}
case FORMAT_DATEVALUE:
if (DateTools.isDateTimeOrDateOrTime(value) || StringUtils.equalsIgnoreCase(DEFINE_TIME, value)
|| StringUtils.equalsIgnoreCase(DEFINE_DATE, value)
|| StringUtils.equalsIgnoreCase(DEFINE_MONTH, value)
|| StringUtils.equalsIgnoreCase(DEFINE_SEASON, value)
|| StringUtils.equalsIgnoreCase(DEFINE_YEAR, value)) {
return true;
} else {
return false;
}
case FORMAT_TIMEVALUE:
if (DateTools.isDateTimeOrDateOrTime(value) || StringUtils.equalsIgnoreCase(DEFINE_TIME, value)
boolean flag = DateTools.isDateTimeOrDateOrTime(value) || StringUtils.equalsIgnoreCase(DEFINE_TIME, value)
|| StringUtils.equalsIgnoreCase(DEFINE_DATE, value)
|| StringUtils.equalsIgnoreCase(DEFINE_MONTH, value)
|| StringUtils.equalsIgnoreCase(DEFINE_SEASON, value)
|| StringUtils.equalsIgnoreCase(DEFINE_YEAR, value)) {
|| StringUtils.equalsIgnoreCase(DEFINE_YEAR, value);
if (flag) {
return true;
} else {
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册