Browse Source
* commit '19c592e2edb2aa36db00bc57675223ea569a1a34': (40 commits) REPORT-140743 【数据集替换】下拉树和视图树的数据集替换后,实际并未生效 REPORT-140743 【数据集替换】下拉树和视图树的数据集替换后,实际并未生效 REPORT-129009 fix:FR标题翻译修改 REPORT-140678 公式使用ds.select,对ds替换数据集后公式没有更新 REPORT-140524 【FVS数据集替换】x3.0.0.1做的看板,图表数据和标题使用的模板和数据集数据,都被识别未使用 REPORT-140524 【FVS数据集替换】x3.0.0.1做的看板,图表数据和标题使用的模板和数据集数据,都被识别未使用 REPORT-140743 【数据集替换】下拉树和视图树的数据集替换后,实际并未生效 REPORT-140634 【数据集替换】下拉树和视图树的数据集替换都不行 REPORT-140453 【数据集替换】自定义校验的属性公式没有替换成功 REPORT-140299 【数据集替换】数据列-高级-自定义显示中,没有替换 REPORT-140371 【数据集替换】条件属性的形态-数据字典的数据集没有替换 REPORT-140563 【数据集替换】参数面板所有控件的控件值字段,都没有替换 REPORT-140564 【数据集替换】参数面板所有控件的数据字典的数据集,都没有替换 REPORT-140361 【数据集替换】图表的特效-图表超链悬浮图表的数据-数据集,没有替换 REPORT-140290 【FVS数据集替换】卸载再安装FVS插件,历史看板和新建看板,替换数据集按钮灰化 REPORT-140290 【FVS数据集替换】卸载再安装FVS插件,历史看板和新建看板,替换数据集按钮灰化 REPORT-140337 【数据集替换】报表填报属性-自定义提交的属性中没有替换 REPORT-140338 【数据集替换】报表填报属性-数据校验-不满足公式提示中,没有替换 REPORT-140231 【数据集替换】替换后,控件-事件-设置回调函数-回调函数-导出事件的参数公式未替换 REPORT-140237 【数据集替换】数据集替换后,数据列的列的替换没生效 ...final/11.0
superman
2 days ago
25 changed files with 1619 additions and 176 deletions
@ -0,0 +1,87 @@
|
||||
package com.fr.design.actions.replace.action.content.tabledata; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* 涉及数据集的公式类型枚举 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/11/5 |
||||
*/ |
||||
public enum TableDataFormulaType { |
||||
/** |
||||
* COLCOUNT公式 |
||||
*/ |
||||
COLCOUNT("COLCOUNT", 0), |
||||
/** |
||||
* CLONAME公式 |
||||
*/ |
||||
COLNAME("COLNAME", 0), |
||||
/** |
||||
* MAP公式 |
||||
*/ |
||||
MAP("MAP", 1), |
||||
/** |
||||
* ROWCOUNT公式 |
||||
*/ |
||||
ROWCOUNT("ROWCOUNT", 0), |
||||
/** |
||||
* TABLEDATAFILEDS公式 |
||||
*/ |
||||
TABLEDATAFIELDS("TABLEDATAFIELDS", 0), |
||||
/** |
||||
* VALUE公式或者是ds1.value(xxx)两种情况 |
||||
*/ |
||||
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; |
||||
|
||||
TableDataFormulaType(String name, int argumentIndex) { |
||||
this.argumentIndex = argumentIndex; |
||||
this.name = name; |
||||
} |
||||
|
||||
public int getArgumentIndex() { |
||||
return argumentIndex; |
||||
} |
||||
|
||||
/** |
||||
* 公式content是否需要替换处理 |
||||
*/ |
||||
public static boolean needReplace(String value) { |
||||
for (TableDataFormulaType type : TableDataFormulaType.values()) { |
||||
if (value.toUpperCase().contains(type.name().toUpperCase())) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取对应的公式类型 |
||||
*/ |
||||
public static TableDataFormulaType get(String functionName) { |
||||
for (TableDataFormulaType type : TableDataFormulaType.values()) { |
||||
if (StringUtils.equalsIgnoreCase(functionName, type.name())) { |
||||
return type; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,316 @@
|
||||
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.BinaryExpression; |
||||
import com.fr.parser.DatasetFunctionCall; |
||||
import com.fr.parser.FunctionCall; |
||||
import com.fr.parser.StringLiteral; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.script.Expression; |
||||
import com.fr.stable.script.Node; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 公式工具 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/11/5 |
||||
*/ |
||||
public class TableDataFormulaUtils { |
||||
|
||||
|
||||
private static final String LEFT_BRACKET = "${"; |
||||
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"; |
||||
|
||||
/** |
||||
* 从公式中寻找数据集名称 |
||||
* |
||||
* @param formula 公式的content |
||||
* @return 返回数据集名称集合 |
||||
*/ |
||||
public static Set<String> search4TableData(String formula) { |
||||
Set<String> result = new HashSet<>(); |
||||
for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) { |
||||
result.addAll(TableDataFormulaUtils.fetchArgument(formula, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex())); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取替换指定数据集后的公式全文 |
||||
* |
||||
* @param formula 公式content |
||||
* @param entities 替换信息 |
||||
* @return 替换后的全文 |
||||
*/ |
||||
public static String replace4TableData(String formula, List<TableReplacementEntity> entities) { |
||||
try { |
||||
Expression expression = Calculator.createCalculator().parse(formula); |
||||
TableDataFormulaUtils.replace0(expression, entities); |
||||
String ans = expression.toString(); |
||||
if (formula.startsWith(FORMULA_MARK) && !ans.startsWith(FORMULA_MARK)) { |
||||
return FORMULA_MARK + ans; |
||||
} else { |
||||
if (ans.startsWith(FORMULA_MARK)) { |
||||
return ans.substring(1); |
||||
} |
||||
} |
||||
return ans; |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
return formula; |
||||
} |
||||
} |
||||
|
||||
private static void replace0(Expression expression, List<TableReplacementEntity> entities) { |
||||
if (expression != null) { |
||||
Node node = expression.getConditionalExpression(); |
||||
if (node instanceof BinaryExpression) { |
||||
BinaryExpression binaryExpression = (BinaryExpression) node; |
||||
Node[] nodes = binaryExpression.getNodes(); |
||||
if (nodes != null) { |
||||
for (Node subNode : nodes) { |
||||
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); |
||||
} |
||||
} |
||||
} |
||||
} else if (node instanceof FunctionCall) { |
||||
FunctionCall functionCall = (FunctionCall) node; |
||||
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()); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 从公式(可能存在嵌套)中解析出某类型函数的第几个参数 |
||||
* |
||||
* @param formula 公式 |
||||
* @param functionName 函数名 |
||||
* @param argumentIndex 参数位置 |
||||
* @return 对应参数位置的值 |
||||
*/ |
||||
public static List<String> fetchArgument(String formula, String functionName, int argumentIndex) { |
||||
List<String> result = new ArrayList<>(); |
||||
try { |
||||
Expression expression = Calculator.createCalculator().parse(formula); |
||||
if (expression != null) { |
||||
Node node = expression.getConditionalExpression(); |
||||
if (node instanceof BinaryExpression) { |
||||
BinaryExpression binaryExpression = (BinaryExpression) node; |
||||
Node[] nodes = binaryExpression.getNodes(); |
||||
if (nodes != null) { |
||||
for (Node subNode : nodes) { |
||||
if (subNode instanceof FunctionCall) { |
||||
FunctionCall functionCall = (FunctionCall) subNode; |
||||
result.addAll(TableDataFormulaUtils.fetchArgument(functionCall, functionName, argumentIndex)); |
||||
} else if (subNode instanceof DatasetFunctionCall) { |
||||
DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) subNode; |
||||
result.addAll(TableDataFormulaUtils.fetchArgument(datasetFunctionCall, functionName)); |
||||
} |
||||
} |
||||
} |
||||
} else if (node instanceof FunctionCall) { |
||||
FunctionCall functionCall = (FunctionCall) node; |
||||
result.addAll(TableDataFormulaUtils.fetchArgument(functionCall, functionName, argumentIndex)); |
||||
} else if (node instanceof DatasetFunctionCall) { |
||||
DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) node; |
||||
result.addAll(TableDataFormulaUtils.fetchArgument(datasetFunctionCall, functionName)); |
||||
} |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
private static List<String> fetchArgument(DatasetFunctionCall datasetFunctionCall, String functionName) { |
||||
List<String> result = new ArrayList<>(); |
||||
Node[] subNodes = datasetFunctionCall.getArguments(); |
||||
String sourceName = datasetFunctionCall.getSourceName(); |
||||
if (StringUtils.isNotEmpty(functionName)) { |
||||
result.add(sourceName); |
||||
} |
||||
if (subNodes != null) { |
||||
// 遍历子公式
|
||||
for (Object subNode : subNodes) { |
||||
if (subNode instanceof FunctionCall) { |
||||
for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) { |
||||
result.addAll(TableDataFormulaUtils.fetchArgument((FunctionCall) subNode, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex())); |
||||
} |
||||
} else if (subNode instanceof DatasetFunctionCall) { |
||||
result.addAll(fetchArgument((DatasetFunctionCall) subNode, functionName)); |
||||
} |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
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) { |
||||
replaceArgument4FunctionCall((FunctionCall) subNode, entities); |
||||
} |
||||
if (subNode instanceof StringLiteral) { |
||||
StringLiteral stringLiteral = (StringLiteral) subNode; |
||||
replaceFunctionCall0(i, stringLiteral, functionCall, entities, 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) { |
||||
String name = stringLiteral.eval(Calculator.createCalculator()).toString(); |
||||
for (TableReplacementEntity entity : entities) { |
||||
// 数据集名
|
||||
if (i == type.getArgumentIndex()) { |
||||
if (StringUtils.equals(name, entity.getOldName())) { |
||||
// 替换数据集名
|
||||
parent.append(name); |
||||
Reflect.on(stringLiteral).set(STATEMENT, entity.getNewName()); |
||||
break; |
||||
} |
||||
} else { |
||||
String field = entity.getTargetField(name); |
||||
// 如果是需要匹配的字段
|
||||
// 要走到字段匹配,就必须先经过数据集名匹配,目前所有公式都是数据集在前,字段在后
|
||||
if (StringUtils.isNotEmpty(field) && StringUtils.isNotEmpty(parent.toString())) { |
||||
// 替换成匹配后的字段
|
||||
Reflect.on(stringLiteral).set(STATEMENT, field); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().debug(e, e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 从公式(可能存在嵌套)中解析出某类型函数的第几个参数 |
||||
* |
||||
* @param functionCall 公式 |
||||
* @param functionName 函数名 |
||||
* @param argumentIndex 参数位置 |
||||
* @return 对应参数位置的值 |
||||
*/ |
||||
public static List<String> fetchArgument(FunctionCall functionCall, String functionName, int argumentIndex) { |
||||
List<String> result = new ArrayList<>(); |
||||
Node[] subNodes = functionCall.getArguments(); |
||||
if (subNodes != null) { |
||||
// 遍历子公式
|
||||
for (int i = 0; i < subNodes.length; i++) { |
||||
Object subNode = subNodes[i]; |
||||
if (i == argumentIndex && subNode instanceof StringLiteral && StringUtils.equalsIgnoreCase(functionCall.getName(), functionName)) { |
||||
StringLiteral stringLiteral = (StringLiteral) subNode; |
||||
try { |
||||
result.add(stringLiteral.eval(Calculator.createCalculator()).toString()); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().debug(e, e.getMessage()); |
||||
} |
||||
continue; |
||||
} |
||||
if (subNode instanceof FunctionCall) { |
||||
for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) { |
||||
result.addAll(TableDataFormulaUtils.fetchArgument((FunctionCall) subNode, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex())); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 通过${content}格式获取公式内容 |
||||
* |
||||
* @param formula 原公式值 |
||||
* @return 最终公式值 |
||||
*/ |
||||
public static String getFormulaPureContent(String formula) { |
||||
if (formula.startsWith(LEFT_BRACKET) && formula.endsWith(RIGHT_BRACKET)) { |
||||
return formula.substring(LEFT_BRACKET.length() + 1, formula.length() - 1); |
||||
} else { |
||||
return formula; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,639 @@
|
||||
package com.fr.design.actions.replace.utils; |
||||
|
||||
import com.fr.base.Formula; |
||||
import com.fr.chart.chartattr.ChartCollection; |
||||
import com.fr.chart.web.ChartHyperPoplink; |
||||
import com.fr.data.SimpleDSColumn; |
||||
import com.fr.data.TableReplacementEntity; |
||||
import com.fr.data.condition.CommonCondition; |
||||
import com.fr.data.condition.JoinCondition; |
||||
import com.fr.data.condition.ListCondition; |
||||
import com.fr.data.core.Compare; |
||||
import com.fr.data.impl.NameTableData; |
||||
import com.fr.data.impl.TableDataDictionary; |
||||
import com.fr.data.impl.TreeNodeAttr; |
||||
import com.fr.data.impl.TreeNodeWrapper; |
||||
import com.fr.design.actions.replace.action.content.cell.SearchCellAction; |
||||
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.js.SearchJSManager; |
||||
import com.fr.design.actions.replace.action.content.tabledata.TableDataFormulaType; |
||||
import com.fr.design.actions.replace.action.content.tabledata.TableDataFormulaUtils; |
||||
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.FormulaInfo; |
||||
import com.fr.design.actions.replace.info.WidgetInfo; |
||||
import com.fr.design.actions.replace.info.base.ITContent; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.form.FormElementCaseProvider; |
||||
import com.fr.form.data.DataBinding; |
||||
import com.fr.form.ui.DataControl; |
||||
import com.fr.form.ui.DictionaryContainer; |
||||
import com.fr.form.ui.ElementCaseEditor; |
||||
import com.fr.form.ui.TreeEditor; |
||||
import com.fr.form.ui.Widget; |
||||
import com.fr.form.ui.concept.data.ValueInitializer; |
||||
import com.fr.form.ui.tree.LayerConfig; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.data.Condition; |
||||
import com.fr.general.data.TableDataColumn; |
||||
import com.fr.js.JavaScript; |
||||
import com.fr.js.NameJavaScript; |
||||
import com.fr.js.NameJavaScriptGroup; |
||||
import com.fr.main.impl.WorkBook; |
||||
import com.fr.main.parameter.ReportParameterAttr; |
||||
import com.fr.report.cell.CellElement; |
||||
import com.fr.report.cell.FloatElement; |
||||
import com.fr.report.cell.TemplateCellElement; |
||||
import com.fr.report.cell.cellattr.core.group.DSColumn; |
||||
import com.fr.report.cell.cellattr.highlight.DefaultHighlight; |
||||
import com.fr.report.cell.cellattr.highlight.Highlight; |
||||
import com.fr.report.cell.cellattr.highlight.HighlightGroup; |
||||
import com.fr.report.cell.cellattr.highlight.HyperlinkHighlightAction; |
||||
import com.fr.report.cell.cellattr.highlight.PresentHighlightAction; |
||||
import com.fr.report.cell.cellattr.highlight.WidgetHighlightAction; |
||||
import com.fr.report.elementcase.ElementCase; |
||||
import com.fr.report.report.Report; |
||||
import com.fr.report.utils.ElementCaseHelper; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashSet; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 数据集查找替换工具 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/11/4 |
||||
*/ |
||||
public class ReplaceUtils { |
||||
/** |
||||
* ----------------------------------------------查找部分-------------------------------------------------- |
||||
*/ |
||||
|
||||
/** |
||||
* 获取公式里使用的数据集 |
||||
* |
||||
* @param formula 公式内容 |
||||
* @return 返回公式中使用的数据集名称 |
||||
*/ |
||||
public static Set<String> getFormulaDependenceTables(String formula) { |
||||
return TableDataFormulaUtils.search4TableData(formula); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取图表块里使用的数据集(不包含公式里的) |
||||
* |
||||
* @param chartCollection 图表对象 |
||||
* @return 使用的数据集名称 |
||||
*/ |
||||
public static Set<String> getChartDependenceTables(ChartCollection chartCollection) { |
||||
return chartCollection.getDataSetNames(); |
||||
} |
||||
|
||||
/** |
||||
* 获取图表里使用的公式 |
||||
* |
||||
* @param chartCollection 图表对象 |
||||
* @return 图表公式集合 |
||||
*/ |
||||
public static Set<String> getChartDependenceFormulas(ChartCollection chartCollection) { |
||||
List<FormulaInfo> formulaInfos = new ArrayList<>(); |
||||
SearchChartCollectionFormulaAction.getInstance().searchChartCollectionFormula(formulaInfos, new ITContent(), chartCollection); |
||||
Set<String> ans = new HashSet<>(); |
||||
for (FormulaInfo formulaInfo : formulaInfos) { |
||||
ans.add(formulaInfo.getContent().getReplaceObject().toString()); |
||||
} |
||||
return ans; |
||||
} |
||||
|
||||
/** |
||||
* 获取报表块里使用的数据集(不包含公式里的) |
||||
* |
||||
* @param elementCaseEditor 报表块 |
||||
* @return 报表块使用的数据集 |
||||
*/ |
||||
public static Set<String> getElementCaseDependenceTables(ElementCaseEditor elementCaseEditor) { |
||||
FormElementCaseProvider elementCase = elementCaseEditor.getElementCase(); |
||||
return elementCase.getCellTableDataSet(); |
||||
} |
||||
|
||||
/** |
||||
* 获取报表块里使用的公式 |
||||
* |
||||
* @param elementCase 报表块 |
||||
* @return 公式集合 |
||||
*/ |
||||
public static Set<String> getElementCaseDependenceFormulas(ElementCase elementCase) { |
||||
List<FormulaInfo> formulaInfos = getElementCaseFormulas(elementCase); |
||||
Set<String> ans = new HashSet<>(); |
||||
for (FormulaInfo formulaInfo : formulaInfos) { |
||||
ans.add(formulaInfo.getContent().getReplaceObject().toString()); |
||||
} |
||||
return ans; |
||||
} |
||||
|
||||
/** |
||||
* 获取CPT里使用的数据集(不包含公式里的) |
||||
* |
||||
* @param template 模板 |
||||
* @return 数据集名字集合 |
||||
*/ |
||||
public static Set<String> getCptDependenceTables(JTemplate template) { |
||||
Set<String> ans = new HashSet<>(); |
||||
if (template.getTarget() instanceof WorkBook) { |
||||
WorkBook workBook = (WorkBook) template.getTarget(); |
||||
Iterator<String> iterator = workBook.getTableDataNameIterator(); |
||||
while (iterator.hasNext()) { |
||||
String tableName = iterator.next(); |
||||
ans.add(tableName); |
||||
} |
||||
} |
||||
return ans; |
||||
} |
||||
|
||||
/** |
||||
* 获取CPT里使用的公式 |
||||
* |
||||
* @param template 包含workbook的Jtemplate |
||||
* @return 公式集合 |
||||
*/ |
||||
public static Set<String> getCptDependenceFormulas(JTemplate template) { |
||||
SearchFormulaManager.getInstance().search4Infos(template); |
||||
List<FormulaInfo> formulaInfos = SearchFormulaManager.getInstance().getFormulaInfos(); |
||||
Set<String> ans = new HashSet<>(); |
||||
for (FormulaInfo formulaInfo : formulaInfos) { |
||||
ans.add(formulaInfo.getContent().getReplaceObject().toString()); |
||||
} |
||||
return ans; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* ----------------------------------------------替换部分-------------------------------------------------- |
||||
*/ |
||||
|
||||
/** |
||||
* 替换公式里的数据集 |
||||
* |
||||
* @param formula 公式 |
||||
* @param entity 替换信息 |
||||
* @return 替换后的公式内容 |
||||
*/ |
||||
public static String replaceFormula(String formula, List<TableReplacementEntity> entity) { |
||||
return TableDataFormulaUtils.replace4TableData(formula, entity); |
||||
} |
||||
|
||||
/** |
||||
* 替换公式里的数据集 |
||||
* |
||||
* @param formula 公式 |
||||
* @param entity 替换信息 |
||||
*/ |
||||
public static void replaceFormula(Formula formula, List<TableReplacementEntity> entity) { |
||||
String content = formula.getContent(); |
||||
formula.setContent(TableDataFormulaUtils.replace4TableData(content, entity)); |
||||
} |
||||
|
||||
/** |
||||
* 替换图表里使用的数据集(包含公式里的) |
||||
* |
||||
* @param chartCollection 图表对象 |
||||
* @param entities 替换信息 |
||||
*/ |
||||
public static void replaceChart(ChartCollection chartCollection, List<TableReplacementEntity> entities) { |
||||
// 非公式部分
|
||||
chartCollection.replaceTableData(entities); |
||||
// 公式部分
|
||||
List<FormulaInfo> formulaInfos = new ArrayList<>(); |
||||
SearchChartCollectionFormulaAction.getInstance().searchChartCollectionFormula(formulaInfos, new ITContent(), chartCollection); |
||||
replaceFormulaInfos(formulaInfos, entities); |
||||
// 超链部分
|
||||
replaceChartJs(chartCollection, entities); |
||||
} |
||||
|
||||
/** |
||||
* 替换报表块里使用的数据集(包含公式里的) |
||||
* |
||||
* @param elementCase 报表块控件 |
||||
* @param entities 替换信息 |
||||
*/ |
||||
public static void replaceElementCase(ElementCase elementCase, List<TableReplacementEntity> entities) { |
||||
// 非公式部分
|
||||
replaceTableDataWithOutFormula(elementCase, entities); |
||||
// 公式部分——理论上就只有单元格和控件(超链那些都包含)
|
||||
List<FormulaInfo> formulaInfos = getElementCaseFormulas(elementCase); |
||||
replaceFormulaInfos(formulaInfos, entities); |
||||
// 超链部分
|
||||
replaceElementCasJs(elementCase, entities); |
||||
|
||||
} |
||||
|
||||
|
||||
/** |
||||
* 替换CPT使用的数据集(包含公式里的) |
||||
* |
||||
* @param template cpt对应的JTemplate |
||||
* @param entity 替换信息 |
||||
*/ |
||||
public static void replaceCpt(JTemplate template, List<TableReplacementEntity> entity) { |
||||
if (template.getTarget() instanceof WorkBook) { |
||||
WorkBook workBook = (WorkBook) template.getTarget(); |
||||
// 参数面板
|
||||
replaceWorkBookPara(workBook, entity); |
||||
// 主体非公式部分替换
|
||||
replaceWorkBook(workBook, entity); |
||||
// 公式部分
|
||||
SearchFormulaManager.getInstance().search4Infos(template); |
||||
List<FormulaInfo> formulaInfos = SearchFormulaManager.getInstance().getFormulaInfos(); |
||||
replaceFormulaInfos(formulaInfos, entity); |
||||
// 超链部分
|
||||
replaceTemplateJs(template, entity); |
||||
// 触发响应
|
||||
template.fireTargetModified(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* ----------------------------------------------private-------------------------------------------------- |
||||
*/ |
||||
private static void replaceWorkBookPara(WorkBook workBook, List<TableReplacementEntity> entity) { |
||||
ReportParameterAttr attr = workBook.getReportParameterAttr(); |
||||
if (attr != null && attr.getParameterUI() != null) { |
||||
Widget[] widgets = attr.getParameterUI().getAllWidgets(); |
||||
for (Widget widget : widgets) { |
||||
replaceWidget(widget, entity); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
private static void replaceTemplateJs(JTemplate template, List<TableReplacementEntity> entity) { |
||||
List<JavaScript> javaScripts = SearchJSManager.getInstance().getTemplateJSDependenceTables(template); |
||||
replaceJs(javaScripts, entity); |
||||
} |
||||
|
||||
private static void replaceChartJs(ChartCollection chartCollection, List<TableReplacementEntity> entities) { |
||||
List<JavaScript> scripts = new ArrayList<>(); |
||||
List<NameJavaScript> nameJavaScripts = SearchJSUtils.getChartJavaScript(chartCollection); |
||||
for(NameJavaScript javaScript : nameJavaScripts) { |
||||
if (javaScript.getJavaScript() instanceof ChartHyperPoplink) { |
||||
scripts.add(javaScript.getJavaScript()); |
||||
} |
||||
} |
||||
replaceJs(scripts, entities); |
||||
} |
||||
|
||||
private static void replaceElementCasJs(ElementCase elementCase, List<TableReplacementEntity> entities) { |
||||
if (elementCase == null) { |
||||
return; |
||||
} |
||||
List<JavaScript> javaScripts = new ArrayList<>(); |
||||
// 替换悬浮元素
|
||||
Iterator floatIterator = elementCase.floatIterator(); |
||||
while (floatIterator.hasNext()) { |
||||
FloatElement floatCell = (FloatElement) floatIterator.next(); |
||||
javaScripts.addAll(SearchJSUtils.getJSDependenceTables(floatCell)); |
||||
} |
||||
// 替换通用元素
|
||||
Iterator cellIterator = elementCase.cellIterator(); |
||||
while (cellIterator.hasNext()) { |
||||
CellElement cell = (CellElement) cellIterator.next(); |
||||
javaScripts.addAll(SearchJSUtils.getJSDependenceTables(cell)); |
||||
} |
||||
replaceJs(javaScripts, entities); |
||||
} |
||||
|
||||
private static void replaceCellHighlight(CellElement cell, List<TableReplacementEntity> entities) { |
||||
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); |
||||
replaceHighlight(highlight, entities); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static void replaceHighlight(Highlight highlight, List<TableReplacementEntity> entities) { |
||||
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); |
||||
ElementCaseHelper.replacePresent(action.getPresent(), entities); |
||||
} else if (defaultHighlight.getHighlightAction(i) instanceof WidgetHighlightAction) { |
||||
WidgetHighlightAction action = (WidgetHighlightAction) defaultHighlight.getHighlightAction(i); |
||||
replaceWidget(action.getWidget(), entities); |
||||
} else if (defaultHighlight.getHighlightAction(i) instanceof HyperlinkHighlightAction) { |
||||
HyperlinkHighlightAction action = (HyperlinkHighlightAction) defaultHighlight.getHighlightAction(i); |
||||
NameJavaScriptGroup group = action.getHperlink(); |
||||
dealNameJavaScriptGroup(group, entities); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static void dealNameJavaScriptGroup(NameJavaScriptGroup group, List<TableReplacementEntity> entities) { |
||||
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) { |
||||
replaceChart((ChartCollection) ((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection(), entities); |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
private static void replaceJs(List<JavaScript> javaScripts, List<TableReplacementEntity> entity) { |
||||
for (JavaScript javaScript : javaScripts) { |
||||
if (javaScript instanceof ChartHyperPoplink) { |
||||
ChartHyperPoplink chartHyperPoplink = (ChartHyperPoplink) javaScript; |
||||
if (chartHyperPoplink.getChartCollection() instanceof ChartCollection) { |
||||
replaceChart((ChartCollection) chartHyperPoplink.getChartCollection(), entity); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
private static void replaceWorkBook(WorkBook workBook, List<TableReplacementEntity> entity) { |
||||
if (acceptTableReplacement(entity)) { |
||||
for (int i = 0; i < workBook.getReportCount(); i++) { |
||||
Report report = workBook.getReport(i); |
||||
if (report != null) { |
||||
Iterator it = report.iteratorOfElementCase(); |
||||
while (it.hasNext()) { |
||||
ElementCase elementCase = (ElementCase) it.next(); |
||||
replaceTableDataWithOutFormula(elementCase, entity); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static boolean acceptTableReplacement(List<TableReplacementEntity> entities) { |
||||
for (TableReplacementEntity entity : entities) { |
||||
if (entity == null) { |
||||
return false; |
||||
} |
||||
String newName = entity.getNewName(); |
||||
String oldName = entity.getOldName(); |
||||
if (StringUtils.isEmpty(newName) || StringUtils.isEmpty(oldName)) { |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
private static void replaceFormulaInfos(List<FormulaInfo> formulaInfos, List<TableReplacementEntity> entity) { |
||||
for (FormulaInfo formulaInfo : formulaInfos) { |
||||
if (TableDataFormulaType.needReplace(formulaInfo.getPureValue())) { |
||||
formulaInfo.setValue(formulaInfo, |
||||
formulaInfo.getPureValue(), |
||||
TableDataFormulaUtils.replace4TableData(formulaInfo.getPureValue(), entity), |
||||
new ArrayList<>()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static List<FormulaInfo> getElementCaseFormulas(ElementCase elementCase) { |
||||
List<CellInfo> cellInfos = new ArrayList<>(); |
||||
List<FormulaInfo> formulaInfos = new ArrayList<>(); |
||||
List<WidgetInfo> widgetInfos = new ArrayList<>(); |
||||
SearchCellAction.getInstance().getCellInfoFromElementCase(elementCase, cellInfos, new ITContent()); |
||||
SearchCellFormulaAction.getInstance().searchFormulaFromCellInfos(cellInfos, formulaInfos); |
||||
SearchWidgetAction.getInstance().searchCellWidget(widgetInfos, cellInfos); |
||||
for (WidgetInfo widgetInfo : widgetInfos) { |
||||
SearchWidgetFormulaAction.getInstance().searchFormulaFromWidgetInfos(widgetInfo, formulaInfos); |
||||
} |
||||
return formulaInfos; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 替换数据集 |
||||
* |
||||
* @param elementCase 可以是报表块、组件、WorkBook... |
||||
* @param entity 数据集替换信息 |
||||
*/ |
||||
private static void replaceTableDataWithOutFormula(ElementCase elementCase, List<TableReplacementEntity> entity) { |
||||
if (elementCase == null) { |
||||
return; |
||||
} |
||||
|
||||
// -------非公式部分-------
|
||||
// 替换悬浮元素
|
||||
replaceFloatCell(elementCase, entity); |
||||
// 替换通用元素
|
||||
replaceNormalCell(elementCase, entity); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 替换通用元素,主要是单元格的各个地方 |
||||
* |
||||
* <li>单元格形态</li> |
||||
* <li>单元格控件</li> |
||||
* <li>单元格数据字典</li> |
||||
* <li>单元格值</li> |
||||
* |
||||
* @param elementCase |
||||
* @param entity |
||||
*/ |
||||
private static void replaceNormalCell(ElementCase elementCase, List<TableReplacementEntity> entity) { |
||||
Iterator cellIterator = elementCase.cellIterator(); |
||||
|
||||
while (cellIterator.hasNext()) { |
||||
CellElement cell = (CellElement) cellIterator.next(); |
||||
// 处理【形态、控件、数据字典】
|
||||
replacePresentAndDictionary(cell, entity); |
||||
// 处理【单元格值】
|
||||
replaceCellValue(cell, entity); |
||||
// 处理【条件属性】
|
||||
replaceCellHighlight(cell, entity); |
||||
} |
||||
} |
||||
|
||||
private static void replaceCellValue(CellElement cell, List<TableReplacementEntity> entity) { |
||||
Object value = cell.getValue(); |
||||
if (value instanceof DSColumn) { |
||||
// 替换【数据列】
|
||||
replaceDSColumn( (DSColumn) value, entity); |
||||
// 替换【条件属性】
|
||||
replaceCondition(((DSColumn) value).getCondition(), entity); |
||||
} else if (value instanceof ChartCollection) { |
||||
((ChartCollection) value).replaceTableData(entity); |
||||
replaceChartJs((ChartCollection) value, entity); |
||||
} |
||||
} |
||||
|
||||
private static void replaceCondition(Condition condition, List<TableReplacementEntity> entity) { |
||||
if (condition != null) { |
||||
//公式条件不需要修改,里面不会涉及到,有问题再加
|
||||
//普通条件
|
||||
//1条条件
|
||||
if (condition instanceof CommonCondition) { |
||||
dealWithTableDataNameChange((CommonCondition) condition, entity); |
||||
} |
||||
//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) { |
||||
dealWithTableDataNameChange((CommonCondition) obCondition, entity); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static void dealWithTableDataNameChange(CommonCondition condition, List<TableReplacementEntity> entities) { |
||||
Compare compare = condition.getCompare(); |
||||
Object ob = compare.getValue(); |
||||
if (ob instanceof SimpleDSColumn) { |
||||
for (TableReplacementEntity entity : entities) { |
||||
if (ComparatorUtils.equals(((SimpleDSColumn) ob).getDsName(), entity.getOldName())) { |
||||
((SimpleDSColumn) ob).setDsName(entity.getNewName()); |
||||
((SimpleDSColumn) ob).setColumn(TableDataColumn.createColumn(entity.getTargetField(TableDataColumn.getColumnName(((SimpleDSColumn) ob).getColumn())))); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
private static void replaceDSColumn(DSColumn dsColumn, List<TableReplacementEntity> entities) { |
||||
for (TableReplacementEntity entity : entities) { |
||||
if (ComparatorUtils.equals(dsColumn.getDSName(), entity.getOldName())) { |
||||
// 数据集替换
|
||||
dsColumn.setDSName(entity.getNewName()); |
||||
// 数据集字段替换
|
||||
dsColumn.setColumn(TableDataColumn.createColumn(entity.getTargetField(dsColumn.getColumnName()))); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static void replacePresentAndDictionary(CellElement cell, List<TableReplacementEntity> entities) { |
||||
TemplateCellElement cellElement = (TemplateCellElement) cell; |
||||
// 处理单元格的控件
|
||||
replaceWidget(cellElement.getWidget(), entities); |
||||
// 处理形态
|
||||
ElementCaseHelper.replacePresent(cellElement.getPresent(), entities); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 处理控件 |
||||
* |
||||
* @param widget 控件 |
||||
* @param entities 替换信息 |
||||
*/ |
||||
private static void replaceWidget(Widget widget, List<TableReplacementEntity> entities) { |
||||
if (widget instanceof DictionaryContainer) { |
||||
DictionaryContainer db = (DictionaryContainer) widget; |
||||
if (widget instanceof TreeEditor) { |
||||
Object config = ((TreeEditor) widget).getBuildModelConfig(); |
||||
replaceTreeConfig(config, entities); |
||||
((TreeEditor) widget).setBuildModelConfig(config); |
||||
} |
||||
if (db.getDictionary() instanceof TableDataDictionary) { |
||||
TableDataDictionary tdd = (TableDataDictionary) db.getDictionary(); |
||||
NameTableData ndd = (NameTableData) tdd.getTableData(); |
||||
// 控件持有的数据字典也得处理
|
||||
ElementCaseHelper.replaceTableDataDictionary(tdd, ndd, entities); |
||||
} |
||||
} |
||||
if (widget instanceof DataControl) { |
||||
ValueInitializer value = ((DataControl) widget).getWidgetValue(); |
||||
if (value != null && value.getValue() instanceof DataBinding) { |
||||
DataBinding binding = (DataBinding) value.getValue(); |
||||
for (TableReplacementEntity entity : entities) { |
||||
if (StringUtils.equals(entity.getOldName(), binding.getDataSourceName())) { |
||||
value.setValue(new DataBinding(entity.getNewName(), entity.getTargetField(binding.getDataBindingKey()))); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 处理树结构的config |
||||
* |
||||
* @param config 树结构配置 |
||||
* @param entities 替换信息 |
||||
*/ |
||||
public static void replaceTreeConfig(Object config, List<TableReplacementEntity> entities) { |
||||
if (config instanceof LayerConfig[]) { |
||||
LayerConfig[] layerConfigs = (LayerConfig[]) config; |
||||
dealWithLayerConfigs(layerConfigs, entities); |
||||
} else if (config instanceof TreeNodeWrapper) { |
||||
TreeNodeWrapper wrapper = (TreeNodeWrapper) config; |
||||
dealWithTreeNodeWrapper(wrapper, entities); |
||||
} else if (config instanceof TableDataDictionary) { |
||||
TableDataDictionary tableDataDictionary = (TableDataDictionary) config; |
||||
ElementCaseHelper.replaceTableDataDictionary(tableDataDictionary, (NameTableData) tableDataDictionary.getTableData(), entities); |
||||
} |
||||
} |
||||
|
||||
private static void dealWithTreeNodeWrapper(TreeNodeWrapper wrapper, List<TableReplacementEntity> entities) { |
||||
for (TreeNodeAttr attr : wrapper.getTreeNodeAttrs()) { |
||||
if (attr.getDictionary() instanceof TableDataDictionary) { |
||||
TableDataDictionary tableDataDictionary = (TableDataDictionary) attr.getDictionary(); |
||||
ElementCaseHelper.replaceTableDataDictionary(tableDataDictionary, (NameTableData) tableDataDictionary.getTableData(), entities); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static void dealWithLayerConfigs(LayerConfig[] layerConfigs, List<TableReplacementEntity> entities) { |
||||
for (LayerConfig layerConfig : layerConfigs) { |
||||
if (layerConfig.getDictionary() != null ) { |
||||
for (TableReplacementEntity entity : entities) { |
||||
if (layerConfig.getTableData() instanceof NameTableData && StringUtils.equals(layerConfig.getTableData().getName(), entity.getOldName())) { |
||||
layerConfig.setTableData(new NameTableData(entity.getNewName())); |
||||
layerConfig.setViewColumn(entity.getTargetIndex(layerConfig.getViewColumn())); |
||||
layerConfig.setModelColumn(entity.getTargetIndex(layerConfig.getModelColumn())); |
||||
} |
||||
} |
||||
ElementCaseHelper.replaceTableDataDictionary(layerConfig.getDictionary(), (NameTableData) layerConfig.getDictionary().getTableData(), entities); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 替换悬浮元素中的数据集 |
||||
* |
||||
* @param elementCase 组件 |
||||
* @param entities 替换信息 |
||||
*/ |
||||
private static void replaceFloatCell(ElementCase elementCase, List<TableReplacementEntity> entities) { |
||||
Iterator floatIterator = elementCase.floatIterator(); |
||||
while (floatIterator.hasNext()) { |
||||
FloatElement floatCell = (FloatElement) floatIterator.next(); |
||||
Object value = floatCell.getValue(); |
||||
if (value instanceof ChartCollection) { |
||||
((ChartCollection) value).replaceTableData(entities); |
||||
replaceChartJs((ChartCollection) value, entities); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,114 @@
|
||||
package com.fr.design.actions.replace.action.content.tabledata; |
||||
|
||||
import com.fr.data.TableReplacementEntity; |
||||
import junit.framework.TestCase; |
||||
import org.junit.Assert; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashSet; |
||||
import java.util.List; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* 公式工具类的单测 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @since 11.0 |
||||
* Created on 2024/11/5 |
||||
*/ |
||||
public class TableDataFormulaUtilsTest extends TestCase { |
||||
|
||||
public void testSearch() { |
||||
String rowcount = "=ROWCOUNT(\"123\")"; |
||||
Set<String> strings = new HashSet<>(); |
||||
strings.add("123"); |
||||
Assert.assertEquals(TableDataFormulaUtils.search4TableData(rowcount), strings); |
||||
Set<String> errorSet = new HashSet<>(); |
||||
errorSet.add("1223"); |
||||
Assert.assertNotEquals(TableDataFormulaUtils.search4TableData(rowcount), errorSet); |
||||
String str = "=COLNAME(\"test-测试\",COLCOUNT(\"列数嵌套123\"))"; |
||||
Set<String> qiantao = new HashSet<>(); |
||||
qiantao.add("test-测试"); |
||||
qiantao.add("列数嵌套123"); |
||||
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<String> qiantao2 = TableDataFormulaUtils.search4TableData(str2); |
||||
Assert.assertTrue(qiantao2.contains("test-测试1")); |
||||
Assert.assertTrue(qiantao2.contains("test-测试2")); |
||||
Assert.assertTrue(qiantao2.contains("test-测试3")); |
||||
Assert.assertTrue(qiantao2.contains("test-测试4")); |
||||
Assert.assertTrue(qiantao2.contains("test-测试5")); |
||||
Assert.assertTrue(qiantao2.contains("test-测试6")); |
||||
Assert.assertTrue(qiantao2.contains("test-测试7")); |
||||
Assert.assertTrue(qiantao2.contains("test-测试8")); |
||||
|
||||
String str3 = "TEST_TABLE.select(INNER.select(glbName,\"6\"),\"6\")"; |
||||
Set<String> result = TableDataFormulaUtils.search4TableData(str3); |
||||
Assert.assertTrue(result.contains("TEST_TABLE")); |
||||
Assert.assertTrue(result.contains("INNER")); |
||||
} |
||||
|
||||
public void testReplace() { |
||||
String rowcount = "=ROWCOUNT(\"123\")"; |
||||
TableReplacementEntity entity = new TableReplacementEntity(); |
||||
entity.setOldName("123"); |
||||
entity.setNewName("222"); |
||||
List<TableReplacementEntity> entities = new ArrayList<>(); |
||||
entities.add(entity); |
||||
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(rowcount, entities), "=ROWCOUNT(\"222\")"); |
||||
|
||||
String colcount = "=COLCOUNT(\"test测试\")"; |
||||
TableReplacementEntity entity1 = new TableReplacementEntity(); |
||||
entity1.setOldName("test测试"); |
||||
entity1.setNewName("替换"); |
||||
List<TableReplacementEntity> entities1 = new ArrayList<>(); |
||||
entities1.add(entity1); |
||||
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colcount, entities1), "=COLCOUNT(\"替换\")"); |
||||
|
||||
String colname = "=COLNAME(\"test测试\")"; |
||||
TableReplacementEntity entity2 = new TableReplacementEntity(); |
||||
entity2.setOldName("test测试"); |
||||
entity2.setNewName("替换123"); |
||||
List<TableReplacementEntity> entities2 = new ArrayList<>(); |
||||
entities2.add(entity2); |
||||
Assert.assertEquals(TableDataFormulaUtils.replace4TableData(colname, entities2), "=COLNAME(\"替换123\")"); |
||||
|
||||
String TABLEDATAFIELDS = "=TABLEDATAFIELDS(\"test测试\")"; |
||||
TableReplacementEntity entity3 = new TableReplacementEntity(); |
||||
entity3.setOldName("test测试"); |
||||
entity3.setNewName("替换111"); |
||||
List<TableReplacementEntity> entities3 = new ArrayList<>(); |
||||
entities3.add(entity3); |
||||
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(); |
||||
entity4.setOldName("test-测试"); |
||||
entity4.setNewName("test-测试的副本"); |
||||
List<TableReplacementEntity> entities4 = new ArrayList<>(); |
||||
entities4.add(entity4); |
||||
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-测试\")))"; |
||||
TableReplacementEntity entity5 = new TableReplacementEntity(); |
||||
entity5.setOldName("test-测试"); |
||||
entity5.setNewName("test-测试的副本"); |
||||
TableReplacementEntity entity6 = new TableReplacementEntity(); |
||||
entity6.setOldName("test-测试1"); |
||||
entity6.setNewName("test-测试2"); |
||||
TableReplacementEntity entity7 = new TableReplacementEntity(); |
||||
entity7.setOldName("test-测试2"); |
||||
entity7.setNewName("test-测试3"); |
||||
TableReplacementEntity entity8 = new TableReplacementEntity(); |
||||
entity8.setOldName("test-测试3"); |
||||
entity8.setNewName("test-测试4"); |
||||
List<TableReplacementEntity> entities5 = new ArrayList<>(); |
||||
entities5.add(entity5); |
||||
entities5.add(entity6); |
||||
entities5.add(entity7); |
||||
entities5.add(entity8); |
||||
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…
Reference in new issue