diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboard.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboard.java index 44ae90b2cf..3094df145b 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboard.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboard.java @@ -1,6 +1,9 @@ package com.fr.design.data.datapane.management.clip; +import com.fr.base.TableData; +import com.fr.design.data.tabledata.paste.TableDataFollowingPasteUtils; import com.fr.design.data.tabledata.wrapper.AbstractTableDataWrapper; +import com.fr.design.data.tabledata.wrapper.TemplateTableDataWrapper; import com.fr.general.NameObject; import java.util.HashMap; @@ -45,7 +48,10 @@ public class TableDataTreeClipboard { return resultMap; } for (NameObject selectedNameObject : selectedNameObjects) { - resultMap.put(selectedNameObject.getName(), (AbstractTableDataWrapper) selectedNameObject.getObject()); + TableData cloned = TableDataFollowingPasteUtils.cloneTableData(((AbstractTableDataWrapper) selectedNameObject.getObject()).getTableData()); + if (cloned != null) { + resultMap.put(selectedNameObject.getName(), new TemplateTableDataWrapper(cloned)); + } } return resultMap; } diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java b/designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java index e90b8a4208..d9892c7637 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java @@ -28,6 +28,7 @@ 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 org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.HashMap; @@ -97,6 +98,8 @@ public class TableDataFollowingPasteUtils { } } } + // 对TableData做clone处理 + tempMap = dealWithTableData4Clone(tempMap); // 处理存储过程名称问题 return dealWithStoreProcedure(tempMap); } catch (Exception e) { @@ -179,6 +182,8 @@ public class TableDataFollowingPasteUtils { collectTableDataInChartCollection(templateTableData, tempMap, widget); collectTableDataInElementCaseEditor(templateTableData, tempMap, widget); } + // 对TableData做clone处理 + tempMap = dealWithTableData4Clone(tempMap); // 处理存储过程名称问题 return dealWithStoreProcedure(tempMap); } catch (Exception e) { @@ -187,6 +192,23 @@ public class TableDataFollowingPasteUtils { return new HashMap<>(); } + /** + * 对Map中所有的TableData做clone处理 + * @param tempMap + */ + private static Map dealWithTableData4Clone(Map tempMap) { + Map resultMap = new HashMap<>(); + for (Map.Entry entry : tempMap.entrySet()) { + String name = entry.getKey(); + TableData tableData = entry.getValue(); + TableData clonedTableData = cloneTableData(tableData); + if (clonedTableData != null) { + resultMap.put(name, clonedTableData); + } + } + return resultMap; + } + /** * 收集控件-报表块中使用的数据集 * @@ -353,4 +375,19 @@ public class TableDataFollowingPasteUtils { } return tableDataPane; } + + /** + * clone数据源,如果失败,打印日志,并返回null,谨慎使用 + * @param tableData + * @return + */ + @Nullable + public static TableData cloneTableData(TableData tableData) { + try { + return (TableData) tableData.clone(); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, "clone table data {} failed", tableData.getName()); + } + return null; + } }