From c76ae5431e2aba130b21b7870a56595e41b8f7d6 Mon Sep 17 00:00:00 2001 From: "John.Ying" Date: Mon, 29 Aug 2022 12:31:51 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-79108=20=E8=BF=9C=E7=A8=8B=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=EF=BC=8C=E5=AF=BC=E5=87=BA=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=88=B0=E6=8A=A5=E8=A1=A8=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/carton/FeedbackToolboxDialog.java | 102 ++++++++++++++---- 1 file changed, 82 insertions(+), 20 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java b/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java index e05d3626a1..f9aee284e2 100644 --- a/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java +++ b/designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java @@ -21,13 +21,26 @@ import com.fr.general.GeneralUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; +import com.fr.workspace.WorkContext; -import javax.swing.*; -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.UIManager; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Frame; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowEvent; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.text.ParseException; import java.util.List; @@ -44,6 +57,7 @@ public class FeedbackToolboxDialog extends JDialog { private final Color lineColor = new Color(192, 192, 192, 120); private JPanel body = null; private static final String WORK_SPACE_PATH = "reportlets"; + private static final int BUFFER_SIZE = 2 * 1024; public FeedbackToolboxDialog(Frame owner) { super(owner, Toolkit.i18nText("Fine-Design_Basic_Carton_Feedback_ToolBox")); @@ -93,7 +107,7 @@ public class FeedbackToolboxDialog extends JDialog { exportLogLabel.setForeground(UIConstants.FLESH_BLUE); exportLogLabel.addMouseListener(new MouseAdapter() { @Override - public void mousePressed(MouseEvent e) { + public void mouseClicked(MouseEvent e) { if (exportLogLabel.isEnabled()) { exportLogFile(); } @@ -127,24 +141,10 @@ public class FeedbackToolboxDialog extends JDialog { //selectDate 2002-03-09例子 String[] split = selectDate.split("-"); int month = Integer.parseInt(split[1]); - File sourceFile = new File(StableUtils.pathJoin(SwitchForSwingChecker.JOURNAL_FILE_PATH, split[0], "month-" + month, selectDate)); + String sourceFilePath = StableUtils.pathJoin(SwitchForSwingChecker.JOURNAL_FILE_PATH, split[0], "month-" + month, selectDate); + File sourceFile = new File(sourceFilePath); if (sourceFile.exists()) { - File[] files = sourceFile.listFiles(); - if (files != null) { - try { - if (path.startsWith(WORK_SPACE_PATH)) { - String curEnvName = DesignerEnvManager.getEnvManager().getCurEnvName(); - DesignerWorkspaceInfo workspaceInfo = DesignerEnvManager.getEnvManager().getWorkspaceInfo(curEnvName); - String workspaceInfoPath = workspaceInfo.getPath(); - path = new StringBuilder(workspaceInfoPath).append(path.substring(10)).toString(); - } - LogZipUtils.compress(files, path, false); - FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Report_Exported_Successfully")); - } catch (Exception exception) { - FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Report_Export_Failed"), UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.ERROR_MESSAGE); - FineLoggerFactory.getLogger().error("export file fail", exception); - } - } + exportCartonLog(sourceFile, path, sourceFilePath); } fileChooserPane.removeAllFilter(); } @@ -333,4 +333,66 @@ public class FeedbackToolboxDialog extends JDialog { uploadButton.setEnabled(flag); exportLogLabel.setEnabled(flag); } + + /** + * 导出卡顿日志到本地或远程服务器WEB-INF下 + * + * @param sourceFile 导出的卡顿日志所在文件夹 + * @param path 文件需要导出到的路径 + * @param sourceFilePath 导出的卡顿日志所在文件夹的路径 + */ + private void exportCartonLog(File sourceFile, String path, String sourceFilePath) { + File[] files = sourceFile.listFiles(); + if (files != null) { + try { + if (path.startsWith(WORK_SPACE_PATH)) { + if (WorkContext.getCurrent().isLocal()) { + String curEnvName = DesignerEnvManager.getEnvManager().getCurEnvName(); + DesignerWorkspaceInfo workspaceInfo = DesignerEnvManager.getEnvManager().getWorkspaceInfo(curEnvName); + String workspaceInfoPath = workspaceInfo.getPath(); + path = StableUtils.pathJoin(workspaceInfoPath, path); + LogZipUtils.compress(files, path, false); + } else { + String sourceFilePathZip = sourceFilePath + ".zip"; + LogZipUtils.compress(files, sourceFilePathZip, false); + byte[] bytesByFile = getBytesByFile(sourceFilePathZip); + WorkContext.getWorkResource().write(path, bytesByFile); + LogZipUtils.delDir(sourceFilePathZip); + } + } else { + LogZipUtils.compress(files, path, false); + } + FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Report_Exported_Successfully")); + } catch (Exception exception) { + FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Report_Export_Failed"), UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.ERROR_MESSAGE); + FineLoggerFactory.getLogger().error("export file fail", exception); + } + } + } + /** + * 根据文件地址将文件转换成byte[] + * + * @param pathStr 本地文件目录 + * @return 本地文件转成的byte[] + */ + public static byte[] getBytesByFile(String pathStr) { + File file = new File(pathStr); + try { + FileInputStream fis = new FileInputStream(file); + ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE); + byte[] b = new byte[BUFFER_SIZE]; + int n; + while ((n = fis.read(b)) != -1) { + bos.write(b, 0, n); + } + fis.close(); + byte[] data = bos.toByteArray(); + bos.close(); + return data; + } catch (Exception e) { + FineLoggerFactory.getLogger().error("reading local file fail", e); + } + return null; + } + }