diff --git a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java index 22210b6bab..6a7f37d28c 100644 --- a/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java +++ b/backend/src/main/java/io/dataease/service/dataset/DataSetTableService.java @@ -2594,38 +2594,62 @@ public class DataSetTableService { visitBinaryExpr(andExpression, "AND"); } + @Override + public void visit(Between between) { + if(hasVarible(between.getBetweenExpressionStart().toString()) || hasVarible(between.getBetweenExpressionEnd().toString())){ + getBuffer().append(SubstitutedSql); + }else { + getBuffer().append(between.getLeftExpression()).append(" BETWEEN ").append(between.getBetweenExpressionStart()).append(" AND ").append(between.getBetweenExpressionEnd()); + } + } @Override public void visit(MinorThan minorThan) { + if(hasVarible(minorThan.getLeftExpression().toString()) || hasVarible(minorThan.getRightExpression().toString())){ + getBuffer().append(SubstitutedSql); + return; + } getBuffer().append(minorThan.getLeftExpression()); getBuffer().append(" < "); - getBuffer().append(minorThan.getRightExpression()); + getBuffer().append( minorThan.getRightExpression()); } @Override public void visit(MinorThanEquals minorThan) { + if(hasVarible(minorThan.getLeftExpression().toString()) || hasVarible(minorThan.getRightExpression().toString())){ + getBuffer().append(SubstitutedSql); + return; + } getBuffer().append(minorThan.getLeftExpression()); getBuffer().append(" <= "); - getBuffer().append(minorThan.getRightExpression()); + getBuffer().append( minorThan.getRightExpression()); } @Override public void visit(GreaterThanEquals minorThan) { + if(hasVarible(minorThan.getLeftExpression().toString()) || hasVarible(minorThan.getRightExpression().toString())){ + getBuffer().append(SubstitutedSql); + return; + } getBuffer().append(minorThan.getLeftExpression()); getBuffer().append(" >= "); - getBuffer().append(minorThan.getRightExpression()); + getBuffer().append( minorThan.getRightExpression()); } @Override - public void visit(GreaterThan minorThan) { - getBuffer().append(minorThan.getLeftExpression()); + public void visit(GreaterThan greaterThan) { + if(hasVarible(greaterThan.getLeftExpression().toString()) || hasVarible(greaterThan.getRightExpression().toString())){ + getBuffer().append(SubstitutedSql); + return; + } + getBuffer().append(greaterThan.getLeftExpression()); getBuffer().append(" > "); - getBuffer().append(minorThan.getRightExpression()); + getBuffer().append( greaterThan.getRightExpression()); } @Override public void visit(ExpressionList expressionList) { - for (Iterator iter = expressionList.getExpressions().iterator(); iter.hasNext(); ) { + for (Iterator iter = expressionList.getExpressions().iterator(); iter.hasNext();) { Expression expression = iter.next(); expression.accept(this); if (iter.hasNext()) { @@ -2634,15 +2658,6 @@ public class DataSetTableService { } } - @Override - public void visit(Between between) { - if (hasVarible(between.getBetweenExpressionStart().toString()) || hasVarible(between.getBetweenExpressionEnd().toString())) { - getBuffer().append(SubstitutedSql); - } else { - getBuffer().append(between.getLeftExpression()).append(" BETWEEN ").append(between.getBetweenExpressionStart()).append(" AND ").append(between.getBetweenExpressionEnd()); - } - } - @Override public void visit(LikeExpression likeExpression) { if (hasVarible(likeExpression.toString())) { @@ -2706,33 +2721,29 @@ public class DataSetTableService { private void visitBinaryExpr(BinaryExpression expr, String operator) { - boolean hasBinaryExpression = false; + boolean hasSubBinaryExpression = false; try { BinaryExpression leftBinaryExpression = (BinaryExpression) expr.getLeftExpression(); - hasBinaryExpression = leftBinaryExpression.getLeftExpression() instanceof BinaryExpression; - } catch (Exception e) { - } + hasSubBinaryExpression = leftBinaryExpression.getLeftExpression() instanceof Expression; + } catch (Exception e) {e.printStackTrace();} - if (expr.getLeftExpression() instanceof BinaryExpression && !hasBinaryExpression && hasVarible(expr.getLeftExpression().toString())) { + if (expr.getLeftExpression() instanceof BinaryExpression && !hasSubBinaryExpression && hasVarible(expr.getLeftExpression().toString())) { getBuffer().append(SubstitutedSql); } else { expr.getLeftExpression().accept(this); } getBuffer().append(" " + operator + " "); - - hasBinaryExpression = false; + hasSubBinaryExpression = false; try { BinaryExpression rightBinaryExpression = (BinaryExpression) expr.getRightExpression(); - hasBinaryExpression = rightBinaryExpression.getRightExpression() instanceof BinaryExpression; + hasSubBinaryExpression = rightBinaryExpression.getRightExpression() instanceof BinaryExpression; + } catch (Exception e) { } - - if (expr.getRightExpression() instanceof BinaryExpression && !hasBinaryExpression && hasVarible(expr.getRightExpression().toString())) { + if (expr.getRightExpression() instanceof BinaryExpression && !hasSubBinaryExpression && hasVarible(expr.getRightExpression().toString())) { getBuffer().append(SubstitutedSql); - } else if (expr.getRightExpression() instanceof InExpression && !hasBinaryExpression && hasVarible(expr.getRightExpression().toString())) { - getBuffer().append(SubstitutedSql); - } else { + } else { expr.getRightExpression().accept(this); } }