fix(数据集): SQL数据集参数会把between等条件丢失

This commit is contained in:
taojinlong 2022-08-25 21:59:27 +08:00
parent d915775007
commit 43cb2c2190

View File

@ -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<Expression> iter = expressionList.getExpressions().iterator(); iter.hasNext(); ) {
for (Iterator<Expression> 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,31 +2721,27 @@ 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())) {
getBuffer().append(SubstitutedSql);
} else if (expr.getRightExpression() instanceof InExpression && !hasBinaryExpression && hasVarible(expr.getRightExpression().toString())) {
if (expr.getRightExpression() instanceof BinaryExpression && !hasSubBinaryExpression && hasVarible(expr.getRightExpression().toString())) {
getBuffer().append(SubstitutedSql);
} else {
expr.getRightExpression().accept(this);