Browse Source

REPORT-1916 做模板的过程和耗时收集=》完成基本信息的本地存取

master
plough 8 years ago
parent
commit
af03d197f0
  1. 1
      designer/src/com/fr/design/mainframe/JPolyWorkBook.java
  2. 64
      designer/src/com/fr/design/mainframe/JWorkBook.java
  3. 45
      designer_base/src/com/fr/design/mainframe/JTemplate.java
  4. 133
      designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java
  5. 30
      designer_form/src/com/fr/design/mainframe/JForm.java

1
designer/src/com/fr/design/mainframe/JPolyWorkBook.java

@ -24,7 +24,6 @@ public class JPolyWorkBook extends JWorkBook {
super(new WorkBook(new PolyWorkSheet()), DEFAULT_NAME);
populateReportParameterAttr();
}
/**
* 创建sheet名称tab面板

64
designer/src/com/fr/design/mainframe/JWorkBook.java

@ -3,6 +3,7 @@ package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.base.FRContext;
import com.fr.base.Parameter;
import com.fr.base.parameter.ParameterUI;
import com.fr.design.DesignModelAdapter;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.AllowAuthorityEditAction;
@ -54,7 +55,10 @@ import com.fr.main.impl.WorkBook;
import com.fr.main.parameter.ReportParameterAttr;
import com.fr.poly.PolyDesigner;
import com.fr.privilege.finegrain.WorkSheetPrivilegeControl;
import com.fr.report.cellcase.CellCase;
import com.fr.report.elementcase.TemplateElementCase;
import com.fr.report.poly.PolyWorkSheet;
import com.fr.report.report.Report;
import com.fr.report.worksheet.WorkSheet;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StableUtils;
@ -66,10 +70,7 @@ import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* JWorkBook used to edit WorkBook.
@ -129,6 +130,61 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
return centerPane;
}
// 获取模板类型
public int getReportType() {
return template.isElementCaseBook() ? 0 : 1;
}
// 获取模板格子数
public int getCellCount() {
int cellCount = 0;
if (template.isElementCaseBook()) { // 如果是普通报表
for (int i = 0; i < template.getReportCount(); i++) {
WorkSheet r = (WorkSheet) template.getReport(i);
CellCase cc = r.getBlock().getCellCase();
for (int j = 0; j < cc.getRowCount(); j++) {
Iterator iter = cc.getRow(j);
while (iter.hasNext()) {
cellCount ++;
iter.next();
}
}
}
}
return cellCount;
}
// 获取模板悬浮元素个数
public int getFloatCount() {
int chartCount = 0;
if (template.isElementCaseBook()) { // 如果是普通报表
for (int i = 0; i < template.getReportCount(); i++) {
WorkSheet r = (WorkSheet) template.getReport(i);
Iterator fiter = r.getBlock().floatIterator();
while (fiter.hasNext()) {
chartCount ++;
fiter.next();
}
}
}
return chartCount;
}
// 获取模板聚合块个数
public int getBlockCount() {
int blockCount = 0;
if (!template.isElementCaseBook()) { // 如果是聚合报表
for (int i = 0; i < template.getReportCount(); i++) {
PolyWorkSheet r = (PolyWorkSheet) template.getReport(i);
blockCount += r.getBlockCount();
}
}
return blockCount;
}
// 获取模板控件数
public int getWidgetCount() {
ParameterUI pui = template.getReportParameterAttr().getParameterUI();
return pui == null ? 0 : (pui.getAllWidgets().length - 1);
}
/**
* 判断sheet权限
*

45
designer_base/src/com/fr/design/mainframe/JTemplate.java

@ -27,6 +27,7 @@ import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.itree.filetree.TemplateFileTree;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus;
import com.fr.design.menu.MenuDef;
import com.fr.design.menu.NameSeparator;
@ -72,16 +73,25 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
private UndoManager authorityUndoManager;
protected U undoState;
protected U authorityUndoState = null;
protected T template; // 当前模板
private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复
private DesignModelAdapter<T, ?> designModel;
private PreviewProvider previewType;
private long openTime = 0L; // 打开模板的时间点(包括新建模板)
private TemplateInfoCollector tic = TemplateInfoCollector.getInstance();
public JTemplate(T t, String defaultFileName) {
this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)));
this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true);
initForCollect();
}
public JTemplate(T t, FILE file) {
this(t, file, false);
}
public JTemplate(T t, FILE file, boolean isNewFile) {
super(t);
this.template = t;
this.previewType = parserPreviewProvider(t.getPreviewType());
this.editingFILE = file;
this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -89,8 +99,38 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
this.add(createCenterPane(), BorderLayout.CENTER);
this.undoState = createUndoState();
designModel = createDesignModel();
// 如果不是新建模板,并且在收集列表中
if (!isNewFile && tic.inList(t)) {
openTime = System.currentTimeMillis();
}
}
// 为收集模版信息作准备
private void initForCollect() {
if (template.getReportletsid() == null) {
template.initReportletsid(); // 为新模板设置 reportletsid 属性
}
if (openTime == 0) {
openTime = System.currentTimeMillis();
}
}
private void collectInfo() { // 执行收集操作
long saveTime = System.currentTimeMillis(); // 保存模板的时间点
tic.collectInfo(template, this, openTime, saveTime);
openTime = saveTime; // 更新 openTime,准备下一次计算
}
// 获取模板类型。0 代表普通报表,1 代表聚合报表,2 代表表单
public abstract int getReportType();
// 获取模板格子数
public abstract int getCellCount();
// 获取模板悬浮元素个数
public abstract int getFloatCount();
// 获取模板聚合块个数
public abstract int getBlockCount();
// 获取模板控件数
public abstract int getWidgetCount();
public U getUndoState() {
return undoState;
}
@ -439,6 +479,7 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_No-Privilege") + "!", Inter.getLocText("FR-Designer_Message"), JOptionPane.WARNING_MESSAGE);
return false;
}
collectInfo();
return this.saveFile();
}
@ -487,6 +528,8 @@ public abstract class JTemplate<T extends IOFile, U extends BaseUndoState<?>> ex
boolean result = this.saveFile();
if (result) {
DesignerFrameFileDealerPane.getInstance().refresh();
initForCollect(); // 如果是旧模板另存为新模板,则添加 reportletsid
collectInfo();
}
//更换最近打开
DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(oldName, this.getFullPathName());

133
designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java

@ -0,0 +1,133 @@
package com.fr.design.mainframe.templateinfo;
import com.fr.base.io.IOFile;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.JTemplate;
import com.fr.general.FRLogger;
import com.fr.general.GeneralUtils;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import java.io.*;
import java.util.Date;
import java.util.HashMap;
/**
* 做模板的过程和耗时收集辅助类
* Created by plough on 2017/2/21.
*/
public class TemplateInfoCollector<T extends IOFile> implements Serializable {
private static final String FILE_NAME = "tplInfo.ser";
private static TemplateInfoCollector instance;
private HashMap<String, HashMap<String, Object>> templateInfoList;
@SuppressWarnings("unchecked")
private TemplateInfoCollector() {
// 先尝试从文件读取
try{
ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile()));
templateInfoList = (HashMap<String, HashMap<String,Object>>) is.readObject();
} catch (FileNotFoundException ex) {
// 如果之前没有存储过,则创建新对象
templateInfoList = new HashMap<>();
} catch (Exception ex) {
FRLogger.getLogger().error(ex.getMessage(), ex);
}
}
/**
* 获取缓存文件存放路径
*/
private static File getInfoFile() {
return new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FILE_NAME));
}
public static TemplateInfoCollector getInstance() {
if (instance == null) {
instance = new TemplateInfoCollector();
}
return instance;
}
/**
* 根据模板ID是否在收集列表中判断是否需要收集当前模板的信息
*/
public boolean inList(T t) {
return templateInfoList.containsKey(t.getReportletsid());
}
// 将包含所有信息的对象保存到文件
private void saveInfo() {
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile()));
System.out.println("写入:" + instance.templateInfoList);
os.writeObject(instance.templateInfoList);
os.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public HashMap getInfoList() {
for (String key : templateInfoList.keySet()) {
System.out.println(templateInfoList.get(key));
}
return templateInfoList;
}
/**
* 收集模板信息如果之前没有记录则新增如果已有记录则更新
* 同时将最新数据保存到文件中
*/
public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) {
HashMap<String, Object> templateInfo;
if (inList(t)) { // 已有记录
templateInfo = templateInfoList.get(t.getReportletsid());
} else { // 新增
templateInfo = new HashMap<>();
String username = DesignerEnvManager.getEnvManager().getBBSName();
String uuid = DesignerEnvManager.getEnvManager().getUUID();
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey();
String reportletsid = t.getReportletsid();
String createTime = new Date(openTime).toString();
int reportType = jt.getReportType();
String jarTime = GeneralUtils.readBuildNO();
String version = ProductConstants.VERSION;
templateInfo.put("username", username);
templateInfo.put("uuid", uuid);
templateInfo.put("activitykey", activitykey);
templateInfo.put("reportletsid", reportletsid);
templateInfo.put("create_time", createTime);
templateInfo.put("report_type", reportType);
templateInfo.put("jar_time", jarTime);
templateInfo.put("version", version);
}
long timeConsume = saveTime - openTime;
// 如果已存有数据,则加上本次编辑时间
if (templateInfo.get("time_consume") != null) {
timeConsume += (long)templateInfo.get("time_consume");
}
// String process;
int cellCount = jt.getCellCount();
int floatCount = jt.getFloatCount();
int blockCount = jt.getBlockCount();
int widgetCount = jt.getWidgetCount();
templateInfo.put("time_consume", timeConsume);
templateInfo.put("cell_count", cellCount);
templateInfo.put("float_count", floatCount);
templateInfo.put("block_count", blockCount);
templateInfo.put("widget_count", widgetCount);
templateInfoList.put(t.getReportletsid(), templateInfo);
saveInfo(); // 每次更新之后,都同步到暂存文件中
}
public static void main(String[] args) {
TemplateInfoCollector tic = TemplateInfoCollector.getInstance();
tic.getInfoList();
}
}

30
designer_form/src/com/fr/design/mainframe/JForm.java

@ -38,6 +38,7 @@ import com.fr.form.FormElementCaseProvider;
import com.fr.form.main.Form;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WBorderLayout;
import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
@ -88,6 +89,35 @@ public class JForm extends JTemplate<Form, FormUndoState> implements BaseJForm {
return DesignState.JFORM;
}
// 获取模板类型
public int getReportType() {
return 2;
}
// 获取模板格子数
public int getCellCount() {
return 0;
}
// 获取模板悬浮元素个数
public int getFloatCount() {
return 0;
}
// 获取模板聚合块个数
public int getBlockCount() {
return 0;
}
// 获取模板控件数
public int getWidgetCount() {
int widgetCount = 0;
for (int i = 0; i < template.getContainer().getWidgetCount(); i++) {
WFitLayout wf = (WFitLayout) template.getContainer().getWidget(i);
widgetCount += wf.getWidgetCount();
}
int a = 1;
int b = 2;
return widgetCount;
}
@Override
protected boolean accept(Object o) {
return !(o instanceof FloatElementsProvider);

Loading…
Cancel
Save