Browse Source

REPORT-1916 做模板的过程和耗时收集=》上传模板数据前,判断模板是否完成

master
plough 8 years ago
parent
commit
66f7e6fbcb
  1. 2
      designer/src/com/fr/design/mainframe/InformationCollector.java
  2. 90
      designer_base/src/com/fr/design/mainframe/templateinfo/TemplateInfoCollector.java

2
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.Select;
import com.fr.data.core.db.dml.Table; import com.fr.data.core.db.dml.Table;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.general.*; import com.fr.general.*;
import com.fr.general.http.HttpClient; import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
@ -315,6 +316,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
} }
sendFunctionsInfo(); sendFunctionsInfo();
sendUserInfo(); sendUserInfo();
TemplateInfoCollector.getInstance().sendTemplateInfo();
} }
}); });
sendThread.start(); sendThread.start();

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

@ -27,19 +27,38 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
private static final String FILE_NAME = "tplInfo.ser"; private static final String FILE_NAME = "tplInfo.ser";
private static TemplateInfoCollector instance; private static TemplateInfoCollector instance;
private HashMap<String, HashMap<String, Object>> templateInfoList; private HashMap<String, HashMap<String, Object>> templateInfoList;
private String designerOpenDate; //设计器最近一次打开日期
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private TemplateInfoCollector() { private TemplateInfoCollector() {
// 先尝试从文件读取 // // 先尝试从文件读取
try{ // try{
ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile())); // ObjectInputStream is = new ObjectInputStream(new FileInputStream(getInfoFile()));
templateInfoList = (HashMap<String, HashMap<String,Object>>) is.readObject(); //// templateInfoList = (HashMap<String, HashMap<String,Object>>) is.readObject();
} catch (FileNotFoundException ex) { // instance = (HashMap<String, HashMap<String,Object>>) is.readObject();
// 如果之前没有存储过,则创建新对象 // } catch (FileNotFoundException ex) {
templateInfoList = new HashMap<>(); // // 如果之前没有存储过,则创建新对象
} catch (Exception ex) { // templateInfoList = new HashMap<>();
FRLogger.getLogger().error(ex.getMessage(), ex); // } 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<T extends IOFile> implements Serializable {
} }
public static TemplateInfoCollector getInstance() { public static TemplateInfoCollector getInstance() {
// if (instance == null) {
// instance = new TemplateInfoCollector();
// }
// return instance;
if (instance == null) { 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; return instance;
} }
@ -83,8 +115,8 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
private void saveInfo() { private void saveInfo() {
try { try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile())); ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getInfoFile()));
System.out.println("写入:" + templateInfoList); System.out.println("写入:" + instance.templateInfoList);
os.writeObject(templateInfoList); os.writeObject(instance);
os.close(); os.close();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -98,6 +130,20 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
return templateInfoList; return templateInfoList;
} }
/**
* 更新 day_count打开设计器却未编辑模板的连续日子
*/
private void addDayCount() {
if (designerOpenFirstTime()) {
for (String key : templateInfoList.keySet()) {
HashMap<String, Object> 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<T extends IOFile> implements Serializable {
public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) { public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) {
HashMap<String, Object> templateInfo; HashMap<String, Object> templateInfo;
long timeConsume = saveTime - openTime; // 制作模板耗时 long timeConsume = ((saveTime - openTime) / 1000); // 制作模板耗时(单位:s)
String reportletsid = t.getReportletsid(); String reportletsid = t.getReportletsid();
if (inList(t)) { // 已有记录 if (inList(t)) { // 已有记录
@ -123,7 +169,8 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
// 直接覆盖 processMap // 直接覆盖 processMap
templateInfo.put("processMap", getProcessMap(reportletsid, jt)); templateInfo.put("processMap", getProcessMap(reportletsid, jt));
// TODO: 更新模板是否完成的标记 // 保存模板时,让 day_count 归零
templateInfo.put("day_count", 0);
templateInfoList.put(reportletsid, templateInfo); templateInfoList.put(reportletsid, templateInfo);
@ -138,7 +185,7 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
String uuid = DesignerEnvManager.getEnvManager().getUUID(); String uuid = DesignerEnvManager.getEnvManager().getUUID();
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey(); String activitykey = DesignerEnvManager.getEnvManager().getActivationKey();
// String createTime = new Date(openTime).toString(); // 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 jarTime = GeneralUtils.readBuildNO();
String version = ProductConstants.VERSION; String version = ProductConstants.VERSION;
consumingMap.put("username", username); consumingMap.put("username", username);
@ -171,17 +218,19 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
* 发送本地模板信息到服务器 * 发送本地模板信息到服务器
*/ */
public void sendTemplateInfo() { public void sendTemplateInfo() {
addDayCount();
String url1 = "http://cloud.fanruan.com/api/monitor/record_of_make_reports/single"; String url1 = "http://cloud.fanruan.com/api/monitor/record_of_make_reports/single";
ArrayList<HashMap<String, String>> completeTemplatesInfo = getCompleteTemplatesInfo(); ArrayList<HashMap<String, String>> completeTemplatesInfo = getCompleteTemplatesInfo();
for (HashMap<String, String> templateInfo : completeTemplatesInfo) { for (HashMap<String, String> templateInfo : completeTemplatesInfo) {
String jsonConsumingMap = templateInfo.get("jsonConsumingMap"); String jsonConsumingMap = templateInfo.get("jsonConsumingMap");
String jsonProcessMap = templateInfo.get("jsonProcessMap"); String jsonProcessMap = templateInfo.get("jsonProcessMap");
if (sendSingleTemplateInfo(url1, jsonConsumingMap) && sendSingleTemplateInfo(url1, jsonProcessMap)) { if (sendSingleTemplateInfo(url1, jsonConsumingMap) && sendSingleTemplateInfo(url1, jsonProcessMap)) {
// TODO: 清空记录 // 清空记录
System.out.println("success"); System.out.println("success");
templateInfoList.remove(templateInfo.get("reportletsid"));
} }
} }
saveInfo();
// //服务器返回true, 说明已经获取成功, 清空当前记录的信息 // //服务器返回true, 说明已经获取成功, 清空当前记录的信息
// if (success) { // if (success) {
// System.out.println("success"); // System.out.println("success");
@ -217,6 +266,9 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
private ArrayList<HashMap<String, String>> getCompleteTemplatesInfo() { private ArrayList<HashMap<String, String>> getCompleteTemplatesInfo() {
ArrayList<HashMap<String, String>> completeTemplatesInfo = new ArrayList<>(); ArrayList<HashMap<String, String>> completeTemplatesInfo = new ArrayList<>();
for (String key : templateInfoList.keySet()) { for (String key : templateInfoList.keySet()) {
if ((int)templateInfoList.get(key).get("day_count") <= 15) { // 未完成模板
continue;
}
HashMap<String, String> templateInfo = new HashMap<>(); HashMap<String, String> templateInfo = new HashMap<>();
HashMap<String, Object> consumingMap = (HashMap<String, Object>) templateInfoList.get(key).get("consumingMap"); HashMap<String, Object> consumingMap = (HashMap<String, Object>) templateInfoList.get(key).get("consumingMap");
HashMap<String, Object> processMap = (HashMap<String, Object>) templateInfoList.get(key).get("processMap"); HashMap<String, Object> processMap = (HashMap<String, Object>) templateInfoList.get(key).get("processMap");
@ -234,7 +286,7 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable {
public static void main(String[] args) { public static void main(String[] args) {
TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); TemplateInfoCollector tic = TemplateInfoCollector.getInstance();
// tic.getInfoList(); tic.getInfoList();
tic.sendTemplateInfo(); tic.sendTemplateInfo();
} }

Loading…
Cancel
Save