feat: 过滤组件支持空数据逻辑

This commit is contained in:
junjun 2024-03-13 15:04:58 +08:00
parent afb337e0fa
commit 7a25ca2e2d
2 changed files with 15 additions and 3 deletions

View File

@ -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_$";
}

View File

@ -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<String> 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);
}
}