From 66f7e6fbcbc65d058d64aef67739971eb9884aec Mon Sep 17 00:00:00 2001 From: plough Date: Wed, 15 Mar 2017 16:21:02 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-1916=20=E5=81=9A=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=E8=BF=87=E7=A8=8B=E5=92=8C=E8=80=97=E6=97=B6=E6=94=B6?= =?UTF-8?q?=E9=9B=86=3D=E3=80=8B=E4=B8=8A=E4=BC=A0=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=89=8D=EF=BC=8C=E5=88=A4=E6=96=AD=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=98=AF=E5=90=A6=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/InformationCollector.java | 2 + .../templateinfo/TemplateInfoCollector.java | 90 +++++++++++++++---- 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/InformationCollector.java b/designer/src/com/fr/design/mainframe/InformationCollector.java index a4b3fc6ab6..f50cc5dadf 100644 --- a/designer/src/com/fr/design/mainframe/InformationCollector.java +++ b/designer/src/com/fr/design/mainframe/InformationCollector.java @@ -10,6 +10,7 @@ import com.fr.data.core.db.dml.Delete; import com.fr.data.core.db.dml.Select; import com.fr.data.core.db.dml.Table; import com.fr.design.DesignerEnvManager; +import com.fr.design.mainframe.templateinfo.TemplateInfoCollector; import com.fr.general.*; import com.fr.general.http.HttpClient; import com.fr.json.JSONArray; @@ -315,6 +316,7 @@ public class InformationCollector implements XMLReadable, XMLWriter { } sendFunctionsInfo(); sendUserInfo(); + TemplateInfoCollector.getInstance().sendTemplateInfo(); } }); sendThread.start(); 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 7c2ef0eab3..83c7c1d63b 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -27,19 +27,38 @@ public class TemplateInfoCollector implements Serializable { private static final String FILE_NAME = "tplInfo.ser"; private static TemplateInfoCollector instance; private HashMap> templateInfoList; + private String designerOpenDate; //设计器最近一次打开日期 @SuppressWarnings("unchecked") private TemplateInfoCollector() { - // 先尝试从文件读取 - try{ - ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile())); - templateInfoList = (HashMap>) is.readObject(); - } catch (FileNotFoundException ex) { - // 如果之前没有存储过,则创建新对象 - templateInfoList = new HashMap<>(); - } catch (Exception ex) { - FRLogger.getLogger().error(ex.getMessage(), ex); - } +// // 先尝试从文件读取 +// try{ +// ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile())); +//// templateInfoList = (HashMap>) is.readObject(); +// instance = (HashMap>) is.readObject(); +// } catch (FileNotFoundException ex) { +// // 如果之前没有存储过,则创建新对象 +// templateInfoList = new HashMap<>(); +// } catch (Exception ex) { +// FRLogger.getLogger().error(ex.getMessage(), ex); +// } + templateInfoList = new HashMap<>(); + setDesignerOpenDate(); + } + + /** + * 把设计器最近打开日期设定为当前日期 + */ + private void setDesignerOpenDate() { + designerOpenDate = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); + } + + /** + * 判断今天是否第一次打开设计器 + */ + private boolean designerOpenFirstTime() { + String today = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); + return !ComparatorUtils.equals(today, designerOpenDate); } /** @@ -50,8 +69,21 @@ public class TemplateInfoCollector implements Serializable { } public static TemplateInfoCollector getInstance() { +// if (instance == null) { +// instance = new TemplateInfoCollector(); +// } +// return instance; if (instance == null) { - instance = new TemplateInfoCollector(); + // 先尝试从文件读取 + try{ + ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile())); + instance = (TemplateInfoCollector) is.readObject(); + } catch (FileNotFoundException ex) { + // 如果之前没有存储过,则创建新对象 + instance = new TemplateInfoCollector(); + } catch (Exception ex) { + FRLogger.getLogger().error(ex.getMessage(), ex); + } } return instance; } @@ -83,8 +115,8 @@ public class TemplateInfoCollector implements Serializable { private void saveInfo() { try { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile())); - System.out.println("写入:" + templateInfoList); - os.writeObject(templateInfoList); + System.out.println("写入:" + instance.templateInfoList); + os.writeObject(instance); os.close(); } catch (Exception ex) { ex.printStackTrace(); @@ -98,6 +130,20 @@ public class TemplateInfoCollector implements Serializable { return templateInfoList; } + /** + * 更新 day_count:打开设计器却未编辑模板的连续日子 + */ + private void addDayCount() { + if (designerOpenFirstTime()) { + for (String key : templateInfoList.keySet()) { + HashMap templateInfo = templateInfoList.get(key); + int dayCount = (int)templateInfo.get("day_count") + 1; + templateInfo.put("day_count", dayCount); + } + setDesignerOpenDate(); + } + } + /** * 收集模板信息。如果之前没有记录,则新增;如果已有记录,则更新。 * 同时将最新数据保存到文件中。 @@ -105,7 +151,7 @@ public class TemplateInfoCollector implements Serializable { public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) { HashMap templateInfo; - long timeConsume = saveTime - openTime; // 制作模板耗时 + long timeConsume = ((saveTime - openTime) / 1000); // 制作模板耗时(单位:s) String reportletsid = t.getReportletsid(); if (inList(t)) { // 已有记录 @@ -123,7 +169,8 @@ public class TemplateInfoCollector implements Serializable { // 直接覆盖 processMap templateInfo.put("processMap", getProcessMap(reportletsid, jt)); - // TODO: 更新模板是否完成的标记 + // 保存模板时,让 day_count 归零 + templateInfo.put("day_count", 0); templateInfoList.put(reportletsid, templateInfo); @@ -138,7 +185,7 @@ public class TemplateInfoCollector implements Serializable { String uuid = DesignerEnvManager.getEnvManager().getUUID(); String activitykey = DesignerEnvManager.getEnvManager().getActivationKey(); // String createTime = new Date(openTime).toString(); - String createTime = new SimpleDateFormat("yyyy-MM-dd hh:mm").format(Calendar.getInstance().getTime()); + String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()); String jarTime = GeneralUtils.readBuildNO(); String version = ProductConstants.VERSION; consumingMap.put("username", username); @@ -171,17 +218,19 @@ public class TemplateInfoCollector implements Serializable { * 发送本地模板信息到服务器 */ public void sendTemplateInfo() { - + addDayCount(); String url1 = "http://cloud.fanruan.com/api/monitor/record_of_make_reports/single"; ArrayList> completeTemplatesInfo = getCompleteTemplatesInfo(); for (HashMap templateInfo : completeTemplatesInfo) { String jsonConsumingMap = templateInfo.get("jsonConsumingMap"); String jsonProcessMap = templateInfo.get("jsonProcessMap"); if (sendSingleTemplateInfo(url1, jsonConsumingMap) && sendSingleTemplateInfo(url1, jsonProcessMap)) { - // TODO: 清空记录 + // 清空记录 System.out.println("success"); + templateInfoList.remove(templateInfo.get("reportletsid")); } } + saveInfo(); // //服务器返回true, 说明已经获取成功, 清空当前记录的信息 // if (success) { // System.out.println("success"); @@ -217,6 +266,9 @@ public class TemplateInfoCollector implements Serializable { private ArrayList> getCompleteTemplatesInfo() { ArrayList> completeTemplatesInfo = new ArrayList<>(); for (String key : templateInfoList.keySet()) { + if ((int)templateInfoList.get(key).get("day_count") <= 15) { // 未完成模板 + continue; + } HashMap templateInfo = new HashMap<>(); HashMap consumingMap = (HashMap) templateInfoList.get(key).get("consumingMap"); HashMap processMap = (HashMap) templateInfoList.get(key).get("processMap"); @@ -234,7 +286,7 @@ public class TemplateInfoCollector implements Serializable { public static void main(String[] args) { TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); -// tic.getInfoList(); + tic.getInfoList(); tic.sendTemplateInfo(); }