|
@@ -0,0 +1,134 @@
|
|
|
+package com.github.binarywang.demo.wx.cp.utils;
|
|
|
+
|
|
|
+
|
|
|
+import freemarker.template.utility.StringUtil;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class FiltersData {
|
|
|
+
|
|
|
+ private int pageIndex;
|
|
|
+ private int pageSize;
|
|
|
+ private List<FiltersUtils> filters;
|
|
|
+
|
|
|
+ private Integer sortDirection;
|
|
|
+
|
|
|
+ private String sortField;
|
|
|
+
|
|
|
+ public int getPageIndex() {
|
|
|
+ return pageIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPageIndex(int pageIndex) {
|
|
|
+ this.pageIndex = pageIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getPageSize() {
|
|
|
+ return pageSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setPageSize(int pageSize) {
|
|
|
+ this.pageSize = pageSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<FiltersUtils> getFilters() {
|
|
|
+ return filters;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setFilters(List<FiltersUtils> filters) {
|
|
|
+ this.filters = filters;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer getSortDirection() {
|
|
|
+ return sortDirection;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSortDirection(Integer sortDirection) {
|
|
|
+ this.sortDirection = sortDirection;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getSortField() {
|
|
|
+ return sortField;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSortField(String sortField) {
|
|
|
+ this.sortField = sortField;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getFilterString() {
|
|
|
+ String queryCondition = " where 1=1 ";
|
|
|
+ if (this.getFilters() != null) {
|
|
|
+ for (FiltersUtils item : this.getFilters()) {
|
|
|
+ if (item != null && (item.getValue()!=null || (item.getRules() != null && item.getRules().size() > 0))) {
|
|
|
+ String val = item.getValue();
|
|
|
+ String field = item.getField();
|
|
|
+ String operate = item.getOperate();
|
|
|
+ switch (operate) {
|
|
|
+ case "equal":
|
|
|
+ queryCondition += " and " + field + "= '" + val + "'";
|
|
|
+ break;
|
|
|
+ case "notequal":
|
|
|
+ queryCondition += " and " + field + "!= '" + val+"'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "less":
|
|
|
+ queryCondition += " and " + field + "< '" + val+"'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "lessorequal":
|
|
|
+ queryCondition += " and " + field + "<= '" + val+"'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "greater":
|
|
|
+ queryCondition += " and " + field + "> '" + val+"'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "greaterorequal":
|
|
|
+ queryCondition += " and " + field + ">= '" + val+"'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "contains":
|
|
|
+ queryCondition += " and " + field + " like '%" + val + "%'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "startswith":
|
|
|
+ queryCondition += " and " + field + " >='" + val + "'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "endswith":
|
|
|
+ queryCondition += " and " + field + " <= '" + val + "'";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "or":
|
|
|
+ String innerCondition = "1 = 1";
|
|
|
+ List<Map<String, Object>> rulesMap = item.getRules();
|
|
|
+ for (Map<String, Object> stringObjectMap : rulesMap) {
|
|
|
+ String rulesField = (String) stringObjectMap.get("field");
|
|
|
+ String rulesValue = (String) stringObjectMap.get("value");
|
|
|
+ innerCondition += " or "+rulesField+" = '"+rulesValue+"'";
|
|
|
+ }
|
|
|
+
|
|
|
+ innerCondition = innerCondition.replace("1 = 1 or", "");
|
|
|
+ queryCondition += " and (" + innerCondition + ")";
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "nestand":
|
|
|
+ String innerConditionNest = "1 = 1";
|
|
|
+ List<Map<String, Object>> rules = item.getRules();
|
|
|
+ for (Map<String, Object> stringObjectMap : rules) {
|
|
|
+ String rulesField = (String) stringObjectMap.get("field");
|
|
|
+ String rulesvalue = (String) stringObjectMap.get("value");
|
|
|
+ innerConditionNest += " and "+rulesField+" = '"+rulesvalue+"'";
|
|
|
+ }
|
|
|
+ innerConditionNest = innerConditionNest.replace("1 = 1 and", "");
|
|
|
+ queryCondition += " and (" + innerConditionNest + ")";
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return queryCondition;
|
|
|
+ }
|
|
|
+}
|