Commit 177f4914 authored by wangqiang's avatar wangqiang

生成卷内目录物理文档和备考表物理文件

parent 7581b47e
...@@ -3,12 +3,15 @@ package com.inet.dcs.document.core.service.impl; ...@@ -3,12 +3,15 @@ package com.inet.dcs.document.core.service.impl;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import com.inet.dcs.document.common.vo.ExtFilesDocLinkVO; import com.inet.dcs.document.common.vo.ExtFilesDocLinkVO;
import com.inet.dcs.document.common.vo.ExtFilesVO; import com.inet.dcs.document.common.vo.ExtFilesVO;
import com.inet.dcs.document.common.vo.ExtTransferDocLinkVO;
import com.inet.dcs.document.common.vo.archivesOtherVO.ExtFilesUpdateVO; import com.inet.dcs.document.common.vo.archivesOtherVO.ExtFilesUpdateVO;
import com.inet.dcs.document.core.constants.Constants; import com.inet.dcs.document.core.constants.Constants;
import com.inet.dcs.document.core.repository.ExtFilesRepository; import com.inet.dcs.document.core.repository.ExtFilesRepository;
import com.inet.dcs.document.core.service.ExtDocService; import com.inet.dcs.document.core.service.ExtDocService;
import com.inet.dcs.document.core.service.ExtFilesDocLinkService; import com.inet.dcs.document.core.service.ExtFilesDocLinkService;
import com.inet.dcs.document.core.service.ExtFilesService; import com.inet.dcs.document.core.service.ExtFilesService;
import com.inet.dcs.document.core.service.ExtTransferDocLinkService;
import com.inet.dcs.document.core.util.DateUtils;
import com.inet.dcs.document.core.util.SearchUtil; import com.inet.dcs.document.core.util.SearchUtil;
import com.inet.dcs.document.core.util.WordUtils; import com.inet.dcs.document.core.util.WordUtils;
import com.inet.dcs.document.entity.po.ExtFiles; import com.inet.dcs.document.entity.po.ExtFiles;
...@@ -38,6 +41,7 @@ import com.yonde.dex.user.feign.DxUserInfoFeign; ...@@ -38,6 +41,7 @@ import com.yonde.dex.user.feign.DxUserInfoFeign;
import com.yonde.dex.vo.info.DxApplicationVO; import com.yonde.dex.vo.info.DxApplicationVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -92,6 +96,8 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic ...@@ -92,6 +96,8 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
@Autowired @Autowired
private DxOrganizationFeign organizationService; private DxOrganizationFeign organizationService;
@Autowired
private ExtTransferDocLinkService extTransferDocLinkService;
@Override @Override
public void beforeSave(Collection<V> target) { public void beforeSave(Collection<V> target) {
...@@ -320,6 +326,23 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic ...@@ -320,6 +326,23 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
return pdfFile2.getAbsolutePath(); return pdfFile2.getAbsolutePath();
} }
public String fillWordAndConvertPdf(String modelName, Map<String, Object> dataMap,String pdfFileName) {
String targetPath = System.getProperty("user.dir") + "/TEMP/";
File wordFile = new File(targetPath + modelName);
File pdfFile2 = new File("TEMP/" + pdfFileName + "_" + UUID.randomUUID() + ".pdf");
try {
InputStream tempStream2 = Files.newInputStream(wordFile.toPath());
OutputStream outputStream = Files.newOutputStream(pdfFile2.toPath());
byte[] bytes2 = WordUtils.fillWord(dataMap, tempStream2);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes2);
WordUtils.wordToPDF(byteArrayInputStream, outputStream);
byteArrayInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return pdfFile2.getAbsolutePath();
}
//递归根据项目群查询项目子项 //递归根据项目群查询项目子项
...@@ -340,7 +363,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic ...@@ -340,7 +363,7 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
*/ */
@Override @Override
public void generateJNDirectory(Long id) { public void generateJNDirectory(Long id) {
MultipartFile[] multipartFiles = new MultipartFile[2];
//查询项目群下所有案卷 //查询项目群下所有案卷
SearchQueryCondition searchProgram = SearchUtil.buildQuery("dxContextId", SearchItem.Operator.EQ, id); SearchQueryCondition searchProgram = SearchUtil.buildQuery("dxContextId", SearchItem.Operator.EQ, id);
List<V> content = this.findRecursion(searchProgram).getContent(); List<V> content = this.findRecursion(searchProgram).getContent();
...@@ -353,24 +376,113 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic ...@@ -353,24 +376,113 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
.setPropName("target").setPropName("source").build(); .setPropName("target").setPropName("source").build();
List<ExtFilesDocLinkVO> extFilesDocLinkVOList = extFilesDocLinkService.findRecursion(searchQueryCondition).getContent(); List<ExtFilesDocLinkVO> extFilesDocLinkVOList = extFilesDocLinkService.findRecursion(searchQueryCondition).getContent();
ExtFilesVO extFilesVO = extFilesDocLinkVOList.get(0).getTarget(); ExtFilesVO extFilesVO = extFilesDocLinkVOList.get(0).getTarget();
//获取案卷下所有的档案数据 -- 填充模板数据 //1.获取案卷下所有的档案(doc模型)数据并填充到模板中
Map<String,Object> wordFillData = getJNDirectoryFillData(extFilesDocLinkVOList,extFilesVO); Map<String,Object> wordFillDataForJN = getJNDirectoryFillData(extFilesDocLinkVOList,extFilesVO);
//文档转pdf //填充卷内文档目录数据并转pdf
String string = convertPdf("卷内目录模板.docx", wordFillData); String JNDirectoryPdfPath = fillWordAndConvertPdf("卷内目录模板.docx", wordFillDataForJN,getJNMLFileName(extFilesVO));
//上传文件
MultipartFile multipartFile = DxObjFileUtils.createFile(string); //2.获取备考表需要填充的数据并填充数据到模板中
Map<String,Object> wordFillDataForBK = getJNBKTableFillData(extFilesDocLinkVOList,extFilesVO);
String BKPdfPath = fillWordAndConvertPdf("卷内备考表模板.docx", wordFillDataForBK,getBKFileName(extFilesVO));
//3.上传卷内文档目录文件
MultipartFile multipartFileForJN = DxObjFileUtils.createFile(JNDirectoryPdfPath);
multipartFiles[0]=multipartFileForJN;
//4.上传备考文件
MultipartFile multipartFileForBK = DxObjFileUtils.createFile(BKPdfPath);
multipartFiles[1]=multipartFileForBK;
DxApplicationVO modelApp = dxAppModelDefLinkFeignService.findAppByModelName("ExtFiles"); DxApplicationVO modelApp = dxAppModelDefLinkFeignService.findAppByModelName("ExtFiles");
Assert.notNull(modelApp.getBucketId(), String.format("当前应用%s未绑定桶!", modelApp.getName())); Assert.notNull(modelApp.getBucketId(), String.format("当前应用%s未绑定桶!", modelApp.getName()));
RepoFileVO fileVo = fileManagerFeignService.uploadFile(multipartFile, Long.parseLong(modelApp.getBucketId())); List<RepoFileVO> fileVos = fileManagerFeignService.uploadFiles(multipartFiles, Long.parseLong(modelApp.getBucketId()));
for(RepoFileVO repoFileVO:fileVos){
//将生成的文件挂载到案卷上 if(repoFileVO.getRepoFileName().contains("卷内目录")){ //卷内
DxObjFileUtils.replaceFile(extFilesVO, fileVo, FileTypeEnum.MASTER_FILE); //5.将生成的卷内目录pdf文件挂载到案卷上
DxObjFileUtils.replaceFile(extFilesVO, repoFileVO, FileTypeEnum.MASTER_FILE);
}else { //备考
//6.将生成的备考表pdf文件挂载到案卷上
DxObjFileUtils.replaceFile(extFilesVO, repoFileVO, FileTypeEnum.ATTACH_FILE);
}
}
extFilesVO.setOperator(OperatorType.MODIFY); extFilesVO.setOperator(OperatorType.MODIFY);
this.saveRecursion((V) extFilesVO); this.saveRecursion((V) extFilesVO);
} }
} }
/**
* 获取卷内备考表填充的数据
* @param extFilesDocLinkVOList
* @param extFilesVO
* @return
*/
public Map<String,Object> getJNBKTableFillData(List<ExtFilesDocLinkVO> extFilesDocLinkVOList,ExtFilesVO extFilesVO){
Map<String, Object> resultDatas = new HashMap<>();
//档号
resultDatas.put("DH",extFilesVO.getVolumeNumber());
//互见号
resultDatas.put("HJH",extFilesVO.getMutualNumber()==null?"":extFilesVO.getMutualNumber());
//文件共几件 =案卷下所有文档的个数
resultDatas.put("fileNumber",extFilesDocLinkVOList == null?0:extFilesDocLinkVOList.size());
//文件共几页 =案卷下所有文档中的附件个数相加
Integer totalPage = getJNBKTableTotalPage(extFilesDocLinkVOList);
resultDatas.put("filePage",getJNBKTableTotalPage(extFilesDocLinkVOList));
//文字材料页 = 文件类型除图册、图纸之外的文件的总页数(见业务需求书)
Integer totalTextPage = getJNBKTableTotalTextPage(extFilesDocLinkVOList);
resultDatas.put("textPage",getJNBKTableTotalTextPage(extFilesDocLinkVOList));
//图纸几张 = 文件总页数 - 文字材料页)
resultDatas.put("imagePiece",totalPage - totalTextPage);
//立卷人 = 创建人
DxUserInfoVO userVO = (DxUserInfoVO) userService.get(extFilesVO.getCreatorId());
resultDatas.put("filer",userVO.getName());
//立卷时间 = 创建时间
resultDatas.put("filerYear",extFilesVO.getCreateTime().getYear());
resultDatas.put("filerMonth",extFilesVO.getCreateTime().getMonthValue());
resultDatas.put("filerDay",extFilesVO.getCreateTime().getDayOfMonth());
//检查人 =暂时不取(见业务需求书)
//检查时间=暂时不取(见业务需求书)
return resultDatas;
}
/**
* 计算文件类型除图册、图纸之外的文件的总页数(见业务需求书)
* @param extFilesDocLinkVOList
* @return
*/
public Integer getJNBKTableTotalTextPage(List<ExtFilesDocLinkVO> extFilesDocLinkVOList){
//DesignAtlas(设计图册)、InstallAtlas(安装图册)、DesignDrawings(设计图纸) 排除这三种类型的
// 定义一个数组
String[] array = {"DesignAtlas","InstallAtlas","DesignDrawings"};
List<String> subTypeNameList = Arrays.asList(array) ;
//获取所有文档对象集合
List<DxDocumentVO> documentVOList = extFilesDocLinkVOList.stream().map(linkVO -> linkVO.getSource()).collect(Collectors.toList());
//除DesignAtlas(设计图册)、InstallAtlas(安装图册)、DesignDrawings(设计图纸) 的文档对象
List<DxDocumentVO> docList = new ArrayList<>();
for (DxDocumentVO documentVO:documentVOList){
if(!subTypeNameList.contains(documentVO.getSubSystem())){
docList.add(documentVO);
}
}
return docList.stream().mapToInt(doc ->doc.getAttachPages() == null?0:Integer.parseInt(doc.getAttachPages())).sum();
}
/**
* 计算案卷中挂载的文档中附件个数总和
* @param extFilesDocLinkVOList
* @return
*/
public Integer getJNBKTableTotalPage(List<ExtFilesDocLinkVO> extFilesDocLinkVOList){
List<DxDocumentVO> documentVoList = extFilesDocLinkVOList.stream().map(linkVO -> linkVO.getSource()).collect(Collectors.toList());
return documentVoList.stream().mapToInt(doc ->doc.getAttachPages() == null?0:Integer.parseInt(doc.getAttachPages())).sum();
}
/**
* 获取卷内目录需要填充的数据
* @param extFilesDocLinkVOList
* @param extFilesVO
* @return
*/
public Map<String,Object> getJNDirectoryFillData(List<ExtFilesDocLinkVO> extFilesDocLinkVOList,ExtFilesVO extFilesVO){ public Map<String,Object> getJNDirectoryFillData(List<ExtFilesDocLinkVO> extFilesDocLinkVOList,ExtFilesVO extFilesVO){
List<Map<String, Object>> extFilesMap = new ArrayList<>(); List<Map<String, Object>> extFilesMap = new ArrayList<>();
Map<String, Object> resultDatas = new HashMap<>(); Map<String, Object> resultDatas = new HashMap<>();
...@@ -382,30 +494,35 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic ...@@ -382,30 +494,35 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
Map<String, Object> datas = new HashMap<>(); Map<String, Object> datas = new HashMap<>();
//档号 //档号
datas.put("DH",extFilesVO.getVolumeNumber()); //datas.put("DH",extFilesVO.getVolumeNumber() == null?"":extFilesVO.getVolumeNumber());
//序号 //序号
datas.put("serialNumber",serialNumber); datas.put("serialNumber",serialNumber);
//文件编号
datas.put("fileNumber",source.getNumber()== null?"":source.getNumber());
//责任责 ---文件创建部门 //责任责 ---文件创建部门
DxUserInfoVO userVO = (DxUserInfoVO) userService.get(source.getCreatorId()); DxUserInfoVO userVO = (DxUserInfoVO) userService.get(source.getCreatorId());
//通过orgId获取组织名称 //通过orgId获取组织名称
DxOrganizationVO organizationVO = (DxOrganizationVO) organizationService.get(userVO.getDxOrganizationId()); DxOrganizationVO organizationVO = (DxOrganizationVO) organizationService.get(userVO.getDxOrganizationId());
datas.put("author",organizationVO.getName()); datas.put("author",organizationVO.getName()== null?"":organizationVO.getName());
//文件题目 -- 文件名称 //文件题目 -- 文件名称
datas.put("fileName",source.getName()); datas.put("fileName",source.getName()== null?"":source.getName());
//日期 -- 文件发布日期,有流程的文件取流程结束时间,无流程的文件取文件创建时间 //日期 -- 文件发布日期,有流程的文件取流程结束时间,无流程的文件取文件创建时间
datas.put("date",source.getCreateTime()); datas.put("date",source.getCreateTime()== null?"": DateUtils.converLocalDateToString(source.getCreateTime()));
//页数 --文件页数 //页数 --文件页数
datas.put("pageNumber",extFilesDocLinkVO.getSource().getAttachPages()); datas.put("pageNumber",extFilesDocLinkVO.getSource().getAttachPages() == null?"":extFilesDocLinkVO.getSource().getAttachPages());
//密级 --文件密级 //密级 --文件密级
datas.put("secret",searchDictDataValueByDictCode(Constants.SECRET_CODE,extFilesDocLinkVO.getSource().getSecretCode())); datas.put("secret",searchDictDataValueByDictCode(Constants.SECRET_CODE,extFilesDocLinkVO.getSource().getSecretCode()));
//备注 -- 文件本身的备注 //备注 -- 文件本身的备注
datas.put("note",source.getNote()); datas.put("note",source.getNote() == null?"":source.getNote());
//档号 -- 文件档号 --在移交单文档关联中 //档号 -- 文件档号 --在移交单文档关联中
datas.put("fileDH",""); String fileDH = getFileDH(source);
datas.put("fileDH",fileDH == null?"":fileDH);
extFilesMap.add(datas); extFilesMap.add(datas);
serialNumber++; serialNumber++;
} }
resultDatas.put("data", extFilesMap); resultDatas.put("data", extFilesMap);
//档号
resultDatas.put("DH",extFilesVO.getVolumeNumber() == null?"":extFilesVO.getVolumeNumber());
return resultDatas; return resultDatas;
} }
...@@ -436,6 +553,27 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic ...@@ -436,6 +553,27 @@ public class ExtFilesServiceImpl<V extends ExtFilesVO> implements ExtFilesServic
log.error("所查字典Key为空!字典code为:" + dictCode); log.error("所查字典Key为空!字典code为:" + dictCode);
return ""; return "";
} }
public String getFileDH(DxDocumentVO source){
List content = extTransferDocLinkService.findRecursion(SearchUtil.buildQuery("sourceId", SearchItem.Operator.EQ, source.getId())).getContent();
if(ObjectUtils.isNotEmpty(content)){
ExtTransferDocLinkVO extTransferDocLinkVO = (ExtTransferDocLinkVO)content.get(0);
return extTransferDocLinkVO.getArchiveNumber();
}
return "";
}
public String getJNMLFileName(ExtFilesVO extFilesVO){
String secretCode = searchDictDataValueByDictCode(Constants.SECRET_CODE, extFilesVO.getSecretCode());
return extFilesVO.getVolumeNumber()+"_卷内目录("+secretCode+")";
}
public String getBKFileName(ExtFilesVO extFilesVO){
String secretCode = searchDictDataValueByDictCode(Constants.SECRET_CODE, extFilesVO.getSecretCode());
return extFilesVO.getVolumeNumber()+"_备考表("+secretCode+")";
}
} }
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