新增[自定义查询sql]

This commit is contained in:
2019-07-09 16:20:36 +08:00
parent 73db35749e
commit 8454cdb3fb
22 changed files with 432 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import java.util.List;
public class Filter {
private String col;
private String value;
private String[] values;
private String type;
//----------------------

View File

@@ -15,7 +15,10 @@ public enum FilterType {
GREATERTHANOREQUALTO(">=", ">="),
LESSTHAN("<", "小于"),
LIKE("LIKE", "LIKE"),
IN("IN", "包含");
IN("IN", "包含"),
RANGE("RANGE", "区间"),
SQL("SQL", "SQL") //直接使用sql查询
;
private String expre;
private String remark;
@@ -35,7 +38,7 @@ public enum FilterType {
return "";
}
String _sql;
String _sql = "";
switch (filterType) {
case IN:
_sql = String.format(" AND %s IN (%s)", filter.getCol(), filter.getValue());
@@ -43,9 +46,20 @@ public enum FilterType {
case LIKE:
_sql = String.format(" AND %s LIKE '%s'", filter.getCol(), "%" + filter.getValue() + "%");
break;
case RANGE:
if (filter.getValues() != null) {
if (filter.getValues().length == 1) {
_sql = String.format(" AND %s>='%s'", filter.getCol(), filter.getValues()[0]);
} else if (filter.getValues().length == 2) {
_sql = String.format(" AND (%s>='%s' and %s<'%s')", filter.getCol(), filter.getValues()[0], filter.getCol(), filter.getValues()[1]);
}
}
break;
case SQL:
_sql = String.format(" AND (%s)", filter.getValue());
break;
default:
_sql = String.format(" AND %s %s '%s'", filter.getCol(), filterType.expre, filter.getValue());
break;
}
return _sql;