|
@@ -9,12 +9,16 @@ import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
import cn.cslg.pas.common.model.request.StringRequest;
|
|
|
import cn.cslg.pas.common.utils.StringUtils;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.*;
|
|
|
+import cn.cslg.pas.common.vo.EsConfigVO;
|
|
|
import cn.cslg.pas.exception.ConditionException;
|
|
|
+import cn.cslg.pas.factorys.EsBuilderFactory.EsBuilderFactory;
|
|
|
+import cn.cslg.pas.factorys.EsBuilderFactory.IQueryBuilder;
|
|
|
import cn.cslg.pas.factorys.getOrderFactory.GetOrderFactory;
|
|
|
import cn.cslg.pas.factorys.getOrderFactory.GetOrderObject;
|
|
|
import cn.cslg.pas.factorys.getSqlFactorys.GetSqlFactory;
|
|
|
import cn.cslg.pas.factorys.getSqlFactorys.GetSqlObject;
|
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.google.gson.Gson;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -22,8 +26,10 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -39,6 +45,10 @@ public class FormatQueryService {
|
|
|
@Autowired
|
|
|
private GetOrderFactory getOrderFactory;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EsBuilderFactory esBuilderFactory;
|
|
|
+
|
|
|
+
|
|
|
public String getText(String text) throws Exception {
|
|
|
treeNode tree = expressManager.getInstance().Parse(text, false);
|
|
|
System.out.print(this.ToString((operateNode) tree));
|
|
@@ -370,4 +380,36 @@ public class FormatQueryService {
|
|
|
|
|
|
return reQuery;
|
|
|
}
|
|
|
+
|
|
|
+ public Query EsQueryToQuery(operateNode node, String configName) throws ParseException {
|
|
|
+ Query query = null;
|
|
|
+ operate operate1 = node.getoperate();
|
|
|
+ treeNode Left = node.getLeft();
|
|
|
+ treeNode Right = node.getRight();
|
|
|
+ if (operate1.getShowName().equals(enuType.Logic)) {
|
|
|
+ Query q1 = this.EsQueryToQuery((operateNode) Left, configName);
|
|
|
+ Query q2 = this.EsQueryToQuery((operateNode) Right, configName);
|
|
|
+ query = QueryBuilders.bool(i -> i.must(q1, q2));
|
|
|
+ } else if (operate1.getShowName().equals(enuType.Assignment)){
|
|
|
+ IQueryBuilder iQueryBuilder = null;
|
|
|
+ String field = Left.ToString();
|
|
|
+ String value = Right.ToString();
|
|
|
+ String json = CommonService.readJsonFile(configName + ".json");
|
|
|
+ List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
+ EsConfigVO esConfigVO = esConfigVOS.stream().filter(item -> item.getValue().equals(field)).findFirst().orElse(null);
|
|
|
+ if (esConfigVO != null) {
|
|
|
+ iQueryBuilder = esBuilderFactory.getClass(esConfigVO.getEsClass());
|
|
|
+ iQueryBuilder.setField(esConfigVO.getEsField());
|
|
|
+ if (iQueryBuilder.getField().contains(".")) {
|
|
|
+ String path = iQueryBuilder.getField().substring(0, iQueryBuilder.getField().indexOf("."));
|
|
|
+ iQueryBuilder.setPath(path);
|
|
|
+ }
|
|
|
+ iQueryBuilder.setOperator(operate1.getShowName());
|
|
|
+ iQueryBuilder.setValue(value);
|
|
|
+ query = iQueryBuilder.creteQuery();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return query;
|
|
|
+ }
|
|
|
}
|