From a74462497d009febbba793f947a1e1e1a46ec1df Mon Sep 17 00:00:00 2001 From: plough Date: Tue, 23 Apr 2019 12:12:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-16391=20=E3=80=9010.03=E5=9F=8B?= =?UTF-8?q?=E7=82=B9-=E6=A8=A1=E6=9D=BF=E3=80=91=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E6=A8=A1=E6=9D=BF=E5=8F=A6=E5=AD=98?= =?UTF-8?q?=E4=B8=BA=EF=BC=8C=E4=B8=8D=E4=BC=9A=E6=9C=89originid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/template/info/TemplateInfo.java | 4 +++ .../template/info/TemplateInfoCollector.java | 5 +--- .../info/TemplateInfoCollectorTest.java | 28 ++++++++++++++++++- .../design/mainframe/template/info/tpl.info | 4 +-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java index 4c45ce823e..ffd9aaf3b4 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfo.java @@ -102,6 +102,10 @@ class TemplateInfo implements XMLReadable, XMLWriter { return templateID; } + String getOriginID() { + return originID; + } + int getTimeConsume() { return (int)consumingMap.get(ATTR_TIME_CONSUME); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java index 30bfb5e1d6..c16c6b6275 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/template/info/TemplateInfoCollector.java @@ -75,11 +75,8 @@ public class TemplateInfoCollector implements XMLReadable, XMLWriter { TemplateInfo templateInfo; if (this.contains(templateID)) { templateInfo = templateInfoMap.get(templateID); - } else if (!this.contains(originID)) { - templateInfo = TemplateInfo.newInstance(templateID); - templateInfoMap.put(templateID, templateInfo); } else { - int originTime = templateInfoMap.get(originID).getTimeConsume(); + int originTime = this.contains(originID) ? templateInfoMap.get(originID).getTimeConsume() : 0; templateInfo = TemplateInfo.newInstance(templateID, originID, originTime); templateInfoMap.put(templateID, templateInfo); } diff --git a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java index 7b02f4bba2..e83a523fc4 100644 --- a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java +++ b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoCollectorTest.java @@ -66,9 +66,12 @@ public class TemplateInfoCollectorTest { @Test public void testReadXML() { + assertEquals(",,", DesignerOpenHistory.getInstance().toString()); + TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); - assertEquals("2019-04-18", Reflect.on(collector).field("designerOpenDate").get()); assertEquals(7, ((Map) Reflect.on(collector).field("templateInfoMap").get()).size()); + + assertEquals("2019-04-08,2019-04-03,2019-03-29", DesignerOpenHistory.getInstance().toString()); } @Test @@ -151,6 +154,29 @@ public class TemplateInfoCollectorTest { assertEquals(129, consumingMap.get("originTime")); } + @Test + public void testCollectInfoWhenSaveAsWithNoTrackOriginID() throws Exception { + setUpMockForNewInstance(); + + TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); + + String templateID = "423238d4-5223-22vj-vlsj-42jc49245iw3"; + String originID = "3kha8jcs-31xw-42f5-h2ww-2ee84935312z"; + int timeConsume = 200; + + collector.collectInfo(templateID, originID, mockProcessInfo, timeConsume); + + TemplateInfo templateInfo = collector.getOrCreateTemplateInfoByID(templateID); + assertEquals(templateID, templateInfo.getTemplateID()); + assertEquals(originID, templateInfo.getOriginID()); + + Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); + assertEquals(templateID, consumingMap.get("templateID")); + assertEquals(originID, consumingMap.get("originID")); + assertEquals(200, consumingMap.get("time_consume")); + assertEquals(0, consumingMap.get("originTime")); + } + @Test public void testAddIdleDateCount() { String templateID = "16a988ce-8529-42f5-b17c-2ee849355071"; diff --git a/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info b/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info index 39bec00067..eae77630fa 100644 --- a/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info +++ b/designer-base/src/test/resources/com/fr/design/mainframe/template/info/tpl.info @@ -1,7 +1,7 @@ - - + + From 6f1d52b6bb642730158d895fd505b352a6603893 Mon Sep 17 00:00:00 2001 From: 1 <1@qq> Date: Wed, 24 Apr 2019 15:56:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=88=A0=E9=99=A4=EF=BC=9B=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=82=B9=E4=B8=8A=E4=BC=A0=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AF=B9=E4=B8=8D=E4=B8=8A=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/FileEntityBuilder.java | 48 +++++++------------ .../impl/AbstractSendDataToCloud.java | 2 +- .../impl/FocusPointMessageUploader.java | 26 +++++----- 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java index c23a3b999b..24d14edf39 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java @@ -9,7 +9,6 @@ import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.stable.CommonUtils; import com.fr.stable.EncodeConstants; -import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.third.org.apache.http.HttpEntity; @@ -25,8 +24,11 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import static com.fr.third.org.apache.http.HttpStatus.SC_OK; @@ -41,41 +43,16 @@ public class FileEntityBuilder { private static final String ATTR_SIGNATURE = "signature"; private static final String ATTR_KEY = "key"; private static final String FOCUS_POINT_FILE_ROOT_PATH = "FocusPoint"; - /** - * 文件名 - */ - private String fileName; - /** - * 文件的完整路径 - */ - private String pathName; + /** * 文件夹路径 */ private String folderName; - public FileEntityBuilder(String fileName, String pathName, String folderName) { - this.fileName = fileName; - this.pathName = pathName; + public FileEntityBuilder(String folderName) { this.folderName = folderName; } - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public String getPathName() { - return pathName; - } - - public void setPathName(String pathName) { - this.pathName = pathName; - } - public String getFolderName() { return folderName; } @@ -97,14 +74,19 @@ public class FileEntityBuilder { return zipFile; } - public void generateFile(JSONArray jsonArray, String pathName) { + public void generateFile(JSONArray jsonArray, String folderName) { + if (jsonArray.size() == 0) { + return; + } try { String content = jsonArray.toString(); - File file = new File(pathName + ".json"); + String fileName = String.valueOf(UUID.randomUUID()); + File file = new File(folderName + File.separator + fileName + ".json"); StableUtils.makesureFileExist(file); FileOutputStream out = new FileOutputStream(file); InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8)); IOUtils.copyBinaryTo(in, out); + in.close(); out.close(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); @@ -112,7 +94,7 @@ public class FileEntityBuilder { } public void deleteFileAndZipFile(File zipFile, String pathName) { - File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), pathName)); + File file = new File(pathName); CommonUtils.deleteFile(file); CommonUtils.deleteFile(zipFile); } @@ -124,9 +106,11 @@ public class FileEntityBuilder { * @throws IOException */ public static void uploadFile(File file, String keyFileName) throws IOException { + Date today=new Date(); + SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd"); HttpClient httpclient = new DefaultHttpClient(); try { - String signedUrl = generateSignedUploadUrl(FOCUS_POINT_FILE_ROOT_PATH + File.separator +keyFileName); + String signedUrl = generateSignedUploadUrl(FOCUS_POINT_FILE_ROOT_PATH + File.separator + f.format(today) + File.separator +keyFileName); if(StringUtils.isEmpty(signedUrl)){ FineLoggerFactory.getLogger().error("signedUrl is null."); return; diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/AbstractSendDataToCloud.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/AbstractSendDataToCloud.java index b6d18235ea..4321d28187 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/AbstractSendDataToCloud.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/AbstractSendDataToCloud.java @@ -102,7 +102,7 @@ public abstract class AbstractSendDataToCloud implements XMLable { try { JSONArray jsonArray = dealWithSendFunctionContent(points); //生成json文件 - fileEntityBuilder.generateFile(jsonArray, getFileEntityBuilder().getPathName()); + fileEntityBuilder.generateFile(jsonArray, getFileEntityBuilder().getFolderName()); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/FocusPointMessageUploader.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/FocusPointMessageUploader.java index 668e7fa413..33adf8e2de 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/FocusPointMessageUploader.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/impl/FocusPointMessageUploader.java @@ -26,6 +26,7 @@ public class FocusPointMessageUploader extends AbstractSendDataToCloud { private static final String TAG = "FocusPointMessageTag"; private static final String SEPARATOR = "_"; private static final String FOCUS_POINT = "FocusPoint"; + private static final long DELTA = 24 * 3600 * 1000L; private static volatile FocusPointMessageUploader instance; public static FocusPointMessageUploader getInstance() { @@ -46,13 +47,13 @@ public class FocusPointMessageUploader extends AbstractSendDataToCloud { FocusPoint focusPoint = (FocusPoint)t; JSONObject jo = new JSONObject(); jo.put("id",focusPoint.getId()); - jo.put("text",focusPoint.getId()); - jo.put("source",focusPoint.getId()); - jo.put("time",focusPoint.getId()); - jo.put("username",focusPoint.getId()); - jo.put("ip",focusPoint.getId()); - jo.put("title",focusPoint.getId()); - jo.put("body",focusPoint.getId()); + jo.put("text",focusPoint.getText()); + jo.put("source",focusPoint.getSource()); + jo.put("time",focusPoint.getTime()); + jo.put("username",focusPoint.getUsername()); + jo.put("ip",focusPoint.getIp()); + jo.put("title",focusPoint.getTitle()); + jo.put("body",focusPoint.getBody()); ja.put(jo); } return ja; @@ -61,10 +62,13 @@ public class FocusPointMessageUploader extends AbstractSendDataToCloud { public void sendToCloudCenter() { MessageCollectUtils.readXMLFile(instance, getLastTimeFile()); long currentTime = new Date().getTime(); - long lastTIme = MessageCollectUtils.getLastTimeMillis(lastTime); + long lastTime = MessageCollectUtils.getLastTimeMillis(this.lastTime); + if (currentTime - lastTime <= DELTA) { + return; + } try { generatePath(); - queryData(currentTime, lastTIme, FocusPoint.class); + queryData(currentTime, lastTime, FocusPoint.class); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage()); } @@ -97,9 +101,7 @@ public class FocusPointMessageUploader extends AbstractSendDataToCloud { append(ProductConstants.MINOR_VERSION).append(SEPARATOR). append(uuid).append(SEPARATOR).append(bbsUserName).append(SEPARATOR). append(UUID.randomUUID()); - String fileName = String.valueOf(UUID.randomUUID()); - String pathName = StableUtils.pathJoin(ProductConstants.getEnvHome(), sb.toString(), fileName); String folderName = StableUtils.pathJoin(ProductConstants.getEnvHome(), sb.toString()); - setFileEntityBuilder(new FileEntityBuilder(fileName, pathName, folderName)); + setFileEntityBuilder(new FileEntityBuilder(folderName)); } } From 11d5a16adf592a8d27e219fe1c87aa43a4e08f80 Mon Sep 17 00:00:00 2001 From: 1 <1@qq> Date: Wed, 24 Apr 2019 19:16:10 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BD=BF=E7=94=A8JDateTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../messagecollect/entity/FileEntityBuilder.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java index 24d14edf39..2555a26329 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java @@ -11,6 +11,7 @@ import com.fr.stable.CommonUtils; import com.fr.stable.EncodeConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; +import com.fr.third.jodd.datetime.JDateTime; import com.fr.third.org.apache.http.HttpEntity; import com.fr.third.org.apache.http.HttpResponse; import com.fr.third.org.apache.http.client.HttpClient; @@ -24,8 +25,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -106,11 +105,10 @@ public class FileEntityBuilder { * @throws IOException */ public static void uploadFile(File file, String keyFileName) throws IOException { - Date today=new Date(); - SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd"); + String today = new JDateTime().toString("YYYY-MM-DD"); HttpClient httpclient = new DefaultHttpClient(); try { - String signedUrl = generateSignedUploadUrl(FOCUS_POINT_FILE_ROOT_PATH + File.separator + f.format(today) + File.separator +keyFileName); + String signedUrl = generateSignedUploadUrl(FOCUS_POINT_FILE_ROOT_PATH + File.separator + today + File.separator +keyFileName); if(StringUtils.isEmpty(signedUrl)){ FineLoggerFactory.getLogger().error("signedUrl is null."); return;