From c19c243a73470b5d3298e87f6b122e9fe13ec482 Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 6 Apr 2017 15:43:45 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-1916=20=E6=A8=A1=E6=9D=BF=E8=80=97?= =?UTF-8?q?=E6=97=B6=3D=E3=80=8B=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templateinfo/JWorkBookProcessInfo.java | 1 - .../com/fr/design/mainframe/JTemplate.java | 111 +++++++++--------- .../templateinfo/TemplateInfoCollector.java | 42 +++++-- .../templateinfo/JFormProcessInfo.java | 0 4 files changed, 88 insertions(+), 66 deletions(-) rename {designer_base => designer}/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java (98%) rename {designer_base => designer_form}/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java (100%) diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java b/designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java similarity index 98% rename from designer_base/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java rename to designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java index 44522b856..bf5d835d2 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java +++ b/designer/src/com/fr/design/mainframe/templateinfo/JWorkBookProcessInfo.java @@ -1,6 +1,5 @@ package com.fr.design.mainframe.templateinfo; -import com.fr.base.io.IOFile; import com.fr.base.parameter.ParameterUI; import com.fr.main.impl.WorkBook; import com.fr.report.cellcase.CellCase; diff --git a/designer_base/src/com/fr/design/mainframe/JTemplate.java b/designer_base/src/com/fr/design/mainframe/JTemplate.java index b0b9f7b5a..48371c787 100644 --- a/designer_base/src/com/fr/design/mainframe/JTemplate.java +++ b/designer_base/src/com/fr/design/mainframe/JTemplate.java @@ -85,7 +85,7 @@ public abstract class JTemplate> ex public JTemplate(T t, String defaultFileName) { this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true); - initForCollect(); + openTime = System.currentTimeMillis(); } public JTemplate(T t, FILE file) { @@ -111,14 +111,15 @@ public abstract class JTemplate> ex // 为收集模版信息作准备 private void initForCollect() { - if (template.getTemplateID() == null) { - template.initTemplateID(); // 为新模板设置 templateID 属性 - } + template.initTemplateID(); // 为新模板设置 templateID 属性 if (openTime == 0) { openTime = System.currentTimeMillis(); } } private void collectInfo() { // 执行收集操作 + if (openTime == 0) { // 旧模板,不收集数据 + return; + } long saveTime = System.currentTimeMillis(); // 保存模板的时间点 tic.collectInfo(template, this, openTime, saveTime); openTime = saveTime; // 更新 openTime,准备下一次计算 @@ -371,7 +372,7 @@ public abstract class JTemplate> ex } protected boolean accept(Object o){ - return true; + return true; } private void fireSuperTargetModified() { @@ -487,15 +488,15 @@ public abstract class JTemplate> ex collectInfo(); return this.saveFile(); } - + private boolean isCancelOperation(int operation){ - return operation == FILEChooserPane.CANCEL_OPTION || - operation == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION; + return operation == FILEChooserPane.CANCEL_OPTION || + operation == FILEChooserPane.JOPTIONPANE_CANCEL_OPTION; } - + private boolean isOkOperation(int operation){ - return operation == FILEChooserPane.JOPTIONPANE_OK_OPTION || - operation == FILEChooserPane.OK_OPTION; + return operation == FILEChooserPane.JOPTIONPANE_OK_OPTION || + operation == FILEChooserPane.OK_OPTION; } private boolean saveAsTemplate(boolean isShowLoc) { @@ -512,8 +513,8 @@ public abstract class JTemplate> ex if (isCancelOperation(chooseResult)) { fileChooser = null; return false; - } - + } + if (isOkOperation(chooseResult)) { if (!FRContext.getCurrentEnv().hasFileFolderAllow(fileChooser.getSelectedFILE().getPath()) ) { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("FR-Designer_No-Privilege") + "!", Inter.getLocText("FR-Designer_Message"), JOptionPane.WARNING_MESSAGE); @@ -523,40 +524,40 @@ public abstract class JTemplate> ex mkNewFile(editingFILE); fileChooser = null; } - + return saveNewFile(editingFILE, oldName); } - + protected boolean saveNewFile(FILE editingFILE, String oldName){ this.editingFILE = editingFILE; boolean result = this.saveFile(); if (result) { DesignerFrameFileDealerPane.getInstance().refresh(); - initForCollect(); // 如果是旧模板另存为新模板,则添加 templateID + initForCollect(); // 如果保存新模板(新建模板直接保存,或者另存为),则添加 templateID collectInfo(); } //更换最近打开 DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(oldName, this.getFullPathName()); return result; } - + protected void mkNewFile(FILE file){ try { - file.mkfile(); + file.mkfile(); } catch (Exception e) { FRContext.getLogger().error(e.getMessage(), e); } } - + /** - * 将模板另存为可以分享出去的混淆后内置数据集模板 - * - * @return 是否另存成功 - * - */ + * 将模板另存为可以分享出去的混淆后内置数据集模板 + * + * @return 是否另存成功 + * + */ public boolean saveShareFile(){ - return true; + return true; } public Widget getSelectElementCase(){ return new NoneWidget(); @@ -761,7 +762,7 @@ public abstract class JTemplate> ex public void revert() { } - + private int getVersionCompare(String versionString){ if (StringUtils.isBlank(versionString)) { return 0; @@ -771,7 +772,7 @@ public abstract class JTemplate> ex return ComparatorUtils.compare(versionString.substring(0, len), ProductConstants.DESIGNER_VERSION.substring(0, len)); } - + private int getVersionCompareHBB(String versionString){ if (StringUtils.isBlank(versionString)) { return 0; @@ -779,17 +780,17 @@ public abstract class JTemplate> ex return ComparatorUtils.compare(versionString, "HBB"); } - + private boolean isHigherThanCurrent(String versionString) { return getVersionCompare(versionString) > 0; } - + private boolean isLowerThanCurrent(String versionString) { - return getVersionCompare(versionString) < 0; + return getVersionCompare(versionString) < 0; } - + private boolean isLowerThanHBB(String versionString) { - return getVersionCompareHBB(versionString) < 0; + return getVersionCompareHBB(versionString) < 0; } /** @@ -799,7 +800,7 @@ public abstract class JTemplate> ex public boolean isNewDesigner() { String xmlDesignerVersion = getTarget().getXMLDesignerVersion(); if (isLowerThanHBB(xmlDesignerVersion)) { - String info = Inter.getLocText("FR-Designer_open-new-form-tip"); + String info = Inter.getLocText("FR-Designer_open-new-form-tip"); String moreInfo = Inter.getLocText("FR-Designer_Server-version-tip-moreInfo"); new InformationWarnPane(info, moreInfo, Inter.getLocText("FR-Designer_Tooltips")).show(); return true; @@ -853,13 +854,13 @@ public abstract class JTemplate> ex * @return 是则返回true */ public abstract boolean isJWorkBook(); - + /** * 返回当前支持的超链界面pane * @return 超链连接界面 */ public HyperlinkGroupPane getHyperLinkPane() { - return new HyperlinkGroupPane(); + return new HyperlinkGroupPane(); } /** @@ -914,29 +915,29 @@ public abstract class JTemplate> ex public void requestGridFocus() { } - + /** - * 创建内置sql提交的pane - * - * @return 内置sql提交的pane - * - * - * @date 2014-10-14-下午7:39:27 - */ + * 创建内置sql提交的pane + * + * @return 内置sql提交的pane + * + * + * @date 2014-10-14-下午7:39:27 + */ public DBManipulationPane createDBManipulationPane(){ - return new DBManipulationPane(); + return new DBManipulationPane(); } - + /** * 创建控件事件里内置sql提交的pane - * + * * @return 内置sql提交的pane - * + * * * @date 2014-10-14-下午7:39:27 */ public DBManipulationPane createDBManipulationPaneInWidget(){ - return new DBManipulationInWidgetEventPane(); + return new DBManipulationInWidgetEventPane(); } /** @@ -964,15 +965,15 @@ public abstract class JTemplate> ex public void styleChange(){ } - + /** - * 创建分享模板的按钮, 目前只有jworkbook实现了 - * - * @return 分享模板按钮 - * - */ + * 创建分享模板的按钮, 目前只有jworkbook实现了 + * + * @return 分享模板按钮 + * + */ public UIButton[] createShareButton(){ - return new UIButton[0]; + return new UIButton[0]; } /** diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java index 4f7069205..37446b3d3 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -5,6 +5,7 @@ import com.fr.base.io.IOFile; import com.fr.design.DesignerEnvManager; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; +import com.fr.env.RemoteEnv; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.GeneralUtils; @@ -15,9 +16,7 @@ import org.json.JSONObject; import java.io.*; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.HashMap; +import java.util.*; /** * 做模板的过程和耗时收集,辅助类 @@ -70,18 +69,28 @@ public class TemplateInfoCollector implements Serializable { } catch (FileNotFoundException ex) { // 如果之前没有存储过,则创建新对象 instance = new TemplateInfoCollector(); - } catch (Exception ex) { + } catch (InvalidClassException ex) { + // 如果 TemplateInfoCollecor 类结构有改动,则放弃之前收集的数据(下次保存时覆盖) + // 这种情况主要在开发、测试过程中遇到,正式上线后不应该出现 + FRLogger.getLogger().error(ex.getMessage()); + FRLogger.getLogger().info("use a new instance"); + instance = new TemplateInfoCollector(); + } + catch (Exception ex) { FRLogger.getLogger().error(ex.getMessage(), ex); } } return instance; } - private static boolean shouldCollectInfo() { + private boolean shouldCollectInfo() { + if (FRContext.getCurrentEnv() instanceof RemoteEnv) { // 远程设计不收集数据 + return false; + } return DesignerEnvManager.getEnvManager().isJoinProductImprove() && FRContext.isChineseEnv(); } - public static void appendProcess(String log) { + public void appendProcess(String log) { if (!shouldCollectInfo()) { return; } @@ -113,7 +122,14 @@ public class TemplateInfoCollector implements Serializable { private void saveInfo() { try { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile())); - FRLogger.getLogger().info("writing: " + instance.templateInfoList); + String log = ""; + int count = 1; + for (String key : templateInfoList.keySet()) { + String createTime = ((HashMap)templateInfoList.get(key).get("consumingMap")).get("create_time").toString(); + log += (count + ". id: " + key + " " + createTime + "\n" + templateInfoList.get(key).toString() + "\n"); + count ++; + } + FRLogger.getLogger().info("writing tplInfo: \n" + log); os.writeObject(instance); os.close(); } catch (Exception ex) { @@ -225,7 +241,9 @@ public class TemplateInfoCollector implements Serializable { if (sendSingleTemplateInfo(consumingUrl, jsonConsumingMap) && sendSingleTemplateInfo(processUrl, jsonProcessMap)) { // 清空记录 FRLogger.getLogger().info("successfully send " + templateInfo.get("templateID")); - templateInfoList.remove(templateInfo.get("templateID")); + removeFromTemplateInfoList(templateInfo.get("templateID")); + } else { + FRLogger.getLogger().info("send template info failed, will try next time, " + templateInfo.get("templateID")); } } saveInfo(); @@ -277,12 +295,16 @@ public class TemplateInfoCollector implements Serializable { } // 删除测试模板 for (String key : testTemplateKeys) { - templateInfoList.remove(key); -// System.out.println(key + " is removed..."); + removeFromTemplateInfoList(key); } return completeTemplatesInfo; } + private void removeFromTemplateInfoList(String key) { + templateInfoList.remove(key); + FRLogger.getLogger().info(key + " is removed..."); + } + @SuppressWarnings("unchecked") private boolean isTestTemplate(HashMap templateInfo) { HashMap processMap = (HashMap) templateInfo.get("processMap"); diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java b/designer_form/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java similarity index 100% rename from designer_base/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java rename to designer_form/src/com/fr/design/mainframe/templateinfo/JFormProcessInfo.java