|
@@ -1,5 +1,6 @@
|
|
|
package com.persagy.proxy.adm.utils;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -30,7 +31,7 @@ public class AdmQueryCriteriaHelper {
|
|
|
/** 条件匹配字符串 */
|
|
|
public static final String[] COND_STR = {" = "," != "," > "," >= "," < "," <= "," in "," isnull "," contain "," startwith "," endwith "};
|
|
|
/** 条件匹配字符串 根据ADM实际调用查看,去掉空格*/
|
|
|
- public static final String[] COND_STR_TRIM = {"=","!=",">",">=","<","<=","in","isnull","contain","startwith","endwith"};
|
|
|
+ public static final String[] COND_STR_TRIM = {"=","!=",">",">=","<","<=","contain","in","isnull","startwith","endwith"};
|
|
|
/** 需要替换的字段对照 Map<AdmQueryCriteria.name, Map<AdmFieldName, DmpFieldName> */
|
|
|
public static Map<String, Map<String, String>> RENAME_MAP = new HashMap<>(16);
|
|
|
/** 与数据中台的操作参数对照 */
|
|
@@ -116,6 +117,9 @@ public class AdmQueryCriteriaHelper {
|
|
|
if(StrUtil.isBlank(orderStr)) {
|
|
|
return null;
|
|
|
}
|
|
|
+ // 2021年10月20日16:00:01 兼容DMP中台的createTime,updateTime字段
|
|
|
+ orderStr = StrUtil.replace(orderStr,"createTime","creationTime");
|
|
|
+ orderStr = StrUtil.replace(orderStr,"updateTime","modifiedTime");
|
|
|
// 按,分隔
|
|
|
String[] orders = StrUtil.split(orderStr, ",");
|
|
|
List<OrderItem> orderList = new ArrayList<>();
|
|
@@ -157,43 +161,42 @@ public class AdmQueryCriteriaHelper {
|
|
|
filters = StrUtil.replace(filters, "[", " ( ");
|
|
|
filters = StrUtil.replace(filters, "]", " ) ");
|
|
|
// 查找下一个 连接点[and or为连接点]
|
|
|
- ensureOrCondition(name, criteria, filters);
|
|
|
+ convertCondition(name, criteria, filters);
|
|
|
return criteria;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 从or条件中截取表达式
|
|
|
- * @param criteria
|
|
|
- * @param filters
|
|
|
- */
|
|
|
- private static void ensureOrCondition(String name, ObjectNode criteria, String filters) {
|
|
|
- int orIndex = StrUtil.indexOfIgnoreCase(filters, " or ", 0);
|
|
|
- String orLeft = orIndex < 0 ? filters : StrUtil.subPre(filters, orIndex);
|
|
|
- ensureAndCondition(name, criteria, orLeft);
|
|
|
- // 有or条件
|
|
|
- if(orIndex >= 0) {
|
|
|
- String orRight = StrUtil.subSuf(filters, orIndex + 4);
|
|
|
- ObjectNode node = criteria.putObject("$or");
|
|
|
- // 右侧字符串继续递归处理
|
|
|
- ensureOrCondition(name, node, orRight);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 从and条件中截取表达式
|
|
|
+ * 转换为查询条件
|
|
|
+ * @param name
|
|
|
* @param criteria
|
|
|
* @param filters
|
|
|
*/
|
|
|
- private static void ensureAndCondition(String name, ObjectNode criteria, String filters) {
|
|
|
- int andIndex = StrUtil.indexOfIgnoreCase(filters, " and ", 0);
|
|
|
- String andLeft = andIndex < 0 ? filters : StrUtil.subPre(filters, andIndex);
|
|
|
- // 处理左侧条件
|
|
|
- ensureAndExpress(name, criteria, andLeft);
|
|
|
- // 处理右侧条件
|
|
|
- if(andIndex >= 0) {
|
|
|
- String andRight = StrUtil.subSuf(filters, andIndex+5);
|
|
|
- // 递归处理and
|
|
|
- ensureAndCondition(name, criteria, andRight);
|
|
|
+ private static void convertCondition(String name, ObjectNode criteria, String filters) {
|
|
|
+ // 按and分隔
|
|
|
+ List<String> andFilters = StrUtil.splitTrim(filters, " and ");
|
|
|
+ // 按分隔后的表达式依次处理
|
|
|
+ for(String andFilter:andFilters) {
|
|
|
+ // 按or分组
|
|
|
+ List<String> orFilters = StrUtil.splitTrim(andFilter, " or ");
|
|
|
+ if(CollUtil.isEmpty(orFilters)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 长度为1,则不是or条件
|
|
|
+ if(orFilters.size() == 1) {
|
|
|
+ // 转换为Condition
|
|
|
+ convertExpress(name, criteria, orFilters.get(0));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // or条件
|
|
|
+ ObjectNode andOr = (ObjectNode) criteria.get(QueryOperator.AND_OR.getIndex());
|
|
|
+ if(andOr == null) {
|
|
|
+ // 没有此条件则创建
|
|
|
+ andOr = criteria.putObject(QueryOperator.AND_OR.getIndex());
|
|
|
+ }
|
|
|
+ // 转换为Condition
|
|
|
+ for(String orFilter:orFilters) {
|
|
|
+ convertExpress(name, andOr, orFilter);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -202,8 +205,9 @@ public class AdmQueryCriteriaHelper {
|
|
|
* @param criteria
|
|
|
* @param express
|
|
|
*/
|
|
|
- private static void ensureAndExpress(String name, ObjectNode criteria, String express) {
|
|
|
- String cond = StrUtil.isBlank(StrUtil.getContainsStr(express, COND_STR)) ? StrUtil.getContainsStr(express, COND_STR_TRIM) : StrUtil.getContainsStr(express, COND_STR);
|
|
|
+ private static void convertExpress(String name, ObjectNode criteria, String express) {
|
|
|
+ String cond = StrUtil.isBlank(StrUtil.getContainsStr(express, COND_STR)) ?
|
|
|
+ StrUtil.getContainsStr(express, COND_STR_TRIM) : StrUtil.getContainsStr(express, COND_STR);
|
|
|
if(StrUtil.isBlank(cond)) {
|
|
|
return;
|
|
|
}
|