Browse Source

REPORT-13431 功能点记录, 需要合并发送

换用multiple方式合并多条记录
bugfix/10.0
alex.sung 6 years ago
parent
commit
d88f4f9dd8
  1. 43
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

43
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -104,6 +104,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private static final String ATTR_TITLE = "title";
private static final String ATTR_USER_NAME = "username";
private static final String ATTR_UUID = "uuid";
private static final String ATTR_FUNCTION_ARRAY = "functionArray";
private static InformationCollector collector;
@ -232,21 +233,23 @@ public class InformationCollector implements XMLReadable, XMLWriter {
if (currentTime - lastTime <= DELTA) {
return;
}
ArrayList<Map<String, Object>> content = null;
JSONArray content = null;
try {
content = getFunctionsContent(current, new Date(lastTime));
} catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
boolean success = false;
FineLoggerFactory.getLogger().info("Start sent function records to the cloud center...");
String url = CloudCenter.getInstance().acquireUrlByKind(TABLE_FUNCTION_RECORD);
if(content.size() > 0){
for(int i=0; i<content.size(); i++){
success = sendFunctionRecord(url, content.get(i));
}
if(content.length() > 0){
success = sendFunctionRecord(url, content);
//服务器返回true, 说明已经获取成功, 更新最后一次发送时间
if (success) {
this.lastTime = dateToString();
FineLoggerFactory.getLogger().info("Function records successfully sent to the cloud center.");
}
}
FineLoggerFactory.getLogger().info("Function records successfully sent to the cloud center.");
// //先将发送压缩文件这段代码注释,之后提任务
//大数据量下发送压缩zip数据不容易丢失
// try {
@ -265,11 +268,13 @@ public class InformationCollector implements XMLReadable, XMLWriter {
// }
}
private boolean sendFunctionRecord(String url, Map<String,Object> record) {
private boolean sendFunctionRecord(String url, JSONArray record) {
boolean success = false;
try {
String recordUrl = url+"?token=" + SiteCenterToken.generateToken() + "&content="+URLEncoder.encode(new JSONObject(record).toString(), EncodeConstants.ENCODING_UTF_8);
String res = HttpToolbox.get(recordUrl);
HashMap<String, Object> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken());
para.put("content", record);
String res = HttpToolbox.post(url, para);
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success");
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
@ -437,33 +442,33 @@ public class InformationCollector implements XMLReadable, XMLWriter {
});
}
public static ArrayList getFunctionsContent(Date current, Date last){
ArrayList<Map<String,Object>> records = new ArrayList<Map<String,Object>>();
public static JSONArray getFunctionsContent(Date current, Date last) throws JSONException{
JSONArray functionArray = new JSONArray();
QueryCondition condition = QueryFactory.create()
.addRestriction(RestrictionFactory.lte(COLUMN_TIME, current))
.addRestriction(RestrictionFactory.gte(COLUMN_TIME, last));
try {
DataList<FocusPoint> focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition);
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
String bbsUserName = MarketConfig.getInstance().getBbsUsername();
String uuid = envManager.getUUID();
if(!focusPoints.isEmpty()){
for(FocusPoint focusPoint : focusPoints.getList()){
Map<String,Object> record = new HashMap<>();
com.fr.json.JSONObject record = new com.fr.json.JSONObject();
record.put(ATTR_ID, focusPoint.getId());
record.put(ATTR_TEXT, focusPoint.getText());
record.put(ATTR_SOURCE, focusPoint.getSource());
record.put(ATTR_TIME, focusPoint.getTime().getTime());
record.put(ATTR_TITLE, focusPoint.getTitle());
record.put(ATTR_USER_NAME, bbsUserName);
record.put(ATTR_UUID, uuid);
records.add(record);
record.put(ATTR_USER_NAME, MarketConfig.getInstance().getBbsUsername());
record.put(ATTR_UUID, DesignerEnvManager.getEnvManager().getUUID());
record.put(ATTR_FUNCTION_ARRAY, functionArray);
functionArray.put(record);
}
}
} catch (MetricException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return records;
return functionArray;
}
private class StartStopTime implements XMLReadable, XMLWriter {

Loading…
Cancel
Save