Browse Source

REPORT-138249 cpt支持数据集替换 优化命名

release/11.0
Destiny.Lin 3 weeks ago
parent
commit
15f4827532
  1. 30
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java
  2. 10
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java
  3. 22
      designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtilsTest.java

30
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtils.java → 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 * @since 11.0
* Created on 2024/11/5 * Created on 2024/11/5
*/ */
public class FormulaUtils { public class TableDataFormulaUtils {
private static final String LEFT_BRACKET = "${"; private static final String LEFT_BRACKET = "${";
@ -33,22 +33,30 @@ public class FormulaUtils {
/** /**
* 从公式中寻找数据集名称 * 从公式中寻找数据集名称
*
* @param formula 公式的content
* @return 返回数据集名称集合
*/ */
public static Set<String> search(String formula) { public static Set<String> search4TableData(String formula) {
Set<String> result = new HashSet<>(); Set<String> result = new HashSet<>();
for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) { 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; return result;
} }
/** /**
* 获取替换后的公式全文 * 获取替换指定数据集后的公式全文
*
* @param formula 公式content
* @param entities 替换信息
* @return 替换后的全文
*/ */
public static String replace(String formula, List<TableReplacementEntity> entities) { public static String replace4TableData(String formula, List<TableReplacementEntity> entities) {
try { try {
Expression expression = Calculator.createCalculator().parse(formula); Expression expression = Calculator.createCalculator().parse(formula);
FormulaUtils.replace0(expression, entities); TableDataFormulaUtils.replace0(expression, entities);
String ans = expression.toString(); String ans = expression.toString();
if (formula.startsWith(FORMULA_MARK) && !ans.startsWith(FORMULA_MARK)) { if (formula.startsWith(FORMULA_MARK) && !ans.startsWith(FORMULA_MARK)) {
return FORMULA_MARK + ans; return FORMULA_MARK + ans;
@ -74,13 +82,13 @@ public class FormulaUtils {
for (Node subNode : nodes) { for (Node subNode : nodes) {
if (subNode instanceof FunctionCall) { if (subNode instanceof FunctionCall) {
FunctionCall functionCall = (FunctionCall) subNode; FunctionCall functionCall = (FunctionCall) subNode;
FormulaUtils.replaceArgument(functionCall, entities); TableDataFormulaUtils.replaceArgument(functionCall, entities);
} }
} }
} }
} else if (node instanceof FunctionCall) { } else if (node instanceof FunctionCall) {
FunctionCall functionCall = (FunctionCall) node; FunctionCall functionCall = (FunctionCall) node;
FormulaUtils.replaceArgument(functionCall, entities); TableDataFormulaUtils.replaceArgument(functionCall, entities);
} }
} }
} }
@ -107,13 +115,13 @@ public class FormulaUtils {
for (Node subNode : nodes) { for (Node subNode : nodes) {
if (subNode instanceof FunctionCall) { if (subNode instanceof FunctionCall) {
FunctionCall functionCall = (FunctionCall) subNode; FunctionCall functionCall = (FunctionCall) subNode;
result.addAll(FormulaUtils.fetchArgument(functionCall, functionName, argumentIndex)); result.addAll(TableDataFormulaUtils.fetchArgument(functionCall, functionName, argumentIndex));
} }
} }
} }
} else if (node instanceof FunctionCall) { } else if (node instanceof FunctionCall) {
FunctionCall functionCall = (FunctionCall) node; 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) { if (subNode instanceof FunctionCall) {
for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) { 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()));
} }
} }
} }

10
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.cell.SearchCellFormulaAction;
import com.fr.design.actions.replace.action.content.formula.chart.SearchChartCollectionFormulaAction; 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.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.tabledata.TableDataFormulaType;
import com.fr.design.actions.replace.action.content.widget.SearchWidgetAction; import com.fr.design.actions.replace.action.content.widget.SearchWidgetAction;
import com.fr.design.actions.replace.info.CellInfo; import com.fr.design.actions.replace.info.CellInfo;
@ -47,7 +47,7 @@ public class ReplaceUtils {
* @return 返回公式中使用的数据集名称 * @return 返回公式中使用的数据集名称
*/ */
public static Set<String> getFormulaDependenceTables(String formula) { public static Set<String> getFormulaDependenceTables(String formula) {
return FormulaUtils.search(formula); return TableDataFormulaUtils.search4TableData(formula);
} }
@ -151,7 +151,7 @@ public class ReplaceUtils {
* @return 替换后的公式内容 * @return 替换后的公式内容
*/ */
public static String replaceFormula(String formula, List<TableReplacementEntity> entity) { public static String replaceFormula(String formula, List<TableReplacementEntity> 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<TableReplacementEntity> entity) { public static void replaceFormula(Formula formula, List<TableReplacementEntity> entity) {
String content = formula.getContent(); 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())) { if (TableDataFormulaType.needReplace(formulaInfo.getPureValue())) {
formulaInfo.setValue(formulaInfo, formulaInfo.setValue(formulaInfo,
formulaInfo.getPureValue(), formulaInfo.getPureValue(),
FormulaUtils.replace(formulaInfo.getPureValue(), entity), TableDataFormulaUtils.replace4TableData(formulaInfo.getPureValue(), entity),
new ArrayList<>()); new ArrayList<>());
} }
} }

22
designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/FormulaUtilsTest.java → 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 * @since 11.0
* Created on 2024/11/5 * Created on 2024/11/5
*/ */
public class FormulaUtilsTest extends TestCase { public class TableDataFormulaUtilsTest extends TestCase {
public void testSearch() { public void testSearch() {
String rowcount = "=ROWCOUNT(\"123\")"; String rowcount = "=ROWCOUNT(\"123\")";
Set<String> strings = new HashSet<>(); Set<String> strings = new HashSet<>();
strings.add("123"); strings.add("123");
Assert.assertEquals(FormulaUtils.search(rowcount), strings); Assert.assertEquals(TableDataFormulaUtils.search4TableData(rowcount), strings);
Set<String> errorSet = new HashSet<>(); Set<String> errorSet = new HashSet<>();
errorSet.add("1223"); errorSet.add("1223");
Assert.assertNotEquals(FormulaUtils.search(rowcount), errorSet); Assert.assertNotEquals(TableDataFormulaUtils.search4TableData(rowcount), errorSet);
String str = "=COLNAME(\"test-测试\",COLCOUNT(\"列数嵌套123\"))"; String str = "=COLNAME(\"test-测试\",COLCOUNT(\"列数嵌套123\"))";
Set<String> qiantao = new HashSet<>(); Set<String> qiantao = new HashSet<>();
qiantao.add("test-测试"); qiantao.add("test-测试");
qiantao.add("列数嵌套123"); 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\")))"; 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<String> qiantao2 = FormulaUtils.search(str2); Set<String> qiantao2 = TableDataFormulaUtils.search4TableData(str2);
Assert.assertTrue(qiantao2.contains("test-测试1")); Assert.assertTrue(qiantao2.contains("test-测试1"));
Assert.assertTrue(qiantao2.contains("test-测试2")); Assert.assertTrue(qiantao2.contains("test-测试2"));
Assert.assertTrue(qiantao2.contains("test-测试3")); Assert.assertTrue(qiantao2.contains("test-测试3"));
@ -51,7 +51,7 @@ public class FormulaUtilsTest extends TestCase {
entity.setNewName("222"); entity.setNewName("222");
List<TableReplacementEntity> entities = new ArrayList<>(); List<TableReplacementEntity> entities = new ArrayList<>();
entities.add(entity); entities.add(entity);
Assert.assertEquals(FormulaUtils.replace(rowcount, entities), "=ROWCOUNT(\"222\")"); Assert.assertEquals(TableDataFormulaUtils.replace4TableData(rowcount, entities), "=ROWCOUNT(\"222\")");
String colcount = "=COLCOUNT(\"test测试\")"; String colcount = "=COLCOUNT(\"test测试\")";
TableReplacementEntity entity1 = new TableReplacementEntity(); TableReplacementEntity entity1 = new TableReplacementEntity();
@ -59,7 +59,7 @@ public class FormulaUtilsTest extends TestCase {
entity1.setNewName("替换"); entity1.setNewName("替换");
List<TableReplacementEntity> entities1 = new ArrayList<>(); List<TableReplacementEntity> entities1 = new ArrayList<>();
entities1.add(entity1); entities1.add(entity1);
Assert.assertEquals(FormulaUtils.replace(colcount, entities1), "=COLCOUNT(\"替换\")"); Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colcount, entities1), "=COLCOUNT(\"替换\")");
String colname = "=COLNAME(\"test测试\")"; String colname = "=COLNAME(\"test测试\")";
TableReplacementEntity entity2 = new TableReplacementEntity(); TableReplacementEntity entity2 = new TableReplacementEntity();
@ -67,7 +67,7 @@ public class FormulaUtilsTest extends TestCase {
entity2.setNewName("替换123"); entity2.setNewName("替换123");
List<TableReplacementEntity> entities2 = new ArrayList<>(); List<TableReplacementEntity> entities2 = new ArrayList<>();
entities2.add(entity2); entities2.add(entity2);
Assert.assertEquals(FormulaUtils.replace(colname, entities2), "=COLNAME(\"替换123\")"); Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colname, entities2), "=COLNAME(\"替换123\")");
String TABLEDATAFIELDS = "=TABLEDATAFIELDS(\"test测试\")"; String TABLEDATAFIELDS = "=TABLEDATAFIELDS(\"test测试\")";
TableReplacementEntity entity3 = new TableReplacementEntity(); TableReplacementEntity entity3 = new TableReplacementEntity();
@ -75,7 +75,7 @@ public class FormulaUtilsTest extends TestCase {
entity3.setNewName("替换111"); entity3.setNewName("替换111");
List<TableReplacementEntity> entities3 = new ArrayList<>(); List<TableReplacementEntity> entities3 = new ArrayList<>();
entities3.add(entity3); 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-测试\")))"; 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(); TableReplacementEntity entity4 = new TableReplacementEntity();
@ -83,7 +83,7 @@ public class FormulaUtilsTest extends TestCase {
entity4.setNewName("test-测试的副本"); entity4.setNewName("test-测试的副本");
List<TableReplacementEntity> entities4 = new ArrayList<>(); List<TableReplacementEntity> entities4 = new ArrayList<>();
entities4.add(entity4); 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-测试\")))"; 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(entity6);
entities5.add(entity7); entities5.add(entity7);
entities5.add(entity8); 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-测试的副本\")))");
} }
} }
Loading…
Cancel
Save