|
|
@@ -0,0 +1,77 @@
|
|
|
+package com.usoftchina.saas.commons.dto;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: guq
|
|
|
+ * @create: 2018-10-22 15:17
|
|
|
+ **/
|
|
|
+public class ListReqDTO implements Serializable {
|
|
|
+ private String condition;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 区分是否为关联列表
|
|
|
+ */
|
|
|
+ private String mode;
|
|
|
+
|
|
|
+ public String getCondition() {
|
|
|
+ return condition;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCondition(String condition) {
|
|
|
+ this.condition = condition;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMode() {
|
|
|
+ return mode;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMode(String mode) {
|
|
|
+ this.mode = mode;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 {
|
|
|
+ con = " " + field + " " + operation + " '" + value + "' and";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ finalCondition = finalCondition.append(con);
|
|
|
+ }
|
|
|
+ return finalCondition.substring(0, finalCondition.length() - 3);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|