Browse Source

REPORT-1916 做模板的过程和耗时收集=》重构代码,将process和consuming分离,暂时不记录模板过程

master
plough 8 years ago
parent
commit
f3f8b4563b
  1. 13
      designer/src/com/fr/aspectj/designer/TemplateProcessTracker.aj
  2. 9
      designer_base/src/com/fr/aspectj/designerbase/TemplateProcessTracker.aj
  3. 176
      designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java
  4. 71
      designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessTracker.aj
  5. 9
      designer_chart/src/com/fr/aspectj/designerchart/TemplateProcessTracker.aj
  6. 13
      designer_form/src/com/fr/aspectj/designerform/TemplateProcessTracker.aj

13
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);
}

9
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);
}

176
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<T extends IOFile> implements Serializable {
}
public static void appendProcess(String log) {
// System.out.println(log);
// 获取当前编辑的模板
JTemplate jt = DesignerContext.getDesignerFrame().getSelectedJTemplate();
// 追加过程记录
@ -61,9 +66,10 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
/**
* 加载已经存储的模板过程
*/
@SuppressWarnings("unchecked")
public String loadProcess(T t) {
// return "";
return (String)templateInfoList.get(t.getReportletsid()).get("process");
HashMap<String, Object> processMap = (HashMap<String, Object>) templateInfoList.get(t.getReportletsid()).get("processMap");
return (String)processMap.get("process");
}
/**
@ -77,8 +83,8 @@ public class TemplateInfoCollector<T extends IOFile> 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<T extends IOFile> implements Serializable {
public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) {
HashMap<String, Object> templateInfo;
if (inList(t)) { // 已有记录
long timeConsume = saveTime - openTime; // 制作模板耗时
String reportletsid = t.getReportletsid();
if (inList(t)) { // 已有记录
templateInfo = templateInfoList.get(t.getReportletsid());
} else { // 新增
// 更新 conusmingMap
HashMap<String, Object> consumingMap = (HashMap<String, Object>) 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<String, Object> getNewConsumingMap(String reportletsid, long openTime, long timeConsume) {
HashMap<String, Object> 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<String, Object> getProcessMap(String reportletsid, JTemplate jt) {
HashMap<String, Object> 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<HashMap<String, String>> completeTemplatesInfo = getCompleteTemplatesInfo();
for (HashMap<String, String> 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<String, String> 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<HashMap<String, String>> getCompleteTemplatesInfo() {
ArrayList<HashMap<String, String>> completeTemplatesInfo = new ArrayList<>();
for (String key : templateInfoList.keySet()) {
HashMap<String, String> templateInfo = new HashMap<>();
HashMap<String, Object> consumingMap = (HashMap<String, Object>) templateInfoList.get(key).get("consumingMap");
HashMap<String, Object> processMap = (HashMap<String, Object>) 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();
}
}

71
designer_base/src/com/fr/design/mainframe/templateinfo/TemplateProcessTracker.aj

@ -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);
//
// }
//
//
//}

9
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);
}

13
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);
}

Loading…
Cancel
Save