|
|
@ -4,6 +4,7 @@ import com.fr.data.TableReplacementEntity; |
|
|
|
import com.fr.invoke.Reflect; |
|
|
|
import com.fr.invoke.Reflect; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.parser.BinaryExpression; |
|
|
|
import com.fr.parser.BinaryExpression; |
|
|
|
|
|
|
|
import com.fr.parser.DatasetFunctionCall; |
|
|
|
import com.fr.parser.FunctionCall; |
|
|
|
import com.fr.parser.FunctionCall; |
|
|
|
import com.fr.parser.StringLiteral; |
|
|
|
import com.fr.parser.StringLiteral; |
|
|
|
import com.fr.script.Calculator; |
|
|
|
import com.fr.script.Calculator; |
|
|
@ -30,6 +31,7 @@ public class TableDataFormulaUtils { |
|
|
|
private static final String RIGHT_BRACKET = "}"; |
|
|
|
private static final String RIGHT_BRACKET = "}"; |
|
|
|
private static final String FORMULA_MARK = "="; |
|
|
|
private static final String FORMULA_MARK = "="; |
|
|
|
private static final String STATEMENT = "statement"; |
|
|
|
private static final String STATEMENT = "statement"; |
|
|
|
|
|
|
|
private static final String SOURCE_NAME = "sourceName"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 从公式中寻找数据集名称 |
|
|
|
* 从公式中寻找数据集名称 |
|
|
@ -82,17 +84,72 @@ public class TableDataFormulaUtils { |
|
|
|
for (Node subNode : nodes) { |
|
|
|
for (Node subNode : nodes) { |
|
|
|
if (subNode instanceof FunctionCall) { |
|
|
|
if (subNode instanceof FunctionCall) { |
|
|
|
FunctionCall functionCall = (FunctionCall) subNode; |
|
|
|
FunctionCall functionCall = (FunctionCall) subNode; |
|
|
|
TableDataFormulaUtils.replaceArgument(functionCall, entities); |
|
|
|
TableDataFormulaUtils.replaceArgument4FunctionCall(functionCall, entities); |
|
|
|
|
|
|
|
} else if (subNode instanceof DatasetFunctionCall) { |
|
|
|
|
|
|
|
DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) subNode; |
|
|
|
|
|
|
|
TableDataFormulaUtils.replaceArgument4DatasetFunctionCall(datasetFunctionCall, entities); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (node instanceof FunctionCall) { |
|
|
|
} else if (node instanceof FunctionCall) { |
|
|
|
FunctionCall functionCall = (FunctionCall) node; |
|
|
|
FunctionCall functionCall = (FunctionCall) node; |
|
|
|
TableDataFormulaUtils.replaceArgument(functionCall, entities); |
|
|
|
TableDataFormulaUtils.replaceArgument4FunctionCall(functionCall, entities); |
|
|
|
|
|
|
|
} else if (node instanceof DatasetFunctionCall) { |
|
|
|
|
|
|
|
DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) node; |
|
|
|
|
|
|
|
TableDataFormulaUtils.replaceArgument4DatasetFunctionCall(datasetFunctionCall, entities); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void replaceArgument4DatasetFunctionCall(DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities) { |
|
|
|
|
|
|
|
Node[] subNodes = datasetFunctionCall.getArguments(); |
|
|
|
|
|
|
|
if (subNodes != null) { |
|
|
|
|
|
|
|
// 数据集名称
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (TableReplacementEntity entity : entities) { |
|
|
|
|
|
|
|
if (StringUtils.equals(parent.toString(), entity.getOldName())) { |
|
|
|
|
|
|
|
// 子节点都替换完了才换最前面的数据集名称
|
|
|
|
|
|
|
|
Reflect.on(datasetFunctionCall).set(SOURCE_NAME, entity.getNewName()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void replaceDatasetFunctionCall0(StringLiteral stringLiteral, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
TableDataFormulaType type = TableDataFormulaType.get(datasetFunctionCall.getFnName()); |
|
|
|
|
|
|
|
if (type != null) { |
|
|
|
|
|
|
|
String name = stringLiteral.eval(Calculator.createCalculator()).toString(); |
|
|
|
|
|
|
|
for (TableReplacementEntity entity : entities) { |
|
|
|
|
|
|
|
if (StringUtils.equals(parent.toString(), entity.getOldName())) { |
|
|
|
|
|
|
|
// 如果是要替换的数据集
|
|
|
|
|
|
|
|
String field = entity.getTargetField(name); |
|
|
|
|
|
|
|
// 替换成匹配后的字段
|
|
|
|
|
|
|
|
Reflect.on(stringLiteral).set(STATEMENT, field); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().debug(e, e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 从公式(可能存在嵌套)中解析出某类型函数的第几个参数 |
|
|
|
* 从公式(可能存在嵌套)中解析出某类型函数的第几个参数 |
|
|
@ -131,25 +188,25 @@ public class TableDataFormulaUtils { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void replaceArgument(FunctionCall functionCall, List<TableReplacementEntity> entities) { |
|
|
|
private static void replaceArgument4FunctionCall(FunctionCall functionCall, List<TableReplacementEntity> entities) { |
|
|
|
Node[] subNodes = functionCall.getArguments(); |
|
|
|
Node[] subNodes = functionCall.getArguments(); |
|
|
|
if (subNodes != null) { |
|
|
|
if (subNodes != null) { |
|
|
|
StringBuilder parent = new StringBuilder(StringUtils.EMPTY); |
|
|
|
StringBuilder parent = new StringBuilder(StringUtils.EMPTY); |
|
|
|
for (int i = 0; i < subNodes.length; i++) { |
|
|
|
for (int i = 0; i < subNodes.length; i++) { |
|
|
|
Node subNode = subNodes[i]; |
|
|
|
Node subNode = subNodes[i]; |
|
|
|
if (subNode instanceof FunctionCall) { |
|
|
|
if (subNode instanceof FunctionCall) { |
|
|
|
replaceArgument((FunctionCall) subNode, entities); |
|
|
|
replaceArgument4FunctionCall((FunctionCall) subNode, entities); |
|
|
|
} |
|
|
|
} |
|
|
|
if (subNode instanceof StringLiteral) { |
|
|
|
if (subNode instanceof StringLiteral) { |
|
|
|
StringLiteral stringLiteral = (StringLiteral) subNode; |
|
|
|
StringLiteral stringLiteral = (StringLiteral) subNode; |
|
|
|
replaceArgument0(i, stringLiteral, functionCall, entities, parent); |
|
|
|
replaceFunctionCall0(i, stringLiteral, functionCall, entities, parent); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void replaceArgument0(int i, StringLiteral stringLiteral, FunctionCall functionCall, List<TableReplacementEntity> entities, StringBuilder parent) { |
|
|
|
private static void replaceFunctionCall0(int i, StringLiteral stringLiteral, FunctionCall functionCall, List<TableReplacementEntity> entities, StringBuilder parent) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
TableDataFormulaType type = TableDataFormulaType.get(functionCall.getName()); |
|
|
|
TableDataFormulaType type = TableDataFormulaType.get(functionCall.getName()); |
|
|
|
if (type != null) { |
|
|
|
if (type != null) { |
|
|
|