mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-10-08 22:49:33 +08:00
feat: word zip
This commit is contained in:
parent
c6730ac04c
commit
f8c2ff785e
6 changed files with 49 additions and 10 deletions
2
@rbv
2
@rbv
|
@ -1 +1 @@
|
||||||
Subproject commit 44a1fed9ad96a93b55a4bd95f11904864d83b9fe
|
Subproject commit d9e6649023b80aeb93ef4668886c1a674dbfae0c
|
|
@ -238,6 +238,7 @@ public class DataReportManager implements ConfigManager {
|
||||||
else if (fileName.endsWith(".xlsx")) name += ".xlsx";
|
else if (fileName.endsWith(".xlsx")) name += ".xlsx";
|
||||||
else if (fileName.endsWith(".xls")) name += ".xls";
|
else if (fileName.endsWith(".xls")) name += ".xls";
|
||||||
else if (fileName.endsWith(".csv")) name += ".csv";
|
else if (fileName.endsWith(".csv")) name += ".csv";
|
||||||
|
else if (fileName.endsWith(".zip")) name += ".zip";
|
||||||
|
|
||||||
return StringUtils.defaultIfBlank(name, "UNTITLE");
|
return StringUtils.defaultIfBlank(name, "UNTITLE");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,4 +23,8 @@ public class ReportsException extends RebuildException {
|
||||||
public ReportsException(Throwable cause) {
|
public ReportsException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReportsException(String msg, Throwable cause) {
|
||||||
|
super(msg, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class DatabaseBackup {
|
||||||
|
|
||||||
File zip = new File(backups, destName + ".zip");
|
File zip = new File(backups, destName + ".zip");
|
||||||
try {
|
try {
|
||||||
CompressUtils.forceZip(dest, zip, null);
|
CompressUtils.forceZip(zip, dest, null);
|
||||||
|
|
||||||
FileUtils.deleteQuietly(dest);
|
FileUtils.deleteQuietly(dest);
|
||||||
dest = zip;
|
dest = zip;
|
||||||
|
|
|
@ -31,29 +31,29 @@ import java.nio.file.Files;
|
||||||
public class CompressUtils {
|
public class CompressUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param destZip
|
||||||
* @param fileOrDir
|
* @param fileOrDir
|
||||||
* @param destZip delete after create
|
|
||||||
* @param filter
|
* @param filter
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void forceZip(File fileOrDir, File destZip, FileFilter filter) throws IOException {
|
public static void forceZip(File destZip, File fileOrDir, FileFilter filter) throws IOException {
|
||||||
if (destZip.exists()) {
|
if (destZip.exists()) {
|
||||||
log.warn("delete exists after create : {}", destZip);
|
log.warn("delete exists after create : {}", destZip);
|
||||||
FileUtils.deleteQuietly(destZip);
|
FileUtils.deleteQuietly(destZip);
|
||||||
}
|
}
|
||||||
|
|
||||||
zip(fileOrDir, Files.newOutputStream(destZip.toPath()), filter);
|
zip(Files.newOutputStream(destZip.toPath()), fileOrDir, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a zip output stream at the specified path with the contents of the specified directory.
|
* Creates a zip output stream at the specified path with the contents of the specified directory.
|
||||||
*
|
*
|
||||||
* @param fileOrDir
|
|
||||||
* @param zipOutputStream
|
* @param zipOutputStream
|
||||||
|
* @param fileOrDir
|
||||||
* @param filter
|
* @param filter
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static void zip(File fileOrDir, OutputStream zipOutputStream, FileFilter filter) throws IOException {
|
public static void zip(OutputStream zipOutputStream, File fileOrDir, FileFilter filter) throws IOException {
|
||||||
BufferedOutputStream bufferedOutputStream = null;
|
BufferedOutputStream bufferedOutputStream = null;
|
||||||
ZipArchiveOutputStream zipArchiveOutputStream = null;
|
ZipArchiveOutputStream zipArchiveOutputStream = null;
|
||||||
|
|
||||||
|
@ -74,6 +74,41 @@ public class CompressUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param destZip
|
||||||
|
* @param files
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static void forceZip(File destZip, File... files) throws IOException {
|
||||||
|
if (destZip.exists()) {
|
||||||
|
log.warn("delete exists after create : {}", destZip);
|
||||||
|
FileUtils.deleteQuietly(destZip);
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputStream zipOutputStream = Files.newOutputStream(destZip.toPath());
|
||||||
|
BufferedOutputStream bufferedOutputStream = null;
|
||||||
|
ZipArchiveOutputStream zipArchiveOutputStream = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
bufferedOutputStream = new BufferedOutputStream(zipOutputStream);
|
||||||
|
zipArchiveOutputStream = new ZipArchiveOutputStream(bufferedOutputStream);
|
||||||
|
|
||||||
|
for (File file : files) {
|
||||||
|
addFileToZip(zipArchiveOutputStream, file, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (zipArchiveOutputStream != null) {
|
||||||
|
zipArchiveOutputStream.finish();
|
||||||
|
zipArchiveOutputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
IOUtils.closeQuietly(bufferedOutputStream);
|
||||||
|
IOUtils.closeQuietly(zipOutputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static void addFileToZip(ZipArchiveOutputStream zipArchiveOutputStream, File file, String path, FileFilter filter) throws IOException {
|
private static void addFileToZip(ZipArchiveOutputStream zipArchiveOutputStream, File file, String path, FileFilter filter) throws IOException {
|
||||||
// at first call it is the folder, otherwise is the relative path
|
// at first call it is the folder, otherwise is the relative path
|
||||||
String entryName = (path != null) ? path + file.getName() : file.getName();
|
String entryName = (path != null) ? path + file.getName() : file.getName();
|
||||||
|
|
|
@ -97,9 +97,8 @@ public class ReportsController extends BaseController {
|
||||||
try {
|
try {
|
||||||
EasyExcelGenerator reportGenerator;
|
EasyExcelGenerator reportGenerator;
|
||||||
if (tt.type == DataReportManager.TYPE_WORD) {
|
if (tt.type == DataReportManager.TYPE_WORD) {
|
||||||
// 暂不支持多个
|
|
||||||
reportGenerator = (EasyExcelGenerator33) CommonsUtils.invokeMethod(
|
reportGenerator = (EasyExcelGenerator33) CommonsUtils.invokeMethod(
|
||||||
"com.rebuild.rbv.data.WordReportGenerator#create", reportId, recordId);
|
"com.rebuild.rbv.data.WordReportGenerator#create", reportId, recordIds);
|
||||||
} else if (tt.type == DataReportManager.TYPE_HTML5) {
|
} else if (tt.type == DataReportManager.TYPE_HTML5) {
|
||||||
reportGenerator = (EasyExcelGenerator33) CommonsUtils.invokeMethod(
|
reportGenerator = (EasyExcelGenerator33) CommonsUtils.invokeMethod(
|
||||||
"com.rebuild.rbv.data.Html5ReportGenerator#create", reportId, recordIds);
|
"com.rebuild.rbv.data.Html5ReportGenerator#create", reportId, recordIds);
|
||||||
|
|
Loading…
Add table
Reference in a new issue