|
|
@ -1,15 +1,21 @@ |
|
|
|
package com.fr.design.mainframe.templateinfo; |
|
|
|
package com.fr.design.mainframe.templateinfo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
import com.fr.base.io.IOFile; |
|
|
|
import com.fr.base.io.IOFile; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
import com.fr.design.DesignerEnvManager; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.mainframe.DesignerContext; |
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
import com.fr.design.mainframe.JTemplate; |
|
|
|
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
import com.fr.general.FRLogger; |
|
|
|
import com.fr.general.FRLogger; |
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
import com.fr.stable.ProductConstants; |
|
|
|
import com.fr.general.http.HttpClient; |
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
import com.fr.stable.*; |
|
|
|
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
import java.io.*; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
|
|
@ -51,7 +57,6 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void appendProcess(String log) { |
|
|
|
public static void appendProcess(String log) { |
|
|
|
// System.out.println(log);
|
|
|
|
|
|
|
|
// 获取当前编辑的模板
|
|
|
|
// 获取当前编辑的模板
|
|
|
|
JTemplate jt = DesignerContext.getDesignerFrame().getSelectedJTemplate(); |
|
|
|
JTemplate jt = DesignerContext.getDesignerFrame().getSelectedJTemplate(); |
|
|
|
// 追加过程记录
|
|
|
|
// 追加过程记录
|
|
|
@ -61,9 +66,10 @@ public class TemplateInfoCollector<T extends IOFile> implements Serializable { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 加载已经存储的模板过程 |
|
|
|
* 加载已经存储的模板过程 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public String loadProcess(T t) { |
|
|
|
public String loadProcess(T t) { |
|
|
|
// return "";
|
|
|
|
HashMap<String, Object> processMap = (HashMap<String, Object>) templateInfoList.get(t.getReportletsid()).get("processMap"); |
|
|
|
return (String)templateInfoList.get(t.getReportletsid()).get("process"); |
|
|
|
return (String)processMap.get("process"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -77,8 +83,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("写入:" + instance.templateInfoList); |
|
|
|
System.out.println("写入:" + templateInfoList); |
|
|
|
os.writeObject(instance.templateInfoList); |
|
|
|
os.writeObject(templateInfoList); |
|
|
|
os.close(); |
|
|
|
os.close(); |
|
|
|
} catch (Exception ex) { |
|
|
|
} catch (Exception ex) { |
|
|
|
ex.printStackTrace(); |
|
|
|
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) { |
|
|
|
public void collectInfo(T t, JTemplate jt, long openTime, long saveTime) { |
|
|
|
HashMap<String, Object> templateInfo; |
|
|
|
HashMap<String, Object> templateInfo; |
|
|
|
|
|
|
|
|
|
|
|
if (inList(t)) { // 已有记录
|
|
|
|
long timeConsume = saveTime - openTime; // 制作模板耗时
|
|
|
|
|
|
|
|
String reportletsid = t.getReportletsid(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inList(t)) { // 已有记录
|
|
|
|
templateInfo = templateInfoList.get(t.getReportletsid()); |
|
|
|
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 = 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(); |
|
|
|
processMap.put("reportletsid", reportletsid); |
|
|
|
String uuid = DesignerEnvManager.getEnvManager().getUUID(); |
|
|
|
processMap.put("process", jt.getProcess()); |
|
|
|
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey(); |
|
|
|
processMap.put("report_type", jt.getReportType()); |
|
|
|
String reportletsid = t.getReportletsid(); |
|
|
|
processMap.put("cell_count", jt.getCellCount()); |
|
|
|
String createTime = new Date(openTime).toString(); |
|
|
|
processMap.put("float_count", jt.getFloatCount()); |
|
|
|
int reportType = jt.getReportType(); |
|
|
|
processMap.put("block_count", jt.getBlockCount()); |
|
|
|
String jarTime = GeneralUtils.readBuildNO(); |
|
|
|
processMap.put("widget_count", jt.getWidgetCount()); |
|
|
|
String version = ProductConstants.VERSION; |
|
|
|
|
|
|
|
templateInfo.put("username", username); |
|
|
|
return processMap; |
|
|
|
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); |
|
|
|
public void sendTemplateInfo() { |
|
|
|
templateInfo.put("version", version); |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
private boolean sendSingleTemplateInfo(String url, String content) { |
|
|
|
// 如果已存有数据,则加上之前的累计编辑时间
|
|
|
|
HashMap<String, String> para = new HashMap<>(); |
|
|
|
if (templateInfo.get("time_consume") != null) { |
|
|
|
String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); |
|
|
|
timeConsume += (long)templateInfo.get("time_consume"); |
|
|
|
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(); |
|
|
|
String res = httpClient.getResponseText(); |
|
|
|
int cellCount = jt.getCellCount(); |
|
|
|
boolean success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); |
|
|
|
int floatCount = jt.getFloatCount(); |
|
|
|
return success; |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
public static void main(String[] args) { |
|
|
|
TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); |
|
|
|
TemplateInfoCollector tic = TemplateInfoCollector.getInstance(); |
|
|
|
tic.getInfoList(); |
|
|
|
// tic.getInfoList();
|
|
|
|
|
|
|
|
tic.sendTemplateInfo(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|