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