Browse Source

REPORT-70857 数据集复制后独立

【问题原因】数据集在做复制粘贴的时候,没有clone数据源,导致许多变量都共用了,于是会改一个=改一片
【改动方案】添加clone处理
【review建议】无
release/11.0
Yvan 2 years ago
parent
commit
00a9347e5f
  1. 8
      designer-base/src/main/java/com/fr/design/data/datapane/management/clip/TableDataTreeClipboard.java
  2. 37
      designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java

8
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;
}

37
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<String, TableData> dealWithTableData4Clone(Map<String, TableData> tempMap) {
Map<String, TableData> resultMap = new HashMap<>();
for (Map.Entry<String, TableData> 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;
}
}

Loading…
Cancel
Save