mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-09-24 07:36:19 +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(".xls")) name += ".xls";
|
||||
else if (fileName.endsWith(".csv")) name += ".csv";
|
||||
else if (fileName.endsWith(".zip")) name += ".zip";
|
||||
|
||||
return StringUtils.defaultIfBlank(name, "UNTITLE");
|
||||
}
|
||||
|
|
|
@ -23,4 +23,8 @@ public class ReportsException extends RebuildException {
|
|||
public ReportsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ReportsException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,8 @@ public class DatabaseBackup {
|
|||
|
||||
File zip = new File(backups, destName + ".zip");
|
||||
try {
|
||||
CompressUtils.forceZip(dest, zip, null);
|
||||
|
||||
CompressUtils.forceZip(zip, dest, null);
|
||||
|
||||
FileUtils.deleteQuietly(dest);
|
||||
dest = zip;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -31,29 +31,29 @@ import java.nio.file.Files;
|
|||
public class CompressUtils {
|
||||
|
||||
/**
|
||||
* @param destZip
|
||||
* @param fileOrDir
|
||||
* @param destZip delete after create
|
||||
* @param filter
|
||||
* @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()) {
|
||||
log.warn("delete exists after create : {}", 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.
|
||||
*
|
||||
* @param fileOrDir
|
||||
* @param zipOutputStream
|
||||
* @param fileOrDir
|
||||
* @param filter
|
||||
* @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;
|
||||
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 {
|
||||
// at first call it is the folder, otherwise is the relative path
|
||||
String entryName = (path != null) ? path + file.getName() : file.getName();
|
||||
|
|
|
@ -97,9 +97,8 @@ public class ReportsController extends BaseController {
|
|||
try {
|
||||
EasyExcelGenerator reportGenerator;
|
||||
if (tt.type == DataReportManager.TYPE_WORD) {
|
||||
// 暂不支持多个
|
||||
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) {
|
||||
reportGenerator = (EasyExcelGenerator33) CommonsUtils.invokeMethod(
|
||||
"com.rebuild.rbv.data.Html5ReportGenerator#create", reportId, recordIds);
|
||||
|
|
Loading…
Add table
Reference in a new issue