From d88f4f9dd8c9388f06db45c37e9cc4bf2e08b012 Mon Sep 17 00:00:00 2001 From: "alex.sung" Date: Mon, 10 Dec 2018 16:41:28 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-13431=20=E5=8A=9F=E8=83=BD=E7=82=B9?= =?UTF-8?q?=E8=AE=B0=E5=BD=95,=20=E9=9C=80=E8=A6=81=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E9=80=81=20=E6=8D=A2=E7=94=A8multiple=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=90=88=E5=B9=B6=E5=A4=9A=E6=9D=A1=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/InformationCollector.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java b/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java index 6f3c9bdea7..4dafbeccd6 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java +++ b/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> content = null; - content = getFunctionsContent(current, new Date(lastTime)); + 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 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,12 +268,14 @@ public class InformationCollector implements XMLReadable, XMLWriter { // } } - private boolean sendFunctionRecord(String url, Map 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); - success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); + HashMap 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> records = new ArrayList>(); + 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 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 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 {