Browse Source

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

Merge in DESIGN/design from ~JOHN.YING/design:release/11.0 to release/11.0

* commit '4010d3692b58c155031aafee000c686459b074df':
  REPORT-79108 导出卡顿日志默认选择桌面
  REPORT-79108 远程的时候,导出卡顿记录到报表工作目录失败
newui
John.Ying 2 years ago
parent
commit
4f446016f3
  1. 114
      designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java

114
designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java

@ -16,21 +16,39 @@ import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.env.detect.ui.EnvDetectorDialog; import com.fr.env.detect.ui.EnvDetectorDialog;
import com.fr.file.FILE; import com.fr.file.FILE;
import com.fr.file.FILEChooserPane; import com.fr.file.FILEChooserPane;
import com.fr.file.FILEFactory;
import com.fr.file.FileFILE;
import com.fr.file.filter.ChooseFileFilter; import com.fr.file.filter.ChooseFileFilter;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import com.fr.io.repository.base.fs.FileSystemRepository;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.workspace.WorkContext;
import javax.swing.*; import javax.annotation.Nullable;
import java.awt.*; import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.filechooser.FileSystemView;
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.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.text.ParseException; import java.text.ParseException;
import java.util.List; import java.util.List;
import java.util.Objects;
public class FeedbackToolboxDialog extends JDialog { public class FeedbackToolboxDialog extends JDialog {
@ -44,6 +62,7 @@ public class FeedbackToolboxDialog extends JDialog {
private final Color lineColor = new Color(192, 192, 192, 120); private final Color lineColor = new Color(192, 192, 192, 120);
private JPanel body = null; private JPanel body = null;
private static final String WORK_SPACE_PATH = "reportlets"; private static final String WORK_SPACE_PATH = "reportlets";
private static final int BUFFER_SIZE = 2 * 1024;
public FeedbackToolboxDialog(Frame owner) { public FeedbackToolboxDialog(Frame owner) {
super(owner, Toolkit.i18nText("Fine-Design_Basic_Carton_Feedback_ToolBox")); super(owner, Toolkit.i18nText("Fine-Design_Basic_Carton_Feedback_ToolBox"));
@ -93,7 +112,7 @@ public class FeedbackToolboxDialog extends JDialog {
exportLogLabel.setForeground(UIConstants.FLESH_BLUE); exportLogLabel.setForeground(UIConstants.FLESH_BLUE);
exportLogLabel.addMouseListener(new MouseAdapter() { exportLogLabel.addMouseListener(new MouseAdapter() {
@Override @Override
public void mousePressed(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (exportLogLabel.isEnabled()) { if (exportLogLabel.isEnabled()) {
exportLogFile(); exportLogFile();
} }
@ -120,6 +139,9 @@ public class FeedbackToolboxDialog extends JDialog {
fileChooserPane.setFileNameTextField(fileName.toString(), " "); fileChooserPane.setFileNameTextField(fileName.toString(), " ");
fileChooserPane.removeAllFilter(); fileChooserPane.removeAllFilter();
fileChooserPane.addChooseFILEFilter(new ChooseFileFilter("zip", Toolkit.i18nText("Fine-Design_Basic_Carton_Compile_File"))); fileChooserPane.addChooseFILEFilter(new ChooseFileFilter("zip", Toolkit.i18nText("Fine-Design_Basic_Carton_Compile_File")));
//默认选择桌面
FILE desktop = FILEFactory.createFILE(FILEFactory.FILE_PREFIX + FileSystemView.getFileSystemView().getHomeDirectory().getPath());
fileChooserPane.setCurrentDirectory(desktop);
int chooseResult = fileChooserPane.showSaveDialog(DesignerContext.getDesignerFrame()); int chooseResult = fileChooserPane.showSaveDialog(DesignerContext.getDesignerFrame());
if (chooseResult == 0) { if (chooseResult == 0) {
FILE selectedFile = fileChooserPane.getSelectedFILE(); FILE selectedFile = fileChooserPane.getSelectedFILE();
@ -127,24 +149,10 @@ public class FeedbackToolboxDialog extends JDialog {
//selectDate 2002-03-09例子 //selectDate 2002-03-09例子
String[] split = selectDate.split("-"); String[] split = selectDate.split("-");
int month = Integer.parseInt(split[1]); 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()) { if (sourceFile.exists()) {
File[] files = sourceFile.listFiles(); exportCartonLog(sourceFile, path, sourceFilePath);
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);
}
}
} }
fileChooserPane.removeAllFilter(); fileChooserPane.removeAllFilter();
} }
@ -333,4 +341,68 @@ public class FeedbackToolboxDialog extends JDialog {
uploadButton.setEnabled(flag); uploadButton.setEnabled(flag);
exportLogLabel.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 (!Objects.isNull(files)) {
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(this, Toolkit.i18nText("Fine-Design_Report_Exported_Successfully"));
} catch (Exception exception) {
FineJOptionPane.showMessageDialog(this, 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[]
*/
@Nullable
private 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