src/main/java/com/product/file/controller/FileManagerController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/file/util/AsposeTest.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/file/util/FileUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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请æ±è·åéä»¶å 容"); // æ£å¼ä»£ç 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()); } } /** * ä¸è½½æä»¶æè å¨çº¿é¢è§ * 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); //ç§»å¨è³ææ¡£ç»å°¾ 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); } } 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("æ£å¨æå æä»¶..."); 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("æ£å¨æå æä»¶ %s", fileName)); //ä»¥è®ºææ é¢ä¸ºæ¯ä¸ªæä»¶å½å FileInputStream fis = new FileInputStream(downloadPath); @@ -156,11 +154,9 @@ while ((len = fis.read(buffer)) > 0) { if (symbol == 1) { // å å¯ log.info("æ£å¨å å¯..."); out.write(encryption(buffer), 0, len); } else if (symbol == -1) { // è§£å¯ log.info("æ£å¨è§£å¯..."); out.write(decryption(buffer), 0, len); } else { // å纯çå¤å¶