From 5c910a40d97b3564a228a6100ee7b534eac77dc6 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 11 Nov 2024 15:19:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?REPORT-138249=20cpt=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=9B=BF=E6=8D=A2=20=E6=89=A9?= =?UTF-8?q?=E5=B1=95select=E3=80=81group=E3=80=81value=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tabledata/TableDataFormulaType.java | 14 +++- .../tabledata/TableDataFormulaUtils.java | 66 +++++++++++++++++-- .../actions/replace/utils/ReplaceUtils.java | 2 + 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java index 9f78a1e403..283d4df8a2 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java +++ b/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; } } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java index f788bc0c73..335c9f7470 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java +++ b/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 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 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 entities) { + private static void replaceArgument4FunctionCall(FunctionCall functionCall, List 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 entities, StringBuilder parent) { + private static void replaceFunctionCall0(int i, StringLiteral stringLiteral, FunctionCall functionCall, List entities, StringBuilder parent) { try { TableDataFormulaType type = TableDataFormulaType.get(functionCall.getName()); if (type != null) { diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java index 89b90a2d15..4571dc1ad1 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java +++ b/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 formulaInfos = SearchFormulaManager.getInstance().getFormulaInfos(); replaceFormulaInfos(formulaInfos, entity); + // 触发响应 + template.fireTargetModified(); } } From 3a1c9df873b53a48f3a6b23ebfbc43ad79b62ce8 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 11 Nov 2024 15:22:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?REPORT-138249=20cpt=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E6=9B=BF=E6=8D=A2=20=E6=89=A9?= =?UTF-8?q?=E5=B1=95select=E3=80=81group=E3=80=81value=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/content/tabledata/TableDataFormulaUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java index 335c9f7470..d51dc60064 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java @@ -85,6 +85,9 @@ public class TableDataFormulaUtils { if (subNode instanceof FunctionCall) { FunctionCall functionCall = (FunctionCall) subNode; TableDataFormulaUtils.replaceArgument4FunctionCall(functionCall, entities); + } else if (subNode instanceof DatasetFunctionCall) { + DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) subNode; + TableDataFormulaUtils.replaceArgument4DatasetFunctionCall(datasetFunctionCall, entities); } } } From e62ebf1c4cce6eb9b09cd3da51928e4a19efdb40 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 11 Nov 2024 18:08:54 +0800 Subject: [PATCH 3/4] =?UTF-8?q?REPORT-140237=20=E3=80=90=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E6=9B=BF=E6=8D=A2=E3=80=91=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=90=8E=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=88=97?= =?UTF-8?q?=E7=9A=84=E5=88=97=E7=9A=84=E6=9B=BF=E6=8D=A2=E6=B2=A1=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../replace/action/content/tabledata/TableDataFormulaUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java index d51dc60064..85c5b54980 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java @@ -224,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; From 5a4f3b837aaa2f8ac82f4096246d6f38cb7df9ce Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 11 Nov 2024 18:19:37 +0800 Subject: [PATCH 4/4] =?UTF-8?q?REPORT-140231=20=E3=80=90=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E6=9B=BF=E6=8D=A2=E3=80=91=E6=9B=BF=E6=8D=A2=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E6=8E=A7=E4=BB=B6-=E4=BA=8B=E4=BB=B6-=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0-=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E5=87=BD=E6=95=B0-=E5=AF=BC=E5=87=BA=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=8F=82=E6=95=B0=E5=85=AC=E5=BC=8F=E6=9C=AA?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/content/tabledata/TableDataFormulaType.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java index 283d4df8a2..af1ba2a661 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaType.java @@ -41,7 +41,11 @@ public enum TableDataFormulaType { /** * ds1.group(xxx) */ - GROUP("GROUP", 0); + GROUP("GROUP", 0), + /** + * ds1.find(xxx) + */ + FIND("FIND", 0); private int argumentIndex; private String name;