From 00a9347e5f2981beea40e098b608afea55c153ba Mon Sep 17 00:00:00 2001 From: Yvan Date: Tue, 10 May 2022 18:26:12 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-70857=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E5=A4=8D=E5=88=B6=E5=90=8E=E7=8B=AC=E7=AB=8B=20=E3=80=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0=E3=80=91=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E5=9C=A8=E5=81=9A=E5=A4=8D=E5=88=B6=E7=B2=98=E8=B4=B4?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E6=B2=A1=E6=9C=89clone?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90=EF=BC=8C=E5=AF=BC=E8=87=B4=E8=AE=B8?= =?UTF-8?q?=E5=A4=9A=E5=8F=98=E9=87=8F=E9=83=BD=E5=85=B1=E7=94=A8=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E4=BA=8E=E6=98=AF=E4=BC=9A=E6=94=B9=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=3D=E6=94=B9=E4=B8=80=E7=89=87=20=E3=80=90=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=E6=96=B9=E6=A1=88=E3=80=91=E6=B7=BB=E5=8A=A0clone=E5=A4=84?= =?UTF-8?q?=E7=90=86=20=E3=80=90review=E5=BB=BA=E8=AE=AE=E3=80=91=E6=97=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clip/TableDataTreeClipboard.java | 8 +++- .../paste/TableDataFollowingPasteUtils.java | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) 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; + } }