src/main/java/com/product/file/service/OnlineDocumentEditService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/file/util/FileUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/product/file/service/OnlineDocumentEditService.java
@@ -59,6 +59,20 @@ try { String document_template = ff.getString("document_template"); String document_template_tail = ff.getString("document_template_tail"); String fileUuid = ff.getString("file_uuid"); FieldSetEntity fieldSetEntity = getBaseDao().getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, fileUuid, false); //获取文件类型 String fileName = fieldSetEntity.getString(CmnConst.FILE_NAME); //判断是否为doc文件 String fileType = fileName.substring(fileName.lastIndexOf(".") + 1); if ("doc".equals(fileType)) { //将doc文件转换为docx文件 File f = file; file = com.product.file.util.FileUtil.toDocx(file); if (f != null) { f.delete(); } } List<File> fileList = new ArrayList<>(3); if (!StringUtils.isEmpty(document_template)) { fileList.add(fileManagerService.getFile(document_template)); @@ -72,12 +86,21 @@ File mergeFile = MergeDoc.mergeDoc(fileList, Global.getSystemConfig("upload.file.temp.path", "./attachment/temp") + File.separator + "nest_red_document_" + IdUtil.randomUUID() + "_" + ff.getString("file_uuid")); if (mergeFile != null && mergeFile.isFile()) { if("doc".equals(fileType)){ //将docx文件转换为doc文件 File f = mergeFile; mergeFile = com.product.file.util.FileUtil.toDoc(f); if (f != null) { f.delete(); } } HashMap<String, File> objectObjectHashMap = new HashMap<>(); objectObjectHashMap.put("mergeFile", mergeFile); uploadFile(ff.getString("file_uuid"), objectObjectHashMap); } else { throw new BaseException(FileCode.NEST_RED_DOCUMENT_FAIL); } fileList.forEach(FileUtil::del); } catch (BaseException e) { throw e; } catch (Exception e) { src/main/java/com/product/file/util/FileUtil.java
@@ -4,6 +4,7 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.poi.word.WordUtil; import com.aspose.words.Document; import com.aspose.words.SaveFormat; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.xwpf.NiceXWPFDocument; import com.google.common.collect.Maps; @@ -83,6 +84,9 @@ } public static File toDocx(File file) { if (!AsposeUtil.getLicense(2)) { return file; } String docxName = UUID.randomUUID().toString() + ".docx"; File docxFile = new File(file.getParent() + File.separator + docxName); String tempDir = Global.getSystemConfig("temp.dir", "./attachment/temp"); @@ -97,6 +101,24 @@ return docxFile; } public static File toDoc(File file) { if (!AsposeUtil.getLicense(2)) { return file; } String docxName = UUID.randomUUID().toString() + ".doc"; File docxFile = new File(file.getParent() + File.separator + docxName); String tempDir = Global.getSystemConfig("temp.dir", "./attachment/temp"); File tempFile = new File(tempDir + File.separator + docxName); try { Document document = new Document(new FileInputStream(file)); document.save(tempFile.getAbsolutePath(), SaveFormat.DOC); return tempFile; } catch (Exception e) { e.printStackTrace(); } return docxFile; } /** * 批量打包 *