class ExportDataService {
public void exportDataZip(HttpServletResponse response) {
List<ExportData> exportList = getExportData();
try (Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ExportData.class, exportList);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
// Workbook write to ByteArrayOutputStream
ZipEntry zipEntry = new ZipEntry("export.xlsx");
zos.putNextEntry(zipEntry);
zos.write(baos.toByteArray());
exportList.forEach(exportData -> {
List<ExportFile> exportFileList = getExportFile();
exportFileList.forEach(exportFile -> {
try (InputStream inputStream = download(exportData.getUrl())) {
byte[] bytes = IoUtil.readBytes(inputStream);
String folderPath = "file/" + exportData.getName() + "/";
String name = FileUtil.getName(exportFile.getUrl());
ZipEntry entry = new ZipEntry(folderPath + name);
log.error("export file error: {}", e.getMessage());
log.error("export zip error: {}", e.getMessage());
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=\"export.zip\"");
public InputStream download(String url) {
return minioClient.getObject(
log.error("download file error", e);
throw new BusinessException("文件下载异常");
public List<ExportData> getExportData() {
public List<ExportFile> getExportFile() {