diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java similarity index 86% rename from designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtils.java rename to designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java index 22e500c299..f788bc0c73 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtils.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java @@ -23,7 +23,7 @@ import java.util.Set; * @since 11.0 * Created on 2024/11/5 */ -public class FormulaUtils { +public class TableDataFormulaUtils { private static final String LEFT_BRACKET = "${"; @@ -33,22 +33,30 @@ public class FormulaUtils { /** * 从公式中寻找数据集名称 + * + * @param formula 公式的content + * @return 返回数据集名称集合 */ - public static Set search(String formula) { + public static Set search4TableData(String formula) { Set result = new HashSet<>(); for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) { - result.addAll(FormulaUtils.fetchArgument(formula, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex())); + result.addAll(TableDataFormulaUtils.fetchArgument(formula, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex())); } return result; } + /** - * 获取替换后的公式全文 + * 获取替换指定数据集后的公式全文 + * + * @param formula 公式content + * @param entities 替换信息 + * @return 替换后的全文 */ - public static String replace(String formula, List entities) { + public static String replace4TableData(String formula, List entities) { try { Expression expression = Calculator.createCalculator().parse(formula); - FormulaUtils.replace0(expression, entities); + TableDataFormulaUtils.replace0(expression, entities); String ans = expression.toString(); if (formula.startsWith(FORMULA_MARK) && !ans.startsWith(FORMULA_MARK)) { return FORMULA_MARK + ans; @@ -74,13 +82,13 @@ public class FormulaUtils { for (Node subNode : nodes) { if (subNode instanceof FunctionCall) { FunctionCall functionCall = (FunctionCall) subNode; - FormulaUtils.replaceArgument(functionCall, entities); + TableDataFormulaUtils.replaceArgument(functionCall, entities); } } } } else if (node instanceof FunctionCall) { FunctionCall functionCall = (FunctionCall) node; - FormulaUtils.replaceArgument(functionCall, entities); + TableDataFormulaUtils.replaceArgument(functionCall, entities); } } } @@ -107,13 +115,13 @@ public class FormulaUtils { for (Node subNode : nodes) { if (subNode instanceof FunctionCall) { FunctionCall functionCall = (FunctionCall) subNode; - result.addAll(FormulaUtils.fetchArgument(functionCall, functionName, argumentIndex)); + result.addAll(TableDataFormulaUtils.fetchArgument(functionCall, functionName, argumentIndex)); } } } } else if (node instanceof FunctionCall) { FunctionCall functionCall = (FunctionCall) node; - result.addAll(FormulaUtils.fetchArgument(functionCall, functionName, argumentIndex)); + result.addAll(TableDataFormulaUtils.fetchArgument(functionCall, functionName, argumentIndex)); } } @@ -199,7 +207,7 @@ public class FormulaUtils { } if (subNode instanceof FunctionCall) { for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) { - result.addAll(FormulaUtils.fetchArgument((FunctionCall) subNode, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex())); + result.addAll(TableDataFormulaUtils.fetchArgument((FunctionCall) subNode, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex())); } } } 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 c1a89cac86..15c5896c6a 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 @@ -8,7 +8,7 @@ import com.fr.design.actions.replace.action.content.formula.SearchFormulaManager import com.fr.design.actions.replace.action.content.formula.cell.SearchCellFormulaAction; import com.fr.design.actions.replace.action.content.formula.chart.SearchChartCollectionFormulaAction; import com.fr.design.actions.replace.action.content.formula.widget.SearchWidgetFormulaAction; -import com.fr.design.actions.replace.action.content.tabledata.FormulaUtils; +import com.fr.design.actions.replace.action.content.tabledata.TableDataFormulaUtils; import com.fr.design.actions.replace.action.content.tabledata.TableDataFormulaType; import com.fr.design.actions.replace.action.content.widget.SearchWidgetAction; import com.fr.design.actions.replace.info.CellInfo; @@ -47,7 +47,7 @@ public class ReplaceUtils { * @return 返回公式中使用的数据集名称 */ public static Set getFormulaDependenceTables(String formula) { - return FormulaUtils.search(formula); + return TableDataFormulaUtils.search4TableData(formula); } @@ -151,7 +151,7 @@ public class ReplaceUtils { * @return 替换后的公式内容 */ public static String replaceFormula(String formula, List entity) { - return FormulaUtils.replace(formula, entity); + return TableDataFormulaUtils.replace4TableData(formula, entity); } /** @@ -162,7 +162,7 @@ public class ReplaceUtils { */ public static void replaceFormula(Formula formula, List entity) { String content = formula.getContent(); - formula.setContent(FormulaUtils.replace(content, entity)); + formula.setContent(TableDataFormulaUtils.replace4TableData(content, entity)); } /** @@ -219,7 +219,7 @@ public class ReplaceUtils { if (TableDataFormulaType.needReplace(formulaInfo.getPureValue())) { formulaInfo.setValue(formulaInfo, formulaInfo.getPureValue(), - FormulaUtils.replace(formulaInfo.getPureValue(), entity), + TableDataFormulaUtils.replace4TableData(formulaInfo.getPureValue(), entity), new ArrayList<>()); } } diff --git a/designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtilsTest.java b/designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtilsTest.java similarity index 67% rename from designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtilsTest.java rename to designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtilsTest.java index b563010713..ca4fc6dd45 100644 --- a/designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtilsTest.java +++ b/designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtilsTest.java @@ -16,23 +16,23 @@ import java.util.Set; * @since 11.0 * Created on 2024/11/5 */ -public class FormulaUtilsTest extends TestCase { +public class TableDataFormulaUtilsTest extends TestCase { public void testSearch() { String rowcount = "=ROWCOUNT(\"123\")"; Set strings = new HashSet<>(); strings.add("123"); - Assert.assertEquals(FormulaUtils.search(rowcount), strings); + Assert.assertEquals(TableDataFormulaUtils.search4TableData(rowcount), strings); Set errorSet = new HashSet<>(); errorSet.add("1223"); - Assert.assertNotEquals(FormulaUtils.search(rowcount), errorSet); + Assert.assertNotEquals(TableDataFormulaUtils.search4TableData(rowcount), errorSet); String str = "=COLNAME(\"test-测试\",COLCOUNT(\"列数嵌套123\"))"; Set qiantao = new HashSet<>(); qiantao.add("test-测试"); qiantao.add("列数嵌套123"); - Assert.assertEquals(FormulaUtils.search(str), qiantao); + Assert.assertEquals(TableDataFormulaUtils.search4TableData(str), qiantao); String str2 = "=sum(len(MAP(value(\"test-测试1\",COLNAME(\"test-测试2\",2),COLCOUNT(\"test-测试3\")),\"test-测试4\",COLNAME(\"test-测试5\",2),COLNAME(\"test-测试6\",4))),ROWCOUNT(\"test-测试7\"),len(TABLEDATAFIELDS(\"test-测试8\")))"; - Set qiantao2 = FormulaUtils.search(str2); + Set qiantao2 = TableDataFormulaUtils.search4TableData(str2); Assert.assertTrue(qiantao2.contains("test-测试1")); Assert.assertTrue(qiantao2.contains("test-测试2")); Assert.assertTrue(qiantao2.contains("test-测试3")); @@ -51,7 +51,7 @@ public class FormulaUtilsTest extends TestCase { entity.setNewName("222"); List entities = new ArrayList<>(); entities.add(entity); - Assert.assertEquals(FormulaUtils.replace(rowcount, entities), "=ROWCOUNT(\"222\")"); + Assert.assertEquals(TableDataFormulaUtils.replace4TableData(rowcount, entities), "=ROWCOUNT(\"222\")"); String colcount = "=COLCOUNT(\"test测试\")"; TableReplacementEntity entity1 = new TableReplacementEntity(); @@ -59,7 +59,7 @@ public class FormulaUtilsTest extends TestCase { entity1.setNewName("替换"); List entities1 = new ArrayList<>(); entities1.add(entity1); - Assert.assertEquals(FormulaUtils.replace(colcount, entities1), "=COLCOUNT(\"替换\")"); + Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colcount, entities1), "=COLCOUNT(\"替换\")"); String colname = "=COLNAME(\"test测试\")"; TableReplacementEntity entity2 = new TableReplacementEntity(); @@ -67,7 +67,7 @@ public class FormulaUtilsTest extends TestCase { entity2.setNewName("替换123"); List entities2 = new ArrayList<>(); entities2.add(entity2); - Assert.assertEquals(FormulaUtils.replace(colname, entities2), "=COLNAME(\"替换123\")"); + Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colname, entities2), "=COLNAME(\"替换123\")"); String TABLEDATAFIELDS = "=TABLEDATAFIELDS(\"test测试\")"; TableReplacementEntity entity3 = new TableReplacementEntity(); @@ -75,7 +75,7 @@ public class FormulaUtilsTest extends TestCase { entity3.setNewName("替换111"); List entities3 = new ArrayList<>(); entities3.add(entity3); - Assert.assertEquals(FormulaUtils.replace(TABLEDATAFIELDS, entities3), "=TABLEDATAFIELDS(\"替换111\")"); + Assert.assertEquals(TableDataFormulaUtils.replace4TableData(TABLEDATAFIELDS, entities3), "=TABLEDATAFIELDS(\"替换111\")"); String test = "=sum(len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",2),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4))),ROWCOUNT(\"test-测试\"),len(TABLEDATAFIELDS(\"test-测试\")))"; TableReplacementEntity entity4 = new TableReplacementEntity(); @@ -83,7 +83,7 @@ public class FormulaUtilsTest extends TestCase { entity4.setNewName("test-测试的副本"); List entities4 = new ArrayList<>(); entities4.add(entity4); - Assert.assertEquals(FormulaUtils.replace(test, entities4), "=sum(len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); + Assert.assertEquals(TableDataFormulaUtils.replace4TableData(test, entities4), "=sum(len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); String testCircle = "=sum(len(MAP(value(\"test-测试1\",COLNAME(\"test-测试2\",len(MAP(value(\"test-测试3\",COLNAME(\"test-测试4\",len(MAP(value(\"test-测试\",COLNAME(\"test-测试\",2),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4)))),COLCOUNT(\"test-测试\")),\"test-测试\",COLNAME(\"test-测试\",2),COLNAME(\"test-测试\",4))),ROWCOUNT(\"test-测试\"),len(TABLEDATAFIELDS(\"test-测试\")))"; @@ -104,7 +104,7 @@ public class FormulaUtilsTest extends TestCase { entities5.add(entity6); entities5.add(entity7); entities5.add(entity8); - Assert.assertEquals(FormulaUtils.replace(testCircle, entities5), "=sum(len(MAP(value(\"test-测试2\",COLNAME(\"test-测试3\",len(MAP(value(\"test-测试4\",COLNAME(\"test-测试4\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); + Assert.assertEquals(TableDataFormulaUtils.replace4TableData(testCircle, entities5), "=sum(len(MAP(value(\"test-测试2\",COLNAME(\"test-测试3\",len(MAP(value(\"test-测试4\",COLNAME(\"test-测试4\",len(MAP(value(\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4)))),COLCOUNT(\"test-测试的副本\")),\"test-测试的副本\",COLNAME(\"test-测试的副本\",2),COLNAME(\"test-测试的副本\",4))),ROWCOUNT(\"test-测试的副本\"),len(TABLEDATAFIELDS(\"test-测试的副本\")))"); } } \ No newline at end of file