|
|
|
@ -279,7 +279,9 @@ public class Project4WordServiceImpl extends ServiceImpl<ProjectMapper, Project> |
|
|
|
|
log.info("---------------------the basePath:{}", basePath); |
|
|
|
|
String modelFilePath = basePath + "baseInfoModel.docx"; |
|
|
|
|
log.info("---------------------the baseInfoModel path:{}", modelFilePath); |
|
|
|
|
String mergeWordFileName = dto.getProjectName() + ".docx"; |
|
|
|
|
String nameExt = "(" + dto.getId() + ")"; |
|
|
|
|
//加上id用于区分,申报人上传以项目名称为文件名,出现重复文件问题
|
|
|
|
|
String mergeWordFileName = dto.getProjectName() + nameExt + ".docx"; |
|
|
|
|
File outDir = new File(basePath + "pdf"); |
|
|
|
|
if (!outDir.exists()) { |
|
|
|
|
outDir.mkdirs(); |
|
|
|
@ -297,10 +299,9 @@ public class Project4WordServiceImpl extends ServiceImpl<ProjectMapper, Project> |
|
|
|
|
.eq(ProjectFile::getFileType, "docx") |
|
|
|
|
.orderByDesc(ProjectFile::getCreateTime)); |
|
|
|
|
if (ObjectUtil.isNotEmpty(projectFile)) { |
|
|
|
|
//windwos 下直接写回写路径
|
|
|
|
|
//windwos 下直接写回路径
|
|
|
|
|
FileInputStream fis = new FileInputStream("F:\\opt\\upFiles\\temp\\" + projectFile.getFileName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//linux 环境下
|
|
|
|
|
// FileInputStream fis = new FileInputStream(basePath + projectFile.getFileName());
|
|
|
|
|
wordList.add(new XWPFDocument(fis)); |
|
|
|
@ -313,17 +314,19 @@ public class Project4WordServiceImpl extends ServiceImpl<ProjectMapper, Project> |
|
|
|
|
FileInputStream fis2 = new FileInputStream(basePath + "yiJianModel.docx"); |
|
|
|
|
wordList.add(new XWPFDocument(fis2)); |
|
|
|
|
// 2.把集合里面的word文档全部合并在一个文档
|
|
|
|
|
XWPFDocument mergeWordObj = WordUtils.mergeWord(wordList); |
|
|
|
|
FileOutputStream fos = new FileOutputStream(new File(outDir, mergeWordFileName)); |
|
|
|
|
//已合并过的文件,删除
|
|
|
|
|
File oldMergeWord = new File(outDir + File.separator + dto.getProjectName() + ".docx"); |
|
|
|
|
File oldPdf = new File(outDir + File.separator + dto.getProjectName() + ".pdf"); |
|
|
|
|
//删除原文件
|
|
|
|
|
File oldMergeWord = new File(outDir + File.separator + mergeWordFileName); |
|
|
|
|
if (oldMergeWord != null && oldMergeWord.isFile() && oldMergeWord.exists()) { |
|
|
|
|
oldMergeWord.delete(); |
|
|
|
|
} |
|
|
|
|
File oldPdf = new File(outDir + File.separator + dto.getProjectName()+ nameExt + ".pdf"); |
|
|
|
|
if (oldPdf != null && oldPdf.isFile() && oldPdf.exists()) { |
|
|
|
|
oldPdf.delete(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//生成word文件
|
|
|
|
|
XWPFDocument mergeWordObj = WordUtils.mergeWord(wordList); |
|
|
|
|
FileOutputStream fos = new FileOutputStream(new File(outDir, mergeWordFileName)); |
|
|
|
|
mergeWordObj.write(fos); |
|
|
|
|
fos.close(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
@ -331,7 +334,7 @@ public class Project4WordServiceImpl extends ServiceImpl<ProjectMapper, Project> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
String pdfName = dto.getProjectName() + ".pdf"; |
|
|
|
|
String pdfName = dto.getProjectName()+ nameExt + ".pdf"; |
|
|
|
|
createPdf(outDir + File.separator + mergeWordFileName, outDir, pdfName); |
|
|
|
|
} catch (Exception e2) { |
|
|
|
|
e2.printStackTrace(); |
|
|
|
|