diff --git a/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java b/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java index 130d0c2e3d..cf0eab9c81 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java +++ b/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java @@ -100,4 +100,6 @@ public class SQLConstants { public static final String GROUP_CONCAT = "GROUP_CONCAT(%s)"; public static final String QUARTER = "QUARTER(%s)"; + + public static final String EMPTY_SIGN = "_empty_$"; } diff --git a/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java b/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java index 7382489ad2..f666739bcb 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java +++ b/core/core-backend/src/main/java/io/dataease/engine/trans/ExtWhere2Str.java @@ -95,7 +95,12 @@ public class ExtWhere2Str { String whereValue = ""; if (StringUtils.containsIgnoreCase(request.getOperator(), "in")) { - whereValue = "('" + StringUtils.join(value, "','") + "')"; + // 过滤空数据 + if (value.contains(SQLConstants.EMPTY_SIGN)) { + whereValue = "('" + StringUtils.join(value, "','") + "', '')" + " or " + whereName + " is null "; + } else { + whereValue = "('" + StringUtils.join(value, "','") + "')"; + } } else if (StringUtils.containsIgnoreCase(request.getOperator(), "like")) { whereValue = "'%" + value.get(0) + "%'"; } else if (StringUtils.containsIgnoreCase(request.getOperator(), "between")) { @@ -112,7 +117,12 @@ public class ExtWhere2Str { whereValue = String.format(SQLConstants.WHERE_BETWEEN, value.get(0), value.get(1)); } } else { - whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value.get(0)); + // 过滤空数据 + if (StringUtils.equals(value.get(0), SQLConstants.EMPTY_SIGN)) { + whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, "") + " or " + whereName + " is null "; + } else { + whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value.get(0)); + } } list.add(SQLObj.builder() .whereField(whereName) @@ -120,7 +130,7 @@ public class ExtWhere2Str { .build()); } List strList = new ArrayList<>(); - list.forEach(ele -> strList.add(ele.getWhereField() + " " + ele.getWhereTermAndValue())); + list.forEach(ele -> strList.add("(" + ele.getWhereField() + " " + ele.getWhereTermAndValue() + ")")); meta.setExtWheres(ObjectUtils.isNotEmpty(list) ? "(" + String.join(" AND ", strList) + ")" : null); } }