|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.fr.design.data.tabledata.paste; |
|
|
|
|
|
|
|
|
|
import com.fr.base.TableData; |
|
|
|
|
import com.fr.base.chart.BaseChartCollection; |
|
|
|
|
import com.fr.data.TableDataSource; |
|
|
|
|
import com.fr.design.DesignModelAdapter; |
|
|
|
|
import com.fr.design.data.DesignTableDataManager; |
|
|
|
@ -9,17 +10,26 @@ import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
|
|
|
|
|
import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; |
|
|
|
|
import com.fr.design.data.tabledata.wrapper.TableDataWrapper; |
|
|
|
|
import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; |
|
|
|
|
import com.fr.form.FormElementCaseProvider; |
|
|
|
|
import com.fr.form.data.DataBinding; |
|
|
|
|
import com.fr.form.data.DataTableConfig; |
|
|
|
|
import com.fr.form.main.Form; |
|
|
|
|
import com.fr.form.main.WidgetGather; |
|
|
|
|
import com.fr.form.ui.DataControl; |
|
|
|
|
import com.fr.form.ui.DictionaryContainer; |
|
|
|
|
import com.fr.form.ui.ElementCaseEditor; |
|
|
|
|
import com.fr.form.ui.Widget; |
|
|
|
|
import com.fr.form.ui.concept.data.ValueInitializer; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.report.cell.FloatElement; |
|
|
|
|
import com.fr.report.cell.tabledata.ElementUsedTableDataProvider; |
|
|
|
|
import com.fr.report.worksheet.FormElementCase; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
@ -31,6 +41,8 @@ import java.util.Set;
|
|
|
|
|
*/ |
|
|
|
|
public class TableDataFollowingPasteUtils { |
|
|
|
|
|
|
|
|
|
private static final String UNDERLINE = "_"; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 粘贴所有Map中的tabledata到当前模板 |
|
|
|
|
* |
|
|
|
@ -73,19 +85,78 @@ public class TableDataFollowingPasteUtils {
|
|
|
|
|
return new HashMap<>(); |
|
|
|
|
} |
|
|
|
|
// 获取当前的所有模板数据集
|
|
|
|
|
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapper(); |
|
|
|
|
Map<String, TableData> resultMap = new HashMap<>(); |
|
|
|
|
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapperIncludingProcedure(); |
|
|
|
|
Map<String, TableData> tempMap = new HashMap<>(); |
|
|
|
|
try { |
|
|
|
|
for (ElementUsedTableDataProvider tableDataProvider : providers) { |
|
|
|
|
Set<String> usedTableDataNames = tableDataProvider.getElementUsedTableDataNames(); |
|
|
|
|
for (String usedTableDataName : usedTableDataNames) { |
|
|
|
|
if (templateTableData.containsKey(usedTableDataName)) { |
|
|
|
|
resultMap.put(usedTableDataName, templateTableData.get(usedTableDataName).getTableData()); |
|
|
|
|
tempMap.put(usedTableDataName, templateTableData.get(usedTableDataName).getTableData()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 处理存储过程名称问题
|
|
|
|
|
return dealWithStoreProcedure(tempMap); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error("transfer widget tabledata failed", e); |
|
|
|
|
} |
|
|
|
|
return new HashMap<>(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 处理结果集,将结果集中的存储过程子表替换为原本的存储过程,否则跟随粘贴过去的存储过程名称有问题 |
|
|
|
|
* |
|
|
|
|
* @param tableDataMap |
|
|
|
|
*/ |
|
|
|
|
public static Map<String, TableData> dealWithStoreProcedure(Map<String, TableData> tableDataMap) { |
|
|
|
|
Map<String, TableData> resultMap = new HashMap<>(); |
|
|
|
|
if (tableDataMap == null) { |
|
|
|
|
return resultMap; |
|
|
|
|
} |
|
|
|
|
for (Map.Entry<String, TableData> result : tableDataMap.entrySet()) { |
|
|
|
|
String tableDataName = result.getKey(); |
|
|
|
|
TableData tableData = result.getValue(); |
|
|
|
|
// 判断名称中存在"_"的
|
|
|
|
|
if (tableDataName.contains(UNDERLINE)) { |
|
|
|
|
String matchedName = matchTableDataName(tableDataName, tableData); |
|
|
|
|
resultMap.put(matchedName, tableData); |
|
|
|
|
} else { |
|
|
|
|
resultMap.put(tableDataName, tableData); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return resultMap; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 存储过程子表名称匹配其存储过程数据集名称,其余模板数据集名称不变 |
|
|
|
|
* |
|
|
|
|
* @param tableDataName 待匹配的数据集名称 |
|
|
|
|
* @param tableData |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private static String matchTableDataName(String tableDataName, TableData tableData) { |
|
|
|
|
if (tableDataName == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
// 获取不包括存储过程子表的所有TableDataMap
|
|
|
|
|
Map<String, TableDataWrapper> dataWrapperMap = getCurrentTemplateTableDataWrapper(); |
|
|
|
|
// 名称匹配时,直接返回
|
|
|
|
|
if (dataWrapperMap.containsKey(tableDataName)) { |
|
|
|
|
return tableDataName; |
|
|
|
|
} |
|
|
|
|
// 名称不匹配时,判断TableData是否一致
|
|
|
|
|
for (Map.Entry<String, TableDataWrapper> dataWrapperEntry : dataWrapperMap.entrySet()) { |
|
|
|
|
String tdName = dataWrapperEntry.getKey(); |
|
|
|
|
TableData td = dataWrapperEntry.getValue().getTableData(); |
|
|
|
|
if (ComparatorUtils.equals(td, tableData)) { |
|
|
|
|
return tdName; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return tableDataName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 提取控件内使用的数据集,转化成Map返回 |
|
|
|
|
* |
|
|
|
@ -97,63 +168,173 @@ public class TableDataFollowingPasteUtils {
|
|
|
|
|
return new HashMap<>(); |
|
|
|
|
} |
|
|
|
|
// 获取当前的所有模板数据集
|
|
|
|
|
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapper(); |
|
|
|
|
Map<String, TableData> resultMap = new HashMap<>(); |
|
|
|
|
Map<String, TableDataWrapper> templateTableData = getCurrentTemplateTableDataWrapperIncludingProcedure(); |
|
|
|
|
Map<String, TableData> tempMap = new HashMap<>(); |
|
|
|
|
try { |
|
|
|
|
for (Widget widget : widgets) { |
|
|
|
|
collectTableDataInDictionary(templateTableData, resultMap, widget); |
|
|
|
|
collectTableDataInWidgetValue(templateTableData, resultMap, widget); |
|
|
|
|
// widget这个接口太大了,布局和子控件互相嵌套,所以只能分情况一个个收集
|
|
|
|
|
collectTableDataInDictionary(templateTableData, tempMap, widget); |
|
|
|
|
collectTableDataInWidgetValue(templateTableData, tempMap, widget); |
|
|
|
|
collectTableDataInChartCollection(templateTableData, tempMap, widget); |
|
|
|
|
collectTableDataInElementCaseEditor(templateTableData, tempMap, widget); |
|
|
|
|
} |
|
|
|
|
// 处理存储过程名称问题
|
|
|
|
|
return dealWithStoreProcedure(tempMap); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error("transfer widget tabledata failed", e); |
|
|
|
|
} |
|
|
|
|
return new HashMap<>(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 收集控件-报表块中使用的数据集 |
|
|
|
|
* |
|
|
|
|
* @param templateTableData |
|
|
|
|
* @param tempMap |
|
|
|
|
* @param widget |
|
|
|
|
*/ |
|
|
|
|
private static void collectTableDataInElementCaseEditor(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) { |
|
|
|
|
Form.traversalWidget(widget, new WidgetGather() { |
|
|
|
|
@Override |
|
|
|
|
public void dealWith(Widget widget) { |
|
|
|
|
ElementCaseEditor elementCaseEditor = (ElementCaseEditor) widget; |
|
|
|
|
FormElementCaseProvider elementCase = elementCaseEditor.getElementCase(); |
|
|
|
|
if (elementCase != null) { |
|
|
|
|
// 普通单元格
|
|
|
|
|
Iterator cellIterator = elementCase.cellIterator(); |
|
|
|
|
while (cellIterator.hasNext()) { |
|
|
|
|
ElementUsedTableDataProvider cellElement = (ElementUsedTableDataProvider) cellIterator.next(); |
|
|
|
|
collectElement(cellElement); |
|
|
|
|
} |
|
|
|
|
// 悬浮元素
|
|
|
|
|
Iterator<FloatElement> floatIterator = ((FormElementCase) elementCase).floatIterator(); |
|
|
|
|
while (floatIterator.hasNext()) { |
|
|
|
|
ElementUsedTableDataProvider floatElement = floatIterator.next(); |
|
|
|
|
collectElement(floatElement); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void collectElement(ElementUsedTableDataProvider provider) { |
|
|
|
|
Set<String> usedTableDataNames = provider.getElementUsedTableDataNames(); |
|
|
|
|
for (String usedTableDataName : usedTableDataNames) { |
|
|
|
|
if (templateTableData.containsKey(usedTableDataName)) { |
|
|
|
|
tempMap.put(usedTableDataName, templateTableData.get(usedTableDataName).getTableData()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean dealWithAllCards() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
}, ElementCaseEditor.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 收集控件-图表中的TableData |
|
|
|
|
* |
|
|
|
|
* @param templateTableData |
|
|
|
|
* @param tempMap |
|
|
|
|
* @param widget |
|
|
|
|
*/ |
|
|
|
|
private static void collectTableDataInChartCollection(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) { |
|
|
|
|
List<BaseChartCollection> chartCollections = widget.getChartCollections(); |
|
|
|
|
for (BaseChartCollection chartCollection : chartCollections) { |
|
|
|
|
Set<String> dataSetNames = chartCollection.getDataSetNames(); |
|
|
|
|
for (String dataSetName : dataSetNames) { |
|
|
|
|
if (templateTableData.containsKey(dataSetName)) { |
|
|
|
|
tempMap.put(dataSetName, templateTableData.get(dataSetName).getTableData()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return resultMap; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 收集控件值中的TableData |
|
|
|
|
* |
|
|
|
|
* @param templateTableData |
|
|
|
|
* @param resultMap |
|
|
|
|
* @param tempMap |
|
|
|
|
* @param widget |
|
|
|
|
*/ |
|
|
|
|
private static void collectTableDataInWidgetValue(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> resultMap, Widget widget) { |
|
|
|
|
if (widget instanceof DataControl && ((DataControl) widget).getWidgetValue() != null) { |
|
|
|
|
private static void collectTableDataInWidgetValue(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) { |
|
|
|
|
Form.traversalWidget(widget, new WidgetGather() { |
|
|
|
|
@Override |
|
|
|
|
public void dealWith(Widget widget) { |
|
|
|
|
if (((DataControl) widget).getWidgetValue() != null) { |
|
|
|
|
ValueInitializer widgetValue = ((DataControl) widget).getWidgetValue(); |
|
|
|
|
Object value = widgetValue.getValue(); |
|
|
|
|
if (value instanceof DataBinding) { |
|
|
|
|
String dataSourceName = ((DataBinding) value).getDataSourceName(); |
|
|
|
|
if (templateTableData.containsKey(dataSourceName)) { |
|
|
|
|
resultMap.put(dataSourceName, templateTableData.get(dataSourceName).getTableData()); |
|
|
|
|
tempMap.put(dataSourceName, templateTableData.get(dataSourceName).getTableData()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (value instanceof DataTableConfig) { |
|
|
|
|
String tableDataName = ((DataTableConfig) value).getTableDataName(); |
|
|
|
|
if (templateTableData.containsKey(tableDataName)) { |
|
|
|
|
resultMap.put(tableDataName, templateTableData.get(tableDataName).getTableData()); |
|
|
|
|
tempMap.put(tableDataName, templateTableData.get(tableDataName).getTableData()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean dealWithAllCards() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
}, DataControl.class); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 收集控件-数据字典中的TableData |
|
|
|
|
* |
|
|
|
|
* @param templateTableData |
|
|
|
|
* @param resultMap |
|
|
|
|
* @param tempMap |
|
|
|
|
* @param widget |
|
|
|
|
*/ |
|
|
|
|
private static void collectTableDataInDictionary(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> resultMap, Widget widget) { |
|
|
|
|
if (widget instanceof DictionaryContainer) { |
|
|
|
|
private static void collectTableDataInDictionary(Map<String, TableDataWrapper> templateTableData, Map<String, TableData> tempMap, Widget widget) { |
|
|
|
|
Form.traversalWidget(widget, new WidgetGather() { |
|
|
|
|
@Override |
|
|
|
|
public void dealWith(Widget widget) { |
|
|
|
|
Set<String> usedTableDataSets = ((DictionaryContainer) widget).getUsedTableDataSets(); |
|
|
|
|
for (String usedTableDataSet : usedTableDataSets) { |
|
|
|
|
if (templateTableData.containsKey(usedTableDataSet)) { |
|
|
|
|
resultMap.put(usedTableDataSet, templateTableData.get(usedTableDataSet).getTableData()); |
|
|
|
|
tempMap.put(usedTableDataSet, templateTableData.get(usedTableDataSet).getTableData()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean dealWithAllCards() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
}, DictionaryContainer.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当前所有的模板数据集,包括存储过程 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private static Map<String, TableDataWrapper> getCurrentTemplateTableDataWrapperIncludingProcedure() { |
|
|
|
|
Map<String, TableDataWrapper> templateTableDataWrapper = getCurrentTemplateTableDataWrapper(); |
|
|
|
|
// 处理存储过程
|
|
|
|
|
Map<String, TableDataWrapper> dataWrapperMap = DesignTableDataManager.getAllDataSetIncludingProcedure(templateTableDataWrapper); |
|
|
|
|
return dataWrapperMap; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当前所有的模板数据集,不包括存储过程 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private static Map<String, TableDataWrapper> getCurrentTemplateTableDataWrapper() { |
|
|
|
|
TableDataSource tableDataSource = DesignTableDataManager.getEditingTableDataSource(); |
|
|
|
|
List<Map<String, TableDataWrapper>> editingDataSet = DesignTableDataManager.getEditingDataSet(tableDataSource); |
|
|
|
|
return editingDataSet.get(0); |
|
|
|
|
Map<String, TableDataWrapper> templeteDataSet = editingDataSet.get(0); |
|
|
|
|
return templeteDataSet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|