Browse Source

REPORT-138249 cpt支持数据集替换 扩展select、group、value公式

release/11.0
Destiny.Lin 1 month ago
parent
commit
5c910a40d9
  1. 14
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java
  2. 66
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java
  3. 2
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java

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

@ -31,9 +31,17 @@ public enum TableDataFormulaType {
*/
TABLEDATAFIELDS("TABLEDATAFIELDS", 0),
/**
* VALUE公式
* VALUE公式或者是ds1.value(xxx)两种情况
*/
VALUE("VALUE", 0);
VALUE("VALUE", 0),
/**
* ds1.select(xxx)
*/
SELECT("SELECT", 0),
/**
* ds1.group(xxx)
*/
GROUP("GROUP", 0);
private int argumentIndex;
private String name;
@ -52,7 +60,7 @@ public enum TableDataFormulaType {
*/
public static boolean needReplace(String value) {
for (TableDataFormulaType type : TableDataFormulaType.values()) {
if (value.contains(type.name())) {
if (value.toUpperCase().contains(type.name().toUpperCase())) {
return true;
}
}

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

@ -4,6 +4,7 @@ import com.fr.data.TableReplacementEntity;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import com.fr.parser.BinaryExpression;
import com.fr.parser.DatasetFunctionCall;
import com.fr.parser.FunctionCall;
import com.fr.parser.StringLiteral;
import com.fr.script.Calculator;
@ -30,6 +31,7 @@ public class TableDataFormulaUtils {
private static final String RIGHT_BRACKET = "}";
private static final String FORMULA_MARK = "=";
private static final String STATEMENT = "statement";
private static final String SOURCE_NAME = "sourceName";
/**
* 从公式中寻找数据集名称
@ -82,17 +84,69 @@ public class TableDataFormulaUtils {
for (Node subNode : nodes) {
if (subNode instanceof FunctionCall) {
FunctionCall functionCall = (FunctionCall) subNode;
TableDataFormulaUtils.replaceArgument(functionCall, entities);
TableDataFormulaUtils.replaceArgument4FunctionCall(functionCall, entities);
}
}
}
} else if (node instanceof FunctionCall) {
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 +185,25 @@ public class TableDataFormulaUtils {
return result;
}
private static void replaceArgument(FunctionCall functionCall, List<TableReplacementEntity> entities) {
private static void replaceArgument4FunctionCall(FunctionCall functionCall, List<TableReplacementEntity> entities) {
Node[] subNodes = functionCall.getArguments();
if (subNodes != null) {
StringBuilder parent = new StringBuilder(StringUtils.EMPTY);
for (int i = 0; i < subNodes.length; i++) {
Node subNode = subNodes[i];
if (subNode instanceof FunctionCall) {
replaceArgument((FunctionCall) subNode, entities);
replaceArgument4FunctionCall((FunctionCall) subNode, entities);
}
if (subNode instanceof StringLiteral) {
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 {
TableDataFormulaType type = TableDataFormulaType.get(functionCall.getName());
if (type != null) {

2
designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java

@ -213,6 +213,8 @@ public class ReplaceUtils {
SearchFormulaManager.getInstance().search4Infos(template);
List<FormulaInfo> formulaInfos = SearchFormulaManager.getInstance().getFormulaInfos();
replaceFormulaInfos(formulaInfos, entity);
// 触发响应
template.fireTargetModified();
}
}

Loading…
Cancel
Save