|
@@ -11,12 +11,14 @@ 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.exception.XiaoShiException;
|
|
|
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.factorys.getSqlFactorys.GetWebQuerySql;
|
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -340,27 +342,6 @@ public class FormatQueryService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// if ((operate1.getShowName() != null)) {
|
|
|
-// if (operate1.getShowName().equals("AND")) {
|
|
|
-// operate1.setShowName("*");
|
|
|
-// } else if (operate1.getShowName().equals("OR")) {
|
|
|
-// operate1.setShowName("+");
|
|
|
-// } else if (operate1.getShowName().equals("NOT")) {
|
|
|
-// operate1.setShowName("-");
|
|
|
-// }
|
|
|
-// strCode = operate1.getShowName();
|
|
|
-// optionName = operate1.getShowName();
|
|
|
-// } else {
|
|
|
-// if (operate1.getCode().equals("AND")) {
|
|
|
-// operate1.setCode("*");
|
|
|
-// } else if (operate1.getCode().equals("OR")) {
|
|
|
-// operate1.setCode("+");
|
|
|
-// } else if (operate1.getCode().equals("NOT")) {
|
|
|
-// operate1.setCode("-");
|
|
|
-// }
|
|
|
-// strCode = operate1.getCode();
|
|
|
-// optionName = operate1.getCode();
|
|
|
-// }
|
|
|
GetSqlObject getSqlObjectLocal = null;
|
|
|
if (Left != null) {
|
|
|
if ((operate1.gettype() == enuType.Logic || operate1.gettype() == enuType.Assignment) && (Left instanceof operateNode)) {
|
|
@@ -428,7 +409,7 @@ public class FormatQueryService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
//格式化检索式
|
|
|
- String reQuery = this.webQueryToString((operateNode) tree, null, configName);
|
|
|
+ String reQuery = this.webQueryToString2( tree, configName);
|
|
|
reQuery = "F XX (" + reQuery + ")";
|
|
|
return reQuery;
|
|
|
}
|
|
@@ -542,4 +523,84 @@ public class FormatQueryService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ public String webQueryToString2(treeNode treenode, String tableName) {
|
|
|
+ operateNode node =(operateNode)treenode;
|
|
|
+ treeNode Left = node.getLeft();
|
|
|
+ treeNode Right = node.getRight();
|
|
|
+ operate operate1 = node.getoperate();
|
|
|
+ if(operate1.gettype() == enuType.Assignment)
|
|
|
+ {
|
|
|
+ if(!(Left instanceof valueNode)) {
|
|
|
+ throw new XiaoShiException("检索式错误");
|
|
|
+ }
|
|
|
+ valueNode leftValue = (valueNode) Left;
|
|
|
+ return this.getQueryValue(Right,tableName,leftValue.getvalue(),this.getNodeStrCode(operate1));
|
|
|
+ }
|
|
|
+ else if(operate1.gettype()==enuType.Logic)
|
|
|
+ {
|
|
|
+ return "("+ this.webQueryToString2(Left,tableName)+" "+this.getNodeStrCode(operate1)+" "+this.webQueryToString2(Right,tableName)+")";
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String getQueryValue(treeNode node, String tableName,String field,String option){
|
|
|
+ if(node instanceof valueNode){
|
|
|
+ valueNode valuenode =(valueNode) node;
|
|
|
+ String json = CommonService.readJsonFile(tableName + ".json");
|
|
|
+ List<SqlObject> sqlObjects = JSON.parseArray(json, SqlObject.class);
|
|
|
+ SqlObject sqlObject = sqlObjects.stream().filter(item -> item.getField().equals(field)).findFirst().orElse(null);
|
|
|
+ sqlObject.setOption(option);
|
|
|
+ GetSqlObject getSqlObject =getSqlFactory.getClass(sqlObject.getSqlClass());
|
|
|
+ getSqlObject.setSqlObject(sqlObject);
|
|
|
+ return getSqlObject.getSql(valuenode.getvalue());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ operateNode operatenode =(operateNode)node;
|
|
|
+ treeNode Left = operatenode.getLeft();
|
|
|
+ treeNode Right = operatenode.getRight();
|
|
|
+ operate operate1 = operatenode.getoperate();
|
|
|
+ return "("+this.getQueryValue(Left,tableName,field,option)+" "+this.getNodeStrCode(operate1)+" "+this.getQueryValue(Right,tableName,field,option)+")";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getNodeStrCode(operate operate1){
|
|
|
+ String strCode = "";
|
|
|
+ String optionName = "";
|
|
|
+ if ((operate1.getShowName() != null)) {
|
|
|
+ if (operate1.getShowName().equals("AND")) {
|
|
|
+ strCode="*";
|
|
|
+ optionName="*";
|
|
|
+ } else if (operate1.getShowName().equals("OR")) {
|
|
|
+ strCode="+";
|
|
|
+ optionName="+";
|
|
|
+ } else if (operate1.getShowName().equals("NOT")) {
|
|
|
+ strCode="-";
|
|
|
+ optionName="-";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ strCode=operate1.getShowName();
|
|
|
+ optionName=operate1.getShowName();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (operate1.getCode().equals("AND")) {
|
|
|
+ strCode="*";
|
|
|
+ optionName="*";
|
|
|
+ } else if (operate1.getCode().equals("OR")) {
|
|
|
+ strCode="+";
|
|
|
+ optionName="+";
|
|
|
+ } else if (operate1.getCode().equals("NOT")) {
|
|
|
+ strCode="-";
|
|
|
+ optionName="-";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ strCode=operate1.getShowName();
|
|
|
+ optionName=operate1.getShowName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return strCode;
|
|
|
+ }
|
|
|
}
|