shicf
2024-06-12 a0a4e4027514ca678b6b7ec4dde3530e30b5ae25
附件下载
已添加1个文件
已修改2个文件
77 ■■■■■ 文件已修改
src/main/java/com/product/file/controller/FileManagerController.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/util/AsposeTest.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/util/FileUtil.java 4 ●●●● 补丁 | 查看 | 原始文档 | 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 {
                        // å•纯的复制