Browse Source

REPORT-141247 【FVS数据集替换】公式ds1.select、group、find字段名不会被替换

final/11.0
Destiny.Lin 1 day ago
parent
commit
c6e07423f9
  1. 42
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java

42
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java

@ -3,9 +3,11 @@ package com.fr.design.actions.replace.action.content.tabledata;
import com.fr.data.TableReplacementEntity;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import com.fr.parser.Ambiguity;
import com.fr.parser.BinaryExpression;
import com.fr.parser.DatasetFunctionCall;
import com.fr.parser.FunctionCall;
import com.fr.parser.RelationExpression;
import com.fr.parser.StringLiteral;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
@ -107,18 +109,7 @@ public class TableDataFormulaUtils {
// 数据集名称
StringBuilder parent = new StringBuilder(datasetFunctionCall.getSourceName());
for (Node subNode : subNodes) {
// 嵌套普通公式
if (subNode instanceof FunctionCall) {
replaceArgument4FunctionCall((FunctionCall) subNode, entities);
} else if (subNode instanceof StringLiteral) {
// 无嵌套,可以根据传进来的datasetFunctionCall进行替换
StringLiteral stringLiteral = (StringLiteral) subNode;
replaceDatasetFunctionCall0(stringLiteral, datasetFunctionCall, entities, parent);
} else if (subNode instanceof DatasetFunctionCall) {
// 嵌套datasetFunctionCall,递归回来该方法继续往下
DatasetFunctionCall datasetFunctionCall1 = (DatasetFunctionCall) subNode;
replaceArgument4DatasetFunctionCall(datasetFunctionCall1, entities);
}
replaceNode4DatasetFunctionCall(subNode, datasetFunctionCall, entities, parent);
}
for (TableReplacementEntity entity : entities) {
if (StringUtils.equals(parent.toString(), entity.getOldName())) {
@ -130,17 +121,38 @@ public class TableDataFormulaUtils {
}
}
private static void replaceDatasetFunctionCall0(StringLiteral stringLiteral, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
private static void replaceNode4DatasetFunctionCall(Node subNode, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
// 嵌套普通公式
if (subNode instanceof FunctionCall) {
replaceArgument4FunctionCall((FunctionCall) subNode, entities);
} else if (subNode instanceof Ambiguity) {
// 无嵌套,可以根据传进来的datasetFunctionCall进行替换
// 这边产品确认只能替换无双引号的字段,因此是ambiguity而不是StringLiteral
Ambiguity ambiguity = (Ambiguity) subNode;
replaceDatasetFunctionCall0(ambiguity, datasetFunctionCall, entities, parent);
} else if (subNode instanceof DatasetFunctionCall) {
// 嵌套datasetFunctionCall,递归回来该方法继续往下
DatasetFunctionCall datasetFunctionCall1 = (DatasetFunctionCall) subNode;
replaceArgument4DatasetFunctionCall(datasetFunctionCall1, entities);
} else if (subNode instanceof RelationExpression) {
Node left = ((RelationExpression) subNode).getLeft();
Node right = ((RelationExpression) subNode).getRight();
replaceNode4DatasetFunctionCall(left, datasetFunctionCall, entities, parent);
replaceNode4DatasetFunctionCall(right, datasetFunctionCall, entities, parent);
}
}
private static void replaceDatasetFunctionCall0(Ambiguity ambiguity, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
try {
TableDataFormulaType type = TableDataFormulaType.get(datasetFunctionCall.getFnName());
if (type != null) {
String name = stringLiteral.eval(Calculator.createCalculator()).toString();
String name = ambiguity.toString();
for (TableReplacementEntity entity : entities) {
if (StringUtils.equals(parent.toString(), entity.getOldName())) {
// 如果是要替换的数据集
String field = entity.getTargetField(name);
// 替换成匹配后的字段
Reflect.on(stringLiteral).set(STATEMENT, field);
Reflect.on(ambiguity).set(STATEMENT, field);
break;
}
}

Loading…
Cancel
Save