|
|
@@ -35,44 +35,49 @@ public class ListReqDTO implements Serializable {
|
|
|
}
|
|
|
|
|
|
public String getFinalCondition() {
|
|
|
- JSONArray jsonArray = JSONArray.parseArray(this.condition);
|
|
|
- if (null != jsonArray && jsonArray.size() > 0) {
|
|
|
- StringBuffer finalCondition = new StringBuffer();
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- String con = null;
|
|
|
- JSONObject jsonObject = (JSONObject)jsonArray.get(i);
|
|
|
- Object type = jsonObject.get("type");
|
|
|
- Object field = jsonObject.get("field");
|
|
|
- Object operation = jsonObject.get("operation");
|
|
|
- Object value = jsonObject.get("value");
|
|
|
- //包含状态时,前台会自动加单引号
|
|
|
- if (null != value && !"in".equals(operation) && !"not in".equals(operation)) {
|
|
|
- value = value.toString().replaceAll("'", "''");
|
|
|
- }
|
|
|
- if ("between".equals(operation)) {
|
|
|
- String[] vals = value.toString().split(",");
|
|
|
- con = " " + field + " " + operation + " '" + vals[0] + "' and '" + vals[1] + "' and";
|
|
|
- } else if ("startsWith".equals(operation)) {
|
|
|
- con = " " + field + " like '" + value +"%' and";
|
|
|
- } else if ("endsWith".equals(operation)) {
|
|
|
- con = " " + field + " like '%" + value + "' and";
|
|
|
- } else if ("in".equals(operation) || "not in".equals(operation)) {
|
|
|
- con = " " + field + " " + operation + " (" + value + ") and";
|
|
|
- } else {
|
|
|
- //字符串默认是模糊查询
|
|
|
- if ("string".equals(type)) {
|
|
|
- con = " " + field + " like '%" + value + "%' and";
|
|
|
- } else if ("condition".equals(type)) {
|
|
|
- //type为condition为前端拼的条件
|
|
|
- con = " " + value + " and";
|
|
|
- } else {
|
|
|
- con = " " + field + " " + operation + " '" + value + "' and";
|
|
|
+ try {
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(this.condition);
|
|
|
+ if (null != jsonArray && jsonArray.size() > 0) {
|
|
|
+ StringBuffer finalCondition = new StringBuffer();
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ String con = null;
|
|
|
+ JSONObject jsonObject = (JSONObject) jsonArray.get(i);
|
|
|
+ Object type = jsonObject.get("type");
|
|
|
+ Object field = jsonObject.get("field");
|
|
|
+ Object operation = jsonObject.get("operation");
|
|
|
+ Object value = jsonObject.get("value");
|
|
|
+ //包含状态时,前台会自动加单引号
|
|
|
+ if (null != value && !"in".equals(operation) && !"not in".equals(operation) &&
|
|
|
+ !"condition".equals(type)) {
|
|
|
+ value = value.toString().replaceAll("'", "''");
|
|
|
}
|
|
|
+ if ("between".equals(operation)) {
|
|
|
+ String[] vals = value.toString().split(",");
|
|
|
+ con = " " + field + " " + operation + " '" + vals[0] + "' and '" + vals[1] + "' and";
|
|
|
+ } else if ("startsWith".equals(operation)) {
|
|
|
+ con = " " + field + " like '" + value + "%' and";
|
|
|
+ } else if ("endsWith".equals(operation)) {
|
|
|
+ con = " " + field + " like '%" + value + "' and";
|
|
|
+ } else if ("in".equals(operation) || "not in".equals(operation)) {
|
|
|
+ con = " " + field + " " + operation + " (" + value + ") and";
|
|
|
+ } else {
|
|
|
+ //字符串默认是模糊查询
|
|
|
+ if ("string".equals(type)) {
|
|
|
+ con = " " + field + " like '%" + value + "%' and";
|
|
|
+ } else if ("condition".equals(type)) {
|
|
|
+ //type为condition为前端拼的条件
|
|
|
+ con = " " + value + " and";
|
|
|
+ } else {
|
|
|
+ con = " " + field + " " + operation + " '" + value + "' and";
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ finalCondition = finalCondition.append(con);
|
|
|
}
|
|
|
- finalCondition = finalCondition.append(con);
|
|
|
+ return finalCondition.substring(0, finalCondition.length() - 3);
|
|
|
}
|
|
|
- return finalCondition.substring(0, finalCondition.length() - 3);
|
|
|
+ }catch (Exception e){
|
|
|
+ return null;
|
|
|
}
|
|
|
return null;
|
|
|
}
|