From a0a4e4027514ca678b6b7ec4dde3530e30b5ae25 Mon Sep 17 00:00:00 2001 From: shicf <shi_chongfu@163.com> Date: 星期三, 12 六月 2024 10:37:48 +0800 Subject: [PATCH] 附件下载 --- src/main/java/com/product/file/util/AsposeTest.java | 41 ++++++++++++++++++++ src/main/java/com/product/file/util/FileUtil.java | 4 -- src/main/java/com/product/file/controller/FileManagerController.java | 34 ++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/product/file/controller/FileManagerController.java b/src/main/java/com/product/file/controller/FileManagerController.java index 660c754..72f55fe 100644 --- a/src/main/java/com/product/file/controller/FileManagerController.java +++ b/src/main/java/com/product/file/controller/FileManagerController.java @@ -1,12 +1,14 @@ package com.product.file.controller; import com.alibaba.fastjson.JSONObject; +import com.product.common.lang.StringUtils; import com.product.core.config.CoreConst; import com.product.core.controller.support.AbstractBaseController; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.core.spring.context.SpringMVCContextHolder; +import com.product.file.config.CmnConst; import com.product.file.config.FileCode; import com.product.file.service.FileManagerService; import com.product.module.sys.version.ApiVersion; @@ -272,7 +274,37 @@ return error(FileCode.UPLOAD_FILE_FAIL.getValue(), FileCode.UPLOAD_FILE_FAIL.getText()); } } - + /** + * 涓嬭浇鏂囦欢鎴栬�呭湪绾块瑙� + * + * @return 缁撴灉 + */ + @RequestMapping(value = "/get-file-content/{version}", method = RequestMethod.GET) + @ApiVersion(1) + public String getFileContents(HttpServletRequest request, HttpServletResponse response) { + try { + FieldSetEntity fse = null; + String uuid = request.getParameter(CoreConst.UUID); + String onlineView = request.getParameter(CmnConst.NEED_ONLINE_VIEW); + + if (StringUtils.isEmpty(uuid)) { + SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); + return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); + } + fse=new FieldSetEntity(); + fse.setTableName(CmnConst.PRODUCT_SYS_ATTACHMENTS); + fse.setValue(CoreConst.UUID, uuid); + fse.setValue(CmnConst.NEED_ONLINE_VIEW, onlineView); + SpringMVCContextHolder.getSystemLogger().info("閫氳繃GET璇锋眰鑾峰彇闄勪欢鍐呭"); + // 姝e紡浠g爜 + fileManagerService.getFileContent(fse, response); + return OK(); + } catch (Exception e) { + SpringMVCContextHolder.getSystemLogger().error(e); + e.printStackTrace(); + return error(FileCode.GET_FILE_CONTENT_FAIL.getValue(), FileCode.GET_FILE_CONTENT_FAIL.getText()); + } + } /** * 涓嬭浇鏂囦欢鎴栬�呭湪绾块瑙� * diff --git a/src/main/java/com/product/file/util/AsposeTest.java b/src/main/java/com/product/file/util/AsposeTest.java new file mode 100644 index 0000000..20b6aeb --- /dev/null +++ b/src/main/java/com/product/file/util/AsposeTest.java @@ -0,0 +1,41 @@ +package com.product.file.util; + +import com.aspose.words.*; + +import java.io.File; + +public class AsposeTest { + public static void main(String args[]){ + try { + test1(); + }catch (Exception e){ + e.printStackTrace(); + } + } + public static void test1() throws Exception { + File f=new File("e:/qq/xxx.docx"); + if(!f.exists()){ + f.getParentFile().mkdirs(); + f.createNewFile(); + } + Document doc=new Document("e:/qq/xxx.docx"); + DocumentBuilder builder =new DocumentBuilder(doc); + //绉诲姩鑷虫枃妗g粨灏� + builder.moveToDocumentEnd(); +// //鏂板缓鍒嗛〉绗� +// Run pageBreakRun = new Run(doc, ControlChar.PAGE_BREAK); +// //鎻掑叆鍒嗛〉绗� +// builder.insertNode(pageBreakRun); + //璁剧疆瀛椾綋 + + builder.getFont().setName("Arial"); + + builder.getFont().setBold(true); + + builder.getFont().setSize(10); + + builder.write("sssssss"); + + doc.save("e:/qq/xxx.docx", SaveFormat.DOCX); + } +} diff --git a/src/main/java/com/product/file/util/FileUtil.java b/src/main/java/com/product/file/util/FileUtil.java index 4e3e573..a7cdaa2 100644 --- a/src/main/java/com/product/file/util/FileUtil.java +++ b/src/main/java/com/product/file/util/FileUtil.java @@ -119,7 +119,6 @@ * @return zip鏂囦欢淇濆瓨缁濆璺緞 */ public static long createZip(List<Map<String, String>> pathList, OutputStream os) { - log.info("姝e湪鎵撳寘鏂囦欢..."); try { long size = 0; ZipOutputStream out = new ZipOutputStream(os); @@ -144,7 +143,6 @@ fileName = head + "(" + showCount + ")." + tail; } fileNameCountMap.put(fileName, ++showCount); - log.info(String.format("姝e湪鎵撳寘鏂囦欢 %s", fileName)); //浠ヨ鏂囨爣棰樹负姣忎釜鏂囦欢鍛藉悕 FileInputStream fis = new FileInputStream(downloadPath); @@ -156,11 +154,9 @@ while ((len = fis.read(buffer)) > 0) { if (symbol == 1) { // 鍔犲瘑 - log.info("姝e湪鍔犲瘑..."); out.write(encryption(buffer), 0, len); } else if (symbol == -1) { // 瑙e瘑 - log.info("姝e湪瑙e瘑..."); out.write(decryption(buffer), 0, len); } else { // 鍗曠函鐨勫鍒� -- Gitblit v1.9.2