Commit a2a8e48a authored by wangqiang's avatar wangqiang

卷内目录生成pdf文件后,将临时目录及文件删除

parent 88baa04d
......@@ -19,7 +19,7 @@ import com.inet.dcs.document.core.util.SearchUtil;
import com.inet.dcs.document.core.util.WordUtils;
import com.inet.dcs.document.entity.po.ExtFiles;
import com.yonde.dcs.document.common.entity.vo.DxDocumentVO;
import com.yonde.dcs.plan.common.utils.ResourceHelper;
import com.inet.dcs.document.core.util.ResourceHelper;
import com.yonde.dex.basedata.data.search.SearchItem;
import com.yonde.dex.basedata.data.search.SearchItems;
import com.yonde.dex.basedata.data.search.SearchQueryBuilder;
......@@ -340,19 +340,29 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
return pdfFile2.getAbsolutePath();
}
public String fillWordAndConvertPdf(String modelName, Map<String, Object> dataMap, String pdfFileName) {
public String fillWordAndConvertPdf(String modelName, Map<String, Object> dataMap, String pdfFileName,String tempDir) {
String targetPath = System.getProperty("user.dir") + "/TEMP/";
File wordFile = new File(targetPath + modelName);
File pdfFile2 = new File("TEMP/JNDir/" + pdfFileName + ".pdf");
File pdfFile2 = new File(tempDir + File.separator+pdfFileName + ".pdf");
InputStream tempStream = null;
OutputStream outputStream = null;
ByteArrayInputStream byteArrayInputStream = null;
try {
InputStream tempStream2 = Files.newInputStream(wordFile.toPath());
OutputStream outputStream = Files.newOutputStream(pdfFile2.toPath());
byte[] bytes2 = WordUtils.fillWord(dataMap, tempStream2);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes2);
tempStream = Files.newInputStream(wordFile.toPath());
outputStream = Files.newOutputStream(pdfFile2.toPath());
byte[] bytes2 = WordUtils.fillWord(dataMap, tempStream);
byteArrayInputStream = new ByteArrayInputStream(bytes2);
WordUtils.wordToPDF(byteArrayInputStream, outputStream);
byteArrayInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
byteArrayInputStream.close();
tempStream.close();
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return pdfFile2.getAbsolutePath();
}
......@@ -382,24 +392,33 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
//查询项目群下所有案卷
SearchQueryCondition searchProgram = SearchUtil.buildQuery("dxContextId", SearchItem.Operator.EQ, id);
List<V> content = this.findRecursion(searchProgram).getContent();
//临时文件目录
String tempDir = ResourceHelper.createTemDir().getPath();
List<Long> extFilesIdList = content.stream().map(v -> v.getId()).collect(Collectors.toList());
//查询案卷下文件清单
for (Long filesId : extFilesIdList) {
SearchQueryCondition searchQueryCondition = SearchQueryBuilder.openBuild().openFilterBuilder()
.setItem("targetId", SearchItem.Operator.EQ, filesId).closeFilterBuilder()
.setPropName("target").setPropName("source").build();
List<ExtFilesDocLinkVO> extFilesDocLinkVOList = extFilesDocLinkService.findRecursion(searchQueryCondition).getContent();
if (CollectionUtils.isNotEmpty(extFilesDocLinkVOList)) {
ExtFilesVO extFilesVO = extFilesDocLinkVOList.get(0).getTarget();
//查询案卷的附件信息及link中的doc
SearchQueryCondition query = SearchQueryCondition.builder()
.openProp(SearchQueryCondition.builder().name("objFileLinks").build())
.openProp(SearchQueryCondition.builder().name("extFilesDocLinks")
.openProp(SearchQueryCondition.builder().name("source").build()).build())
.searchItems(SearchItems.builder()
.item(new SearchItem("id", SearchItem.Operator.EQ, filesId, null))
.build()).build();
ExtFilesVO extFilesVO = this.findRecursion(query).getContent().get(0);
//link(source=doc)
List<ExtFilesDocLinkVO> extFilesDocLinkVOList = extFilesVO.getExtFilesDocLinks();
if (CollectionUtils.isNotEmpty(extFilesVO.getExtFilesDocLinks())) {
//1.获取案卷下所有的档案(doc模型)数据并填充到模板中
Map<String, Object> wordFillDataForJN = getJNDirectoryFillData(extFilesDocLinkVOList, extFilesVO);
String JNDirectoryPdfPath = fillWordAndConvertPdf("卷内目录模板.docx", wordFillDataForJN, getJNMLFileName(extFilesVO));
String JNDirectoryPdfPath = fillWordAndConvertPdf("卷内目录模板.docx", wordFillDataForJN, getJNMLFileName(extFilesVO),tempDir);
//2.获取备考表需要填充的数据并填充数据到模板中
Map<String, Object> wordFillDataForBK = getJNBKTableFillData(extFilesDocLinkVOList, extFilesVO);
String BKPdfPath = fillWordAndConvertPdf("卷内备考表模板.docx", wordFillDataForBK, getBKFileName(extFilesVO));
String BKPdfPath = fillWordAndConvertPdf("卷内备考表模板.docx", wordFillDataForBK, getBKFileName(extFilesVO),tempDir);
//3.上传卷内文档目录文件
MultipartFile multipartFileForJN = DxObjFileUtils.createFile(JNDirectoryPdfPath);
......@@ -423,7 +442,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
extFilesVO.setOperator(OperatorType.MODIFY);
this.saveRecursion((V) extFilesVO);
//删除目录下所有的文件
FileUtils.deleteFilesInDirectory(System.getProperty("user.dir") + "/TEMP/JNDir/");
FileUtils.deleteDirectory(tempDir);
}
}
......@@ -616,7 +635,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
throw new DxBusinessException("500","必须要选中一条案卷");
}
//临时文件目录
String tempDir = ResourceHelper.createTempDir().getPath();
String tempDir = ResourceHelper.createTemDir().getPath();
//文件id集合
List<Long> fileIds = new ArrayList<>();
......
......@@ -162,16 +162,14 @@ public class ResourceHelper {
public static String getBaseHomeDir() {
if (StringUtils.isEmpty(baseHomeDir)) {
ApplicationHome home = new ApplicationHome(PDFUtil.class);
baseHomeDir = home.getSource().getParentFile().getPath();
baseHomeDir = home.getSource().getParentFile().getParentFile().getPath();
}
return baseHomeDir;
}
public static File createTemDir() {
String uuid = UUID.randomUUID().toString().replace("-", "");
String temDir = getBaseHomeDir() + File.separator +
"tem" + File.separator +
uuid;
String temDir = getBaseHomeDir() + File.separator + "fileTempDir" + File.separator + uuid;
return FileUtil.mkdir(temDir);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment