Skip to content

Commit

Permalink
增加导出查询数据功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubby2001 committed Dec 15, 2023
1 parent 2c1c01e commit 299d6f7
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 154 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

11 changes: 8 additions & 3 deletions .idea/artifacts/QuakeViewer_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/QuakeViewer.iml → QuakeViewer.iml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/com.rubby.quakeviewer/view" type="java-resource" />
</content>
Expand Down
Binary file removed README.assets/image-20231214162529831.png
Binary file not shown.
Binary file removed README.assets/image-20231214162544959.png
Binary file not shown.
Binary file added README.assets/image-20231216005847289.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ java -jar QuakeViewer.jar

![image-20231214162439986](README.assets/image-20231214162439986.png)

可以右键复制URL、ip等内容:
可以右键复制URL、ip等内容,可以导出选中的数据、全部查询数据

![image-20231214162544959](README.assets/image-20231214162544959.png)
![image-20231216005847289](README.assets/image-20231216005847289.png)

双击可以实现跳转:

Expand Down
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
<artifactId>controlsfx</artifactId>
<version>8.40.18</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.78</version>
</dependency>
</dependencies>

</project>
110 changes: 108 additions & 2 deletions src/com.rubby.quakeviewer/controller/QuakeViewerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import com.rubby.quakeviewer.util.CreateConfigFile;
import com.rubby.quakeviewer.util.JsonRequest;
import com.rubby.quakeviewer.util.ReadFile;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.concurrent.Task;
Expand All @@ -28,9 +32,9 @@
import org.controlsfx.control.textfield.TextFields;

import java.awt.*;
import java.io.File;

import com.opencsv.CSVWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URI;
import java.nio.file.Files;
Expand Down Expand Up @@ -231,6 +235,108 @@ public void onClikCopyCompany(ActionEvent actionEvent) {
clipboardContent.putString(content);
Clipboard.getSystemClipboard().setContent(clipboardContent);
}

@FXML
public void onExportDatas(ActionEvent actionEvent) throws IOException {
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
String fileName = "导出数据_" + timestamp + ".csv";

List<assets> slectedAssets = table.getSelectionModel().getSelectedItems();

FileOutputStream os = new FileOutputStream(fileName);
os.write(0xef); //加上这句话
os.write(0xbb); //加上这句话
os.write(0xbf); //加上这句话
try (CSVWriter writer = new CSVWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8))) {
// 写入CSV文件头
String[] header = {"序号", "Url", "Ip","Port","Domain","Service","Title","Cms","Icp","Company"};
writer.writeNext(header);

// 遍历资产列表,写入每一行数据
for (assets asset : slectedAssets) {
String[] row = {
String.valueOf(asset.getCount()),
asset.getUrl(),
asset.getIp(),
asset.getPort(),
asset.getDomain(),
asset.getService(),
asset.getTitle(),
asset.getCms(),
asset.getIcp(),
asset.getCompany()
};
writer.writeNext(row);
}
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("导出成功");
alert.setHeaderText(null);
alert.setContentText("CSV文件导出成功,文件名: " + fileName);

// 显示弹窗
alert.showAndWait();
} catch (IOException e) {
e.printStackTrace();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("导出失败");
alert.setHeaderText(null);
alert.setContentText("CSV文件导出失败:" + e.getMessage());

// 显示弹窗
alert.showAndWait();
}
}


@FXML
public void onExportAllDatas(ActionEvent actionEvent) throws IOException {
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
String fileName = "导出数据_" + timestamp + ".csv";

List<assets> slectedAssets = table.getItems();
FileOutputStream os = new FileOutputStream(fileName);
os.write(0xef); //加上这句话
os.write(0xbb); //加上这句话
os.write(0xbf); //加上这句话
try (CSVWriter writer = new CSVWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8))) {
// 写入CSV文件头
String[] header = {"序号", "Url", "Ip","Port","Domain","Service","Title","Cms","Icp","Company"};
writer.writeNext(header);

// 遍历资产列表,写入每一行数据
for (assets asset : slectedAssets) {
String[] row = {
String.valueOf(asset.getCount()),
asset.getUrl(),
asset.getIp(),
asset.getPort(),
asset.getDomain(),
asset.getService(),
asset.getTitle(),
asset.getCms(),
asset.getIcp(),
asset.getCompany()
};
writer.writeNext(row);
}
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("导出成功");
alert.setHeaderText(null);
alert.setContentText("CSV文件导出成功,文件名: " + fileName);

// 显示弹窗
alert.showAndWait();
} catch (IOException e) {
e.printStackTrace();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("导出失败");
alert.setHeaderText(null);
alert.setContentText("CSV文件导出失败:" + e.getMessage());

// 显示弹窗
alert.showAndWait();
}
}
// @FXML
// public void jumpToURL(MouseEvent mouseEvent) {
// assets seletedAssets = table.getSelectionModel().getSelectedItem();
Expand Down
Loading

0 comments on commit 299d6f7

Please sign in to comment.