模板文件 11.26

master
zhc077 15 hours ago
parent bec7c7db10
commit fe40ae8f15
  1. 1
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  2. 21
      jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/project/service/impl/Project4WordServiceImpl.java

@ -192,7 +192,6 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/sys/sysDepart/queryDepartTreeSync4FaRen", "anon");//法人注册时,选择部门列表 filterChainDefinitionMap.put("/sys/sysDepart/queryDepartTreeSync4FaRen", "anon");//法人注册时,选择部门列表
filterChainDefinitionMap.put("/sys/sysDepart/getDepartList4Quxian", "anon");//法人注册时,获取区县级别部门列表 filterChainDefinitionMap.put("/sys/sysDepart/getDepartList4Quxian", "anon");//法人注册时,获取区县级别部门列表
filterChainDefinitionMap.put("/project/project/createXiangmushuWord", "anon");//测试word生成

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

Loading…
Cancel
Save