diff --git a/o2server/x_query_assemble_surface/src/main/java/com/x/query/assemble/surface/jaxrs/statement/ActionExecuteV2.java b/o2server/x_query_assemble_surface/src/main/java/com/x/query/assemble/surface/jaxrs/statement/ActionExecuteV2.java index 4c2997eb6a788c2d4dc183dae1b569ee32291ff6..eda262eb150e2955a09e6fb9d3ea01e27869ca77 100644 --- a/o2server/x_query_assemble_surface/src/main/java/com/x/query/assemble/surface/jaxrs/statement/ActionExecuteV2.java +++ b/o2server/x_query_assemble_surface/src/main/java/com/x/query/assemble/surface/jaxrs/statement/ActionExecuteV2.java @@ -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 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 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 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()) { - list.add("("); - list.add(StringUtils.join(filterList, " AND ")); - list.add(")"); + int size = wi.getFilterList().size(); + if (size > 0) { + if (size > 1) { + list.add("("); + } + 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(")"); diff --git a/o2server/x_query_core_express/src/main/java/com/x/query/core/express/plan/FilterEntry.java b/o2server/x_query_core_express/src/main/java/com/x/query/core/express/plan/FilterEntry.java index 576000ab61551bbede666037a4eabdef15dc425d..96fcdfb04d5d4604066fd69d98a8a9164451e5bb 100644 --- a/o2server/x_query_core_express/src/main/java/com/x/query/core/express/plan/FilterEntry.java +++ b/o2server/x_query_core_express/src/main/java/com/x/query/core/express/plan/FilterEntry.java @@ -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;