Browse Source

REPORT-79108 远程的时候,导出卡顿记录到报表工作目录失败

newui
John.Ying 2 years ago
parent
commit
c76ae5431e
  1. 102
      designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java

102
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;
}
}

Loading…
Cancel
Save