Browse Source

Merge pull request #15442 in DESIGN/design from release/11.0 to bugfix/11.0

* commit 'c09e97b24b2882427a2fd40814bf2634a5495d35':
  REPORT-140231 【数据集替换】替换后,控件-事件-设置回调函数-回调函数-导出事件的参数公式未替换
  REPORT-140237 【数据集替换】数据集替换后,数据列的列的替换没生效
  REPORT-138249 cpt支持数据集替换 扩展select、group、value公式
  REPORT-138249 cpt支持数据集替换 扩展select、group、value公式
bugfix/11.0
superman 1 week ago
parent
commit
a7e492ac39
  1. 18
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java
  2. 71
      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

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

@ -31,9 +31,21 @@ 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),
/**
* ds1.find(xxx)
*/
FIND("FIND", 0);
private int argumentIndex;
private String name;
@ -52,7 +64,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;
}
}

71
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,72 @@ 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 (subNode instanceof DatasetFunctionCall) {
DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) subNode;
TableDataFormulaUtils.replaceArgument4DatasetFunctionCall(datasetFunctionCall, 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 +188,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) {
@ -167,7 +224,7 @@ public class TableDataFormulaUtils {
String field = entity.getTargetField(name);
// 如果是需要匹配的字段
// 要走到字段匹配,就必须先经过数据集名匹配,目前所有公式都是数据集在前,字段在后
if (StringUtils.isNotEmpty(field) && StringUtils.equals(parent.toString(), name)) {
if (StringUtils.isNotEmpty(field) && StringUtils.isNotEmpty(parent.toString())) {
// 替换成匹配后的字段
Reflect.on(stringLiteral).set(STATEMENT, field);
break;

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