|
|
|
@ -2,12 +2,21 @@ 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.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; |
|
|
|
@ -17,8 +26,18 @@ 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.ui.DictionaryContainer; |
|
|
|
|
import com.fr.form.ui.ElementCaseEditor; |
|
|
|
|
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.main.impl.WorkBook; |
|
|
|
|
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.elementcase.ElementCase; |
|
|
|
|
import com.fr.report.report.Report; |
|
|
|
|
import com.fr.report.utils.ElementCaseHelper; |
|
|
|
@ -180,6 +199,8 @@ public class ReplaceUtils {
|
|
|
|
|
List<FormulaInfo> formulaInfos = new ArrayList<>(); |
|
|
|
|
SearchChartCollectionFormulaAction.getInstance().searchChartCollectionFormula(formulaInfos, new ITContent(), chartCollection); |
|
|
|
|
replaceFormulaInfos(formulaInfos, entities); |
|
|
|
|
// 超链部分
|
|
|
|
|
replaceChartJs(chartCollection, entities); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -190,13 +211,16 @@ public class ReplaceUtils {
|
|
|
|
|
*/ |
|
|
|
|
public static void replaceElementCase(ElementCase elementCase, List<TableReplacementEntity> entities) { |
|
|
|
|
// 非公式部分
|
|
|
|
|
ElementCaseHelper.replaceTableDataWithOutFormula(elementCase, entities); |
|
|
|
|
replaceTableDataWithOutFormula(elementCase, entities); |
|
|
|
|
// 公式部分——理论上就只有单元格和控件(超链那些都包含)
|
|
|
|
|
List<FormulaInfo> formulaInfos = getElementCaseFormulas(elementCase); |
|
|
|
|
replaceFormulaInfos(formulaInfos, entities); |
|
|
|
|
// 超链部分
|
|
|
|
|
replaceElementCasJs(elementCase, entities); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 替换CPT使用的数据集(包含公式里的) |
|
|
|
|
* |
|
|
|
@ -206,18 +230,73 @@ public class ReplaceUtils {
|
|
|
|
|
public static void replaceCpt(JTemplate template, List<TableReplacementEntity> entity) { |
|
|
|
|
if (template.getTarget() instanceof WorkBook) { |
|
|
|
|
WorkBook workBook = (WorkBook) template.getTarget(); |
|
|
|
|
|
|
|
|
|
// 非公式部分替换
|
|
|
|
|
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 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 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++) { |
|
|
|
@ -226,7 +305,7 @@ public class ReplaceUtils {
|
|
|
|
|
Iterator it = report.iteratorOfElementCase(); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
ElementCase elementCase = (ElementCase) it.next(); |
|
|
|
|
ElementCaseHelper.replaceTableDataWithOutFormula(elementCase, entity); |
|
|
|
|
replaceTableDataWithOutFormula(elementCase, entity); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -270,4 +349,158 @@ public class ReplaceUtils {
|
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
// 处理单元格的控件
|
|
|
|
|
replaceCellWidget(cellElement, entities); |
|
|
|
|
// 处理形态
|
|
|
|
|
ElementCaseHelper.replacePresent(cellElement.getPresent(), entities); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 处理单元格控件 |
|
|
|
|
* |
|
|
|
|
* @param cellElement 单元格 |
|
|
|
|
* @param entities 替换信息 |
|
|
|
|
*/ |
|
|
|
|
private static void replaceCellWidget(TemplateCellElement cellElement, List<TableReplacementEntity> entities) { |
|
|
|
|
if (cellElement.getWidget() instanceof DictionaryContainer) { |
|
|
|
|
DictionaryContainer db = (DictionaryContainer) (cellElement.getWidget()); |
|
|
|
|
if (db != null) { |
|
|
|
|
if (db.getDictionary() instanceof TableDataDictionary) { |
|
|
|
|
TableDataDictionary tdd = (TableDataDictionary) db.getDictionary(); |
|
|
|
|
NameTableData ndd = (NameTableData) tdd.getTableData(); |
|
|
|
|
// 控件持有的数据字典也得处理
|
|
|
|
|
ElementCaseHelper.replaceTableDataDictionary(tdd, ndd, 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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|