From f3f8b4563b5e3c261e23de4af8e50b198df5b80a Mon Sep 17 00:00:00 2001 From: plough Date: Wed, 15 Mar 2017 11:32:20 +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=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=B0=86process=E5=92=8Cconsuming=E5=88=86=E7=A6=BB?= =?UTF-8?q?=EF=BC=8C=E6=9A=82=E6=97=B6=E4=B8=8D=E8=AE=B0=E5=BD=95=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=BF=87=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/TemplateProcessTracker.aj | 13 +- .../designerbase/TemplateProcessTracker.aj | 9 +- .../templateinfo/TemplateInfoCollector.java | 176 +++++++++++++----- .../templateinfo/TemplateProcessTracker.aj | 71 ------- .../designerchart/TemplateProcessTracker.aj | 9 +- .../designerform/TemplateProcessTracker.aj | 13 +- 6 files changed, 159 insertions(+), 132 deletions(-) delete mode 100644 designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessTracker.aj diff --git a/designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj b/designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj index 24dfc7351..0b3ea7083 100644 --- a/designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj +++ b/designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj @@ -33,7 +33,8 @@ public aspect TemplateProcessTracker { before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); +// String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } //同上 @@ -44,7 +45,8 @@ public aspect TemplateProcessTracker { return; } - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } @@ -56,7 +58,8 @@ public aspect TemplateProcessTracker { // return; // } - String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + //String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + String log = ""; TemplateInfoCollector.appendProcess(log); } @@ -65,9 +68,9 @@ public aspect TemplateProcessTracker { SourceLocation sl = thisJoinPoint.getSourceLocation(); // String v = "test"; - String log = String.format("%s:\n%s\nset value: %s at %s\n\n", new Date(), sl, v, g.getEditingCellElement()); + //String log = String.format("%s:\n%s\nset value: %s at %s\n\n", new Date(), sl, v, g.getEditingCellElement()); + String log = ""; TemplateInfoCollector.appendProcess(log); - } diff --git a/designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj b/designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj index 04e3fa2e4..b07ec9951 100644 --- a/designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj +++ b/designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj @@ -30,7 +30,8 @@ public aspect TemplateProcessTracker { before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } //同上 @@ -41,7 +42,8 @@ public aspect TemplateProcessTracker { return; } - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } @@ -53,7 +55,8 @@ public aspect TemplateProcessTracker { // return; // } - String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + //String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + String log = ""; TemplateInfoCollector.appendProcess(log); } 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 95ced6330..7c2ef0eab 100644 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java +++ b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java @@ -1,15 +1,21 @@ package com.fr.design.mainframe.templateinfo; +import com.fr.base.FRContext; 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.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.GeneralUtils; -import com.fr.stable.ProductConstants; -import com.fr.stable.StableUtils; +import com.fr.general.http.HttpClient; +import com.fr.stable.*; +import org.json.JSONObject; import java.io.*; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -51,7 +57,6 @@ public class TemplateInfoCollector implements Serializable { } public static void appendProcess(String log) { -// System.out.println(log); // 获取当前编辑的模板 JTemplate jt = DesignerContext.getDesignerFrame().getSelectedJTemplate(); // 追加过程记录 @@ -61,9 +66,10 @@ public class TemplateInfoCollector implements Serializable { /** * 加载已经存储的模板过程 */ + @SuppressWarnings("unchecked") public String loadProcess(T t) { -// return ""; - return (String)templateInfoList.get(t.getReportletsid()).get("process"); + HashMap processMap = (HashMap) templateInfoList.get(t.getReportletsid()).get("processMap"); + return (String)processMap.get("process"); } /** @@ -77,8 +83,8 @@ public class TemplateInfoCollector implements Serializable { private void saveInfo() { try { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile())); - System.out.println("写入:" + instance.templateInfoList); - os.writeObject(instance.templateInfoList); + System.out.println("写入:" + templateInfoList); + os.writeObject(templateInfoList); os.close(); } catch (Exception ex) { ex.printStackTrace(); @@ -99,53 +105,137 @@ public class TemplateInfoCollector implements Serializable { public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) { HashMap templateInfo; - if (inList(t)) { // 已有记录 + long timeConsume = saveTime - openTime; // 制作模板耗时 + String reportletsid = t.getReportletsid(); + + if (inList(t)) { // 已有记录 templateInfo = templateInfoList.get(t.getReportletsid()); - } else { // 新增 + // 更新 conusmingMap + HashMap consumingMap = (HashMap) templateInfo.get("consumingMap"); + timeConsume += (long)consumingMap.get("time_consume"); // 加上之前的累计编辑时间 + consumingMap.put("time_consume", timeConsume); + } + else { // 新增 templateInfo = new HashMap<>(); + templateInfo.put("consumingMap", getNewConsumingMap(reportletsid, openTime, timeConsume)); + } + + // 直接覆盖 processMap + templateInfo.put("processMap", getProcessMap(reportletsid, jt)); + + // TODO: 更新模板是否完成的标记 + + + templateInfoList.put(reportletsid, templateInfo); + + saveInfo(); // 每次更新之后,都同步到暂存文件中 + } + + private HashMap getNewConsumingMap(String reportletsid, long openTime, long timeConsume) { + HashMap consumingMap = new HashMap<>(); + + String username = DesignerEnvManager.getEnvManager().getBBSName(); + 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 jarTime = GeneralUtils.readBuildNO(); + String version = ProductConstants.VERSION; + consumingMap.put("username", username); + consumingMap.put("uuid", uuid); + consumingMap.put("activitykey", activitykey); + consumingMap.put("reportletsid", reportletsid); + consumingMap.put("create_time", createTime); + consumingMap.put("time_consume", timeConsume); + consumingMap.put("jar_time", jarTime); + consumingMap.put("version", version); + + return consumingMap; + } + + private HashMap getProcessMap(String reportletsid, JTemplate jt) { + HashMap processMap = 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); + processMap.put("reportletsid", reportletsid); + processMap.put("process", jt.getProcess()); + processMap.put("report_type", jt.getReportType()); + processMap.put("cell_count", jt.getCellCount()); + processMap.put("float_count", jt.getFloatCount()); + processMap.put("block_count", jt.getBlockCount()); + processMap.put("widget_count", jt.getWidgetCount()); + + return processMap; + } + + /** + * 发送本地模板信息到服务器 + */ + public void sendTemplateInfo() { + + 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"); + } } +// //服务器返回true, 说明已经获取成功, 清空当前记录的信息 +// if (success) { +// System.out.println("success"); +// } else { +// System.out.println("fail"); +// } + } - long timeConsume = saveTime - openTime; - // 如果已存有数据,则加上之前的累计编辑时间 - if (templateInfo.get("time_consume") != null) { - timeConsume += (long)templateInfo.get("time_consume"); + private boolean sendSingleTemplateInfo(String url, String content) { + HashMap para = new HashMap<>(); + String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); + para.put("token", CodeUtils.md5Encode(date, "", "MD5")); + para.put("content", content); +// para.put("content", "{name:3, age:3}"); +// HttpClient httpClient = new HttpClient("http://cloud.fanruan.com/api/monitor/record_of_make_reports/single", para, true); + HttpClient httpClient = new HttpClient(url, para, true); + + //httpClient.setContent(getCompleteTemplatesInfo()); + httpClient.setTimeout(5000); + httpClient.asGet(); + + if (!httpClient.isServerAlive()) { + return false; } - String process = jt.getProcess(); - int cellCount = jt.getCellCount(); - int floatCount = jt.getFloatCount(); - int blockCount = jt.getBlockCount(); - int widgetCount = jt.getWidgetCount(); - templateInfo.put("time_consume", timeConsume); - templateInfo.put("process", process); - 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); + String res = httpClient.getResponseText(); + boolean success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + return success; + } - saveInfo(); // 每次更新之后,都同步到暂存文件中 + // 返回已完成的模板信息 + @SuppressWarnings("unchecked") + private ArrayList> getCompleteTemplatesInfo() { + ArrayList> completeTemplatesInfo = new ArrayList<>(); + for (String key : templateInfoList.keySet()) { + HashMap templateInfo = new HashMap<>(); + HashMap consumingMap = (HashMap) templateInfoList.get(key).get("consumingMap"); + HashMap processMap = (HashMap) templateInfoList.get(key).get("processMap"); + String jsonConsumingMap = new JSONObject(consumingMap).toString(); + String jsonProcessMap = new JSONObject(processMap).toString(); + templateInfo.put("jsonConsumingMap", jsonConsumingMap); + templateInfo.put("jsonProcessMap", jsonProcessMap); + templateInfo.put("reportletsid", key); + completeTemplatesInfo.add(templateInfo); // TODO 暂未添加筛选条件 + } + return completeTemplatesInfo; } + + public static void main(String[] args) { TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); - tic.getInfoList(); +// tic.getInfoList(); + tic.sendTemplateInfo(); + } } diff --git a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessTracker.aj b/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessTracker.aj deleted file mode 100644 index d186f8298..000000000 --- a/designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessTracker.aj +++ /dev/null @@ -1,71 +0,0 @@ -//package com.fr.design.mainframe.templateinfo; -// -//import org.aspectj.lang.reflect.SourceLocation; -// -//import java.awt.event.ActionEvent; -//import java.awt.event.MouseEvent; -//import java.util.Date; -// -///** -// * 记录模板过程 -// * Created by plough on 2017/2/27. -// */ -//public aspect TemplateProcessTracker { -// //声明一个pointcut,匹配你需要的方法 -// pointcut onMouseClicked(MouseEvent e) : -// execution(* mouseClicked(MouseEvent)) && args(e); -// pointcut onMousePressed(MouseEvent e) : -// execution(* mousePressed(MouseEvent)) && args(e); -// pointcut onMouseReleased(MouseEvent e) : -// execution(* mouseReleased(MouseEvent)) && args(e); -// pointcut onActionPerformed(ActionEvent e) : -// execution(* actionPerformed(ActionEvent)) && args(e); -// pointcut onSetValueAt(Object v, int r, int c) : -// execution(* setValueAt(Object, int, int)) && args(v, r, c); -// pointcut onSetValue4EditingElement(Object v) : -// execution(* setValue4EditingElement(Object)) && args(v); -// -// //before表示之前的意思 -// //这整个表示在MouseAdapter的public void mouseXXX(MouseEvent)方法调用之前,你想要执行的代码 -// before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { -// SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 -// -// String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); -// TemplateInfoCollector.appendProcess(log); -// } -// //同上 -// before(ActionEvent e) : onActionPerformed(e) { -// SourceLocation sl = thisJoinPoint.getSourceLocation(); -// // !within(LogHandlerBar) 没用, 手动过滤 -// if (e.getSource().toString().contains("javax.swing.Timer")) { -// return; -// } -// -// String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); -// TemplateInfoCollector.appendProcess(log); -// -// } -// //同上 -// before(Object v, int r, int c) : onSetValueAt(v, r, c) { -// SourceLocation sl = thisJoinPoint.getSourceLocation(); -// // !within(LogHandlerBar) 没用, 手动过滤 -//// if (e.getSource().toString().contains("javax.swing.Timer")) { -//// return; -//// } -// -// String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); -// TemplateInfoCollector.appendProcess(log); -// -// } -// //同上 -// before(Object v) : onSetValue4EditingElement(v) { -// SourceLocation sl = thisJoinPoint.getSourceLocation(); -// -//// String v = "test"; -// String log = String.format("%s:\n%s\nset value: %s\n\n", new Date(), sl, v); -// TemplateInfoCollector.appendProcess(log); -// -// } -// -// -//} diff --git a/designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj b/designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj index c192a190d..51e86fd15 100644 --- a/designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj +++ b/designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj @@ -30,7 +30,8 @@ public aspect TemplateProcessTracker { before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } //同上 @@ -41,14 +42,16 @@ public aspect TemplateProcessTracker { return; } - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } //同上 before(Chart c) : onChartUpdate(c) { SourceLocation sl = thisJoinPoint.getSourceLocation(); - String log = String.format("%s:\n%s\n插入新图表:%s\n\n", new Date(), sl, c.getChartName()); + //String log = String.format("%s:\n%s\n插入新图表:%s\n\n", new Date(), sl, c.getChartName()); + String log = ""; TemplateInfoCollector.appendProcess(log); } diff --git a/designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj b/designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj index 885d21ecd..0aabeb362 100644 --- a/designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj +++ b/designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj @@ -28,7 +28,8 @@ public aspect TemplateProcessTracker { before(MouseEvent e) : onMouseClicked(e) || onMousePressed(e) || onMouseReleased(e) { SourceLocation sl = thisJoinPoint.getSourceLocation();//切面对应的代码位置 - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } //同上 @@ -39,19 +40,17 @@ public aspect TemplateProcessTracker { return; } - String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + //String log = String.format("%s:\n%s\n%s\n%s\n\n", new Date(), sl, e, e.getSource()); + String log = ""; TemplateInfoCollector.appendProcess(log); } //同上 before(Object v, int r, int c) : onSetValueAt(v, r, c) { SourceLocation sl = thisJoinPoint.getSourceLocation(); - // !within(LogHandlerBar) 没用, 手动过滤 -// if (e.getSource().toString().contains("javax.swing.Timer")) { -// return; -// } - String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + //String log = String.format("%s:\n%s\nset value: %s at (%d, %d)\n\n", new Date(), sl, v, r, c); + String log = ""; TemplateInfoCollector.appendProcess(log); }