Browse Source

代码质量

research/10.0
alex.sung 6 years ago
parent
commit
ec5f13f510
  1. 69
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

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

@ -96,6 +96,13 @@ public class InformationCollector implements XMLReadable, XMLWriter {
public static final String FUNC_COLUMNNAME = "func"; public static final String FUNC_COLUMNNAME = "func";
public static final String COLUMN_TIME = "time"; public static final String COLUMN_TIME = "time";
public static final String TABLE_FUNCTION_RECORD = "function.record"; public static final String TABLE_FUNCTION_RECORD = "function.record";
private static final String ATTR_ID = "id";
private static final String ATTR_TEXT = "text";
private static final String ATTR_SOURCE = "source";
private static final String ATTR_TIME = "time";
private static final String ATTR_TITLE = "title";
private static final String ATTR_USER_NAME = "username";
private static final String ATTR_UUID = "uuid";
private static InformationCollector collector; private static InformationCollector collector;
@ -219,21 +226,29 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private void sendFunctionsInfo(){ private void sendFunctionsInfo(){
long currentTime = new Date().getTime(); long currentTime = new Date().getTime();
long lastTime = getLastTimeMillis(); ArrayList<Map<String, Object>> content = null;
if (currentTime - lastTime <= DELTA) {
return;
}
String content = null;
try { try {
content = getFunctionsContentAsByte(currentTime); content = getFunctionsContentAsByte(currentTime);
} catch (JSONException e) { } catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
if(StringUtils.isNotEmpty(content)){ boolean success = false;
HashMap<String, String> para = new HashMap<>();
String url = CloudCenter.getInstance().acquireUrlByKind(TABLE_FUNCTION_RECORD); 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));
}
//服务器返回true, 说明已经获取成功, 清空当前记录的信息
if (success) {
deleteFunctionRecords(currentTime);
}
}
}
private boolean sendFunctionRecord(String url, Map<String,Object> record) {
HashMap<String, String> para = new HashMap<>();
para.put("token", SiteCenterToken.generateToken()); para.put("token", SiteCenterToken.generateToken());
para.put("content", content); para.put("content", new JSONObject(record).toString());
String res = null; String res = null;
try { try {
res = HttpToolbox.get(url, para); res = HttpToolbox.get(url, para);
@ -246,11 +261,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
} catch (JSONException e) { } catch (JSONException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
//服务器返回true, 说明已经获取成功, 清空当前记录的信息 return success;
if (success) {
deleteFunctionRecords(currentTime);
}
}
} }
/** /**
@ -413,34 +424,34 @@ public class InformationCollector implements XMLReadable, XMLWriter {
}); });
} }
public static String getFunctionsContentAsByte(long currentTime) throws JSONException{ public static ArrayList getFunctionsContentAsByte(long currentTime) throws JSONException{
com.fr.json.JSONObject content = new com.fr.json.JSONObject(); ArrayList<Map<String,Object>> records = new ArrayList<Map<String,Object>>();
QueryCondition condition = QueryFactory.create().addRestriction( QueryCondition condition = QueryFactory.create().addRestriction(
RestrictionFactory.lte(COLUMN_TIME, currentTime) RestrictionFactory.lte(COLUMN_TIME, currentTime)
); );
try { try {
DataList<FocusPoint> focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition); DataList<FocusPoint> focusPoints = MetricRegistry.getMetric().find(FocusPoint.class,condition);
JSONArray functionArray = new JSONArray(); focusPoints.getList();
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
String bbsUserName = MarketConfig.getInstance().getBbsUsername();
String uuid = envManager.getUUID();
if(!focusPoints.isEmpty()){ if(!focusPoints.isEmpty()){
for(FocusPoint focusPoint : focusPoints.getList()){ for(FocusPoint focusPoint : focusPoints.getList()){
com.fr.json.JSONObject jsonObject = new com.fr.json.JSONObject(); Map<String,Object> record = new HashMap<>();
jsonObject.put("id", focusPoint.getId()); record.put(ATTR_ID, focusPoint.getId());
jsonObject.put("text", focusPoint.getText()); record.put(ATTR_TEXT, focusPoint.getText());
jsonObject.put("source", focusPoint.getSource()); record.put(ATTR_SOURCE, focusPoint.getSource());
jsonObject.put("time", focusPoint.getTime()); record.put(ATTR_TIME, focusPoint.getTime().getTime());
jsonObject.put("title", focusPoint.getTitle()); record.put(ATTR_TITLE, focusPoint.getTitle());
functionArray.put(jsonObject); record.put(ATTR_USER_NAME, bbsUserName);
record.put(ATTR_UUID, uuid);
records.add(record);
} }
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
content.put("username", MarketConfig.getInstance().getBbsUsername());
content.put("uuid", envManager.getUUID());
content.put("functions", functionArray);
} }
} catch (MetricException e) { } catch (MetricException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} }
return content.toString(); return records;
} }
private void deleteFunctionRecords(long currentTime) { private void deleteFunctionRecords(long currentTime) {

Loading…
Cancel
Save