| | |
| | | import com.java110.utils.util.ExceptionUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xwpf.usermodel.XWPFDocument; |
| | | import org.slf4j.Logger; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | |
| | |
| | | |
| | | ByteArrayInputStream inputStream = null; |
| | | ByteArrayOutputStream os = null; |
| | | SXSSFWorkbook workbook = null; |
| | | Object document = null; |
| | | String fileName = ""; |
| | | |
| | | if (exportDataDto == null) { |
| | |
| | | return; |
| | | } |
| | | updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_DOING,"", "开始下载"); |
| | | |
| | | try { |
| | | workbook = exportDataAdaptImpl.exportData(exportDataDto); |
| | | document = exportDataAdaptImpl.exportData(exportDataDto); |
| | | //保存文件路径到 文件下载表 |
| | | // os = new ByteArrayOutputStream(); |
| | | // workbook.write(os); |
| | | // inputStream = new ByteArrayInputStream(os.toByteArray()); |
| | | // |
| | | // fileName = fileUploadTemplate.saveFile(inputStream, exportDataDto.getFileName()); |
| | | // |
| | | // |
| | | // updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FINISH,fileName, "下载完成"); |
| | | // 根据文档类型,写入流 |
| | | os = new ByteArrayOutputStream(); |
| | | workbook.write(os); |
| | | if (document instanceof SXSSFWorkbook) { |
| | | ((SXSSFWorkbook) document).write(os); |
| | | } else if (document instanceof XWPFDocument) { |
| | | ((XWPFDocument) document).write(os); |
| | | } |
| | | inputStream = new ByteArrayInputStream(os.toByteArray()); |
| | | fileName = fileUploadTemplate.saveFile(inputStream, exportDataDto.getFileName() + "." + exportDataAdaptImpl.getFileType()); |
| | | |
| | | fileName = fileUploadTemplate.saveFile(inputStream, exportDataDto.getFileName()); |
| | | |
| | | |
| | | updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FINISH,fileName, "下载完成"); |
| | | |
| | | updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FINISH, fileName, "下载完成"); |
| | | } catch (Throwable e) { |
| | | e.printStackTrace(); |
| | | updateUserDownloadFile(exportDataDto, UserDownloadFileDto.STATE_FAIL, "","下载失败" + ExceptionUtil.getStackTrace(e)); |
| | | } finally { |
| | | try { |
| | | workbook.close(); |
| | | } catch (Exception e) { |
| | | |
| | | // 关闭文档对象(针对不同类型的文档进行资源释放) |
| | | if (document != null) { |
| | | try { |
| | | if (document instanceof SXSSFWorkbook) { |
| | | ((SXSSFWorkbook) document).close(); |
| | | } else if (document instanceof XWPFDocument) { |
| | | ((XWPFDocument) document).close(); |
| | | } else if (document instanceof ByteArrayInputStream) { |
| | | ((ByteArrayInputStream) document).close(); |
| | | } |
| | | } catch (IOException e) { |
| | | log.error("关闭文档对象失败", e); |
| | | } |
| | | } |
| | | try { |
| | | inputStream.close(); |
| | |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |