From c6e07423f9e3529790cf58be1f81841a2b83a07f Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Thu, 21 Nov 2024 16:45:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-141247=20=E3=80=90FVS=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E6=9B=BF=E6=8D=A2=E3=80=91=E5=85=AC=E5=BC=8F?= =?UTF-8?q?ds1.select=E3=80=81group=E3=80=81find=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=90=8D=E4=B8=8D=E4=BC=9A=E8=A2=AB=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tabledata/TableDataFormulaUtils.java | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) 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 ffeabb95a2..955a44005e 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 @@ -3,9 +3,11 @@ package com.fr.design.actions.replace.action.content.tabledata; import com.fr.data.TableReplacementEntity; import com.fr.invoke.Reflect; import com.fr.log.FineLoggerFactory; +import com.fr.parser.Ambiguity; import com.fr.parser.BinaryExpression; import com.fr.parser.DatasetFunctionCall; import com.fr.parser.FunctionCall; +import com.fr.parser.RelationExpression; import com.fr.parser.StringLiteral; import com.fr.script.Calculator; import com.fr.stable.StringUtils; @@ -107,18 +109,7 @@ public class TableDataFormulaUtils { // 数据集名称 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); - } + replaceNode4DatasetFunctionCall(subNode, datasetFunctionCall, entities, parent); } for (TableReplacementEntity entity : entities) { if (StringUtils.equals(parent.toString(), entity.getOldName())) { @@ -130,17 +121,38 @@ public class TableDataFormulaUtils { } } - private static void replaceDatasetFunctionCall0(StringLiteral stringLiteral, DatasetFunctionCall datasetFunctionCall, List entities, StringBuilder parent) { + private static void replaceNode4DatasetFunctionCall(Node subNode, DatasetFunctionCall datasetFunctionCall, List entities, StringBuilder parent) { + // 嵌套普通公式 + if (subNode instanceof FunctionCall) { + replaceArgument4FunctionCall((FunctionCall) subNode, entities); + } else if (subNode instanceof Ambiguity) { + // 无嵌套,可以根据传进来的datasetFunctionCall进行替换 + // 这边产品确认只能替换无双引号的字段,因此是ambiguity而不是StringLiteral + Ambiguity ambiguity = (Ambiguity) subNode; + replaceDatasetFunctionCall0(ambiguity, datasetFunctionCall, entities, parent); + } else if (subNode instanceof DatasetFunctionCall) { + // 嵌套datasetFunctionCall,递归回来该方法继续往下 + DatasetFunctionCall datasetFunctionCall1 = (DatasetFunctionCall) subNode; + replaceArgument4DatasetFunctionCall(datasetFunctionCall1, entities); + } else if (subNode instanceof RelationExpression) { + Node left = ((RelationExpression) subNode).getLeft(); + Node right = ((RelationExpression) subNode).getRight(); + replaceNode4DatasetFunctionCall(left, datasetFunctionCall, entities, parent); + replaceNode4DatasetFunctionCall(right, datasetFunctionCall, entities, parent); + } + } + + private static void replaceDatasetFunctionCall0(Ambiguity ambiguity, DatasetFunctionCall datasetFunctionCall, List entities, StringBuilder parent) { try { TableDataFormulaType type = TableDataFormulaType.get(datasetFunctionCall.getFnName()); if (type != null) { - String name = stringLiteral.eval(Calculator.createCalculator()).toString(); + String name = ambiguity.toString(); for (TableReplacementEntity entity : entities) { if (StringUtils.equals(parent.toString(), entity.getOldName())) { // 如果是要替换的数据集 String field = entity.getTargetField(name); // 替换成匹配后的字段 - Reflect.on(stringLiteral).set(STATEMENT, field); + Reflect.on(ambiguity).set(STATEMENT, field); break; } } From b8e38a8ef4fe2eb046180bd28971ed367ee6907a Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Thu, 21 Nov 2024 17:27:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-141350=20=E3=80=90FVS=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E6=9B=BF=E6=8D=A2=E3=80=91=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?-=E5=8D=95=E5=85=83=E6=A0=BC-=E6=9D=A1=E4=BB=B6=E5=B1=9E?= =?UTF-8?q?=E6=80=A7-=E6=9D=A1=E4=BB=B6=E6=98=AF=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=97=EF=BC=8C=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/replace/utils/ReplaceUtils.java | 219 +++++++++++++++++- 1 file changed, 217 insertions(+), 2 deletions(-) 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 f7c4946eb6..786ca7c083 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 @@ -1,6 +1,8 @@ package com.fr.design.actions.replace.utils; import com.fr.base.Formula; +import com.fr.base.present.DictPresent; +import com.fr.base.present.Present; import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.web.ChartHyperPoplink; import com.fr.data.SimpleDSColumn; @@ -121,8 +123,18 @@ public class ReplaceUtils { * @return 报表块使用的数据集 */ public static Set getElementCaseDependenceTables(ElementCaseEditor elementCaseEditor) { - FormElementCaseProvider elementCase = elementCaseEditor.getElementCase(); - return elementCase.getCellTableDataSet(); + Set ans = new HashSet<>(); + FormElementCaseProvider provider = elementCaseEditor.getElementCase(); + if (provider instanceof ElementCase) { + // 非公式部分 + ans.addAll(searchTableDataWithOutFormula((ElementCase)provider)); + // 公式部分——理论上就只有单元格和控件(超链那些都包含) + List formulaInfos = getElementCaseFormulas((ElementCase) provider); + ans.addAll(searchFormulaInfos(formulaInfos)); + // 超链部分 + ans.addAll(searchElementCasJs((ElementCase)provider)); + } + return ans; } /** @@ -635,5 +647,208 @@ public class ReplaceUtils { } + /** + * ------------------------private search----------------------------------- + */ + + + private static Set searchElementCasJs(ElementCase elementCase) { + Set ans = new HashSet<>(); + List javaScripts = new ArrayList<>(); + // 替换通用元素 + Iterator cellIterator = elementCase.cellIterator(); + while (cellIterator.hasNext()) { + CellElement cell = (CellElement) cellIterator.next(); + javaScripts.addAll(SearchJSUtils.getJSDependenceTables(cell)); + } + ans.addAll(searchJs(javaScripts)); + return ans; + } + + private static Set searchJs(List javaScripts) { + Set ans = new HashSet<>(); + for (JavaScript javaScript : javaScripts) { + if (javaScript instanceof ChartHyperPoplink) { + ChartHyperPoplink chartHyperPoplink = (ChartHyperPoplink) javaScript; + if (chartHyperPoplink.getChartCollection() instanceof ChartCollection) { + ans.addAll((chartHyperPoplink.getChartCollection().getDataSetNames())); + } + } + } + return ans; + } + + private static Set searchFormulaInfos(List formulaInfos) { + Set ans = new HashSet<>(); + for (FormulaInfo formulaInfo : formulaInfos) { + ans.addAll(TableDataFormulaUtils.search4TableData(formulaInfo.getPureValue())); + } + return ans; + } + + private static Set searchTableDataWithOutFormula(ElementCase elementCase) { + Set ans = new HashSet<>(); + Iterator cellIterator = elementCase.cellIterator(); + while (cellIterator.hasNext()) { + CellElement cell = (CellElement) cellIterator.next(); + // 处理【形态、控件、数据字典】 + ans.addAll(searchPresentAndDictionary(cell)); + // 处理【单元格值】 + ans.addAll(searchCellValue(cell)); + // 处理【条件属性】 + ans.addAll(searchCellHighlight(cell)); + } + return ans; + } + + private static Set searchCellHighlight(CellElement cell) { + Set ans = new HashSet<>(); + if (cell instanceof TemplateCellElement) { + HighlightGroup group = ((TemplateCellElement) cell).getHighlightGroup(); + if (group != null) { + for (int i = 0 ; i < group.size(); i++) { + Highlight highlight = group.getHighlight(i); + ans.addAll(searchHighlight(highlight)); + } + } + } + return ans; + } + + private static Set searchHighlight(Highlight highlight) { + Set ans = new HashSet<>(); + if (highlight instanceof DefaultHighlight) { + DefaultHighlight defaultHighlight = (DefaultHighlight) highlight; + for (int i = 0 ; i < defaultHighlight.actionCount() ; i++) { + if (defaultHighlight.getHighlightAction(i) instanceof PresentHighlightAction) { + PresentHighlightAction action = (PresentHighlightAction) defaultHighlight.getHighlightAction(i); + ans.addAll(searchPresent(action.getPresent())); + } else if (defaultHighlight.getHighlightAction(i) instanceof WidgetHighlightAction) { + WidgetHighlightAction action = (WidgetHighlightAction) defaultHighlight.getHighlightAction(i); + ans.addAll(searchWidget(action.getWidget())); + } else if (defaultHighlight.getHighlightAction(i) instanceof HyperlinkHighlightAction) { + HyperlinkHighlightAction action = (HyperlinkHighlightAction) defaultHighlight.getHighlightAction(i); + NameJavaScriptGroup group = action.getHperlink(); + ans.addAll(searchNameJavaScriptGroup(group)); + } + } + } + return ans; + } + + private static Set searchNameJavaScriptGroup(NameJavaScriptGroup group) { + Set ans = new HashSet<>(); + if (group != null) { + for (int i = 0 ; i < group.size(); i++) { + NameJavaScript javaScript = group.getNameHyperlink(i); + if (javaScript.getJavaScript() instanceof ChartHyperPoplink) { + if (((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection() instanceof ChartCollection) { + ans.addAll((((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection().getDataSetNames())); + } + } + } + } + return ans; + } + + private static Set searchCellValue(CellElement cell) { + Set ans = new HashSet<>(); + Object value = cell.getValue(); + if (value instanceof DSColumn) { + // 查找【数据列】 + ans.add(((DSColumn) value).getDSName()); + // 查找【条件属性】 + ans.addAll(searchCondition(((DSColumn) value).getCondition())); + } else if (value instanceof ChartCollection) { + ans.addAll(((ChartCollection) value).getDataSetNames()); + } + return ans; + } + + private static Set searchCondition(Condition condition) { + Set ans = new HashSet<>(); + if (condition != null) { + //普通条件 + //1条条件 + if (condition instanceof CommonCondition) { + ans.addAll(searchCondition0((CommonCondition) condition)); + } + //N条条件 + if (condition instanceof ListCondition) { + for (int k = 0; k < ((ListCondition) condition).getJoinConditionCount(); k++) { + JoinCondition joinCondition = ((ListCondition) condition).getJoinCondition(k); + Condition obCondition = joinCondition.getCondition(); + if (obCondition != null) { + if (obCondition instanceof CommonCondition) { + ans.addAll(searchCondition0((CommonCondition) obCondition)); + } + } + } + } + } + return ans; + } + + private static Set searchCondition0(CommonCondition condition) { + Set ans = new HashSet<>(); + Compare compare = condition.getCompare(); + Object ob = compare.getValue(); + if (ob instanceof SimpleDSColumn) { + ans.add(((SimpleDSColumn) ob).getDsName()); + } + return ans; + } + + + private static Set searchPresentAndDictionary(CellElement cell) { + Set ans = new HashSet<>(); + TemplateCellElement cellElement = (TemplateCellElement) cell; + // 处理单元格的控件 + ans.addAll(searchWidget(cellElement.getWidget())); + // 处理形态 + ans.addAll(searchPresent(cellElement.getPresent())); + return ans; + } + + private static Set searchPresent(Present p) { + Set ans = new HashSet<>(); + if (!(p instanceof DictPresent)) { + return ans; + } + DictPresent dp = (DictPresent) p; + if (!(dp.getDictionary() instanceof TableDataDictionary)) { + return ans; + } + TableDataDictionary td = (TableDataDictionary) dp.getDictionary(); + if (!(td.getTableData() instanceof NameTableData)) { + return ans; + } + NameTableData nd = (NameTableData) td.getTableData(); + ans.add(nd.getName()); + return ans; + } + + private static Set searchWidget(Widget widget) { + Set ans = new HashSet<>(); + if (widget instanceof DictionaryContainer) { + DictionaryContainer db = (DictionaryContainer) widget; + if (db.getDictionary() instanceof TableDataDictionary) { + TableDataDictionary tdd = (TableDataDictionary) db.getDictionary(); + NameTableData ndd = (NameTableData) tdd.getTableData(); + if (ndd != null) { + ans.add(ndd.getName()); + } + } + } + if (widget instanceof DataControl) { + ValueInitializer value = ((DataControl) widget).getWidgetValue(); + if (value != null && value.getValue() instanceof DataBinding) { + DataBinding binding = (DataBinding) value.getValue(); + ans.add(binding.getDataSourceName()); + } + } + return ans; + } + } From a193674162c5f9642e3f63888e74c5f45a61d1d4 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Thu, 21 Nov 2024 17:38:19 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-141350=20=E3=80=90FVS=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E6=9B=BF=E6=8D=A2=E3=80=91=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?-=E5=8D=95=E5=85=83=E6=A0=BC-=E6=9D=A1=E4=BB=B6=E5=B1=9E?= =?UTF-8?q?=E6=80=A7-=E6=9D=A1=E4=BB=B6=E6=98=AF=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=88=97=EF=BC=8C=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/actions/replace/utils/ReplaceUtils.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 786ca7c083..a9ad21fd2e 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 @@ -778,10 +778,8 @@ public class ReplaceUtils { for (int k = 0; k < ((ListCondition) condition).getJoinConditionCount(); k++) { JoinCondition joinCondition = ((ListCondition) condition).getJoinCondition(k); Condition obCondition = joinCondition.getCondition(); - if (obCondition != null) { - if (obCondition instanceof CommonCondition) { - ans.addAll(searchCondition0((CommonCondition) obCondition)); - } + if (obCondition instanceof CommonCondition) { + ans.addAll(searchCondition0((CommonCondition) obCondition)); } } }