新增[自定义查询sql]
This commit is contained in:
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
public class Filter {
|
||||
private String col;
|
||||
private String value;
|
||||
private String[] values;
|
||||
private String type;
|
||||
//----------------------
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -32,6 +32,9 @@ import static java.util.Arrays.asList;
|
||||
* @author: liangxianyou at 2019/1/20 12:43.
|
||||
*/
|
||||
public class RunTest<T> {
|
||||
static {
|
||||
MetaKit.init();
|
||||
}
|
||||
JsonConvert convert = JsonConvert.root();
|
||||
|
||||
/*public static Task A = new Task("mysql", "select * from user where userid=#(userid)", "查询用户列表", Kv.of("userid", 1));
|
||||
@@ -57,8 +60,9 @@ public class RunTest<T> {
|
||||
|
||||
//@Test
|
||||
public void parseFBeanTest() {
|
||||
String str = "{name:'user_service', filters:[{col:'a.username',type:'like',value:'lxy'}], orders:[{col:a.`id`,desc: -1},{col:a.`deptName`,desc: 1}], limit:{ps:2,pn:10}}";
|
||||
|
||||
String str = "{'platToken':'ipsm_v4','name':'historyTrack'," +
|
||||
"'filters':[{'col':'ap.comName','value':'贵阳市第十九中学','type':'LIKE'},{'col':'','value':'name=213113','type':'SQL'}]," +
|
||||
"'orders':[],'limit':{'pn':1,'ps':10,'total':1}}";
|
||||
|
||||
//FBean fBean = new Gson().fromJson(str, FBean.class);
|
||||
FBean fBean = convert.convertFrom(FBean.class, str);
|
||||
|
||||
Reference in New Issue
Block a user