|
@@ -32,6 +32,7 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.springblade.archive.entity.ArchiveProjectConfig;
|
|
|
import org.springblade.archive.entity.ArchivesAuto;
|
|
|
import org.springblade.archive.service.IArchiveAutoPdfService;
|
|
|
+import org.springblade.archive.service.IArchiveOfflineVersionInfoService;
|
|
|
import org.springblade.archive.service.IArchiveProjectConfigService;
|
|
|
import org.springblade.archive.utils.ArchiveTreeUtil;
|
|
|
import org.springblade.archive.utils.FileTransJavaDemo;
|
|
@@ -82,9 +83,14 @@ import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -120,6 +126,8 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
|
|
|
private final MetadataClassificationClient metadataClassificationClient;
|
|
|
|
|
|
+ private final IArchiveOfflineVersionInfoService versionInfoService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public IPage<ArchivesAutoVO> selectArchivesAutoPage(IPage<ArchivesAutoVO> page, ArchivesAutoVO archivesAuto) {
|
|
@@ -147,6 +155,19 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
if (StringUtils.isNotBlank(vo.getCarrierType())) {
|
|
|
vo.setCarrierTypes(Arrays.asList(vo.getCarrierType().split(",")));
|
|
|
}
|
|
|
+ //判断是否多字段查询
|
|
|
+ if (StringUtils.isNotBlank(vo.getQueryValue())){
|
|
|
+ String queryValue = vo.getQueryValue();
|
|
|
+ if (queryValue.contains(",") || queryValue.contains(",")){
|
|
|
+ if (queryValue.contains(",")){
|
|
|
+ vo.setQueryList(Func.toStrList(",",queryValue));
|
|
|
+ }else if (queryValue.contains(",")){
|
|
|
+ vo.setQueryList(Func.toStrList(",",queryValue));
|
|
|
+ }
|
|
|
+ vo.setQueryValue(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //新增
|
|
|
List<ArchivesAutoVO> archivesAutos = null;
|
|
|
//获取合同段类型
|
|
|
ContractInfo contractInfo = contractClient.getContractById(vo.getContractId());
|
|
@@ -1658,9 +1679,9 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
* @param contractId
|
|
|
* @param nodeId
|
|
|
*/
|
|
|
- public void refreshFileNumberNoSlipt(Long projectId,Long contractId,Long nodeId) {
|
|
|
+ public void refreshFileNumberNoSlipt(Long projectId,Long contractId,Long nodeId,boolean bforce) {
|
|
|
List<ArchiveTreeContract> list = archiveTreeContractClient.getListByProjectId(projectId);
|
|
|
- this.refreshFileNumberNoSlipt(list,contractId,nodeId);
|
|
|
+ this.refreshFileNumberNoSlipt(list,contractId,nodeId,bforce);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1669,7 +1690,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
* @param contractId
|
|
|
* @param nodeId
|
|
|
*/
|
|
|
- public void refreshFileNumberNoSlipt(List<ArchiveTreeContract> archiveTreeContracts,Long contractId,Long nodeId) {
|
|
|
+ public void refreshFileNumberNoSlipt(List<ArchiveTreeContract> archiveTreeContracts,Long contractId,Long nodeId,boolean bforce) {
|
|
|
|
|
|
List<ArchiveTreeContractVO2> subTreeList = new ArrayList<>();
|
|
|
List<List<ArchiveTreeContract>> subGroupedList = new ArrayList<>();
|
|
@@ -1726,9 +1747,16 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
}
|
|
|
|
|
|
String fileNumber = fileNumberPrefix +"_"+ index;
|
|
|
- if (archiveAutoPdfService.refreshFileNumberForce(archivesAuto,fileNumber)){
|
|
|
- changeList.add(archivesAuto);
|
|
|
+ if (bforce) {
|
|
|
+ if (archiveAutoPdfService.refreshFileNumberForce(archivesAuto,fileNumber)){
|
|
|
+ changeList.add(archivesAuto);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (archiveAutoPdfService.refreshFileNumber(archivesAuto,fileNumber)){
|
|
|
+ changeList.add(archivesAuto);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
index++;
|
|
|
}
|
|
|
}
|
|
@@ -1767,71 +1795,75 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
String back = "";
|
|
|
|
|
|
|
|
|
- if(frontUrls != null ) {
|
|
|
- for (String frontUrl : frontUrls) {
|
|
|
- if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[0]) && config.getFactorType().contains("1")) {
|
|
|
- front = frontUrl;
|
|
|
- } else if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[1]) && config.getFactorType().contains("2")) {
|
|
|
- cataLog = frontUrl;
|
|
|
- } else if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[2]) && config.getFactorType().contains("3")) {
|
|
|
- spare = frontUrl;
|
|
|
- } else if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[3]) && config.getFactorType().contains("4")) {
|
|
|
- back = frontUrl;
|
|
|
+ try {
|
|
|
+ if(frontUrls != null ) {
|
|
|
+ for (String frontUrl : frontUrls) {
|
|
|
+ if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[0]) && config.getFactorType().contains("1")) {
|
|
|
+ front = frontUrl;
|
|
|
+ } else if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[1]) && config.getFactorType().contains("2")) {
|
|
|
+ cataLog = frontUrl;
|
|
|
+ } else if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[2]) && config.getFactorType().contains("3")) {
|
|
|
+ spare = frontUrl;
|
|
|
+ } else if (frontUrl.contains(ArchiveAutoPdfServiceImpl.ARCHIVE_NUMBER[3]) && config.getFactorType().contains("4")) {
|
|
|
+ back = frontUrl;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- List<String> fileUrls =new ArrayList<>();
|
|
|
- //if (!archivesAuto.isMedia())
|
|
|
- if (true)
|
|
|
- {
|
|
|
- List<ArchiveFile> result = this.archiveFileClient.getArchiveFileByArchivesId(archivesAuto.getId().toString(),"");
|
|
|
- if(result != null && result.size() > 0){
|
|
|
- //循环访问result,如果pdfpageurl不为空则取出,否则取pdffileurl
|
|
|
- for (ArchiveFile archiveFile : result) {
|
|
|
- String pdfPageUrl = archiveFile.getPdfPageUrl();
|
|
|
- if (StringUtils.isEmpty(pdfPageUrl)) {
|
|
|
- pdfPageUrl = archiveFile.getPdfFileUrl();
|
|
|
- }else{
|
|
|
+ List<String> fileUrls =new ArrayList<>();
|
|
|
+ //if (!archivesAuto.isMedia())
|
|
|
+ if (true)
|
|
|
+ {
|
|
|
+ List<ArchiveFile> result = this.archiveFileClient.getArchiveFileByArchivesId(archivesAuto.getId().toString(),"");
|
|
|
+ if(result != null && result.size() > 0){
|
|
|
+ //循环访问result,如果pdfpageurl不为空则取出,否则取pdffileurl
|
|
|
+ for (ArchiveFile archiveFile : result) {
|
|
|
+ String pdfPageUrl = archiveFile.getPdfPageUrl();
|
|
|
+ if (StringUtils.isEmpty(pdfPageUrl)) {
|
|
|
+ pdfPageUrl = archiveFile.getPdfFileUrl();
|
|
|
+ }else{
|
|
|
+ fileUrls.add(pdfPageUrl);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(pdfPageUrl) || !pdfPageUrl.contains("pdf")) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
fileUrls.add(pdfPageUrl);
|
|
|
}
|
|
|
- if (StringUtils.isEmpty(pdfPageUrl) || !pdfPageUrl.contains("pdf")) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- fileUrls.add(pdfPageUrl);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (fileUrls.size() > 0){
|
|
|
- //此处暂时这么处理,等oss上传接口里文件名可以区分后,再单独取
|
|
|
-// if (frontUrls != null && frontUrls.length > 3){
|
|
|
-//
|
|
|
-// urlList.add(frontUrls[0]);
|
|
|
-// urlList.add(frontUrls[1]);
|
|
|
-// }
|
|
|
- if (StringUtils.isNotEmpty(front)) {
|
|
|
- urlList.add(front);
|
|
|
- }
|
|
|
+ if (fileUrls.size() > 0){
|
|
|
+ //此处暂时这么处理,等oss上传接口里文件名可以区分后,再单独取
|
|
|
+ // if (frontUrls != null && frontUrls.length > 3){
|
|
|
+ //
|
|
|
+ // urlList.add(frontUrls[0]);
|
|
|
+ // urlList.add(frontUrls[1]);
|
|
|
+ // }
|
|
|
+ if (StringUtils.isNotEmpty(front)) {
|
|
|
+ urlList.add(front);
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(cataLog)) {
|
|
|
- urlList.add(cataLog);
|
|
|
- }
|
|
|
+ if (StringUtils.isNotEmpty(cataLog)) {
|
|
|
+ urlList.add(cataLog);
|
|
|
+ }
|
|
|
|
|
|
- urlList.addAll(fileUrls);
|
|
|
+ urlList.addAll(fileUrls);
|
|
|
|
|
|
-// if (frontUrls != null && frontUrls.length > 3){
|
|
|
-// urlList.add(frontUrls[2]);
|
|
|
-// urlList.add(frontUrls[3]);
|
|
|
-// }
|
|
|
- if (StringUtils.isNotEmpty(spare)) {
|
|
|
- urlList.add(spare);
|
|
|
- }
|
|
|
+ // if (frontUrls != null && frontUrls.length > 3){
|
|
|
+ // urlList.add(frontUrls[2]);
|
|
|
+ // urlList.add(frontUrls[3]);
|
|
|
+ // }
|
|
|
+ if (StringUtils.isNotEmpty(spare)) {
|
|
|
+ urlList.add(spare);
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(back)) {
|
|
|
- urlList.add(back);
|
|
|
+ if (StringUtils.isNotEmpty(back)) {
|
|
|
+ urlList.add(back);
|
|
|
+ }
|
|
|
+ String fileName = SnowFlakeUtil.getId().toString();
|
|
|
+ url = archiveAutoPdfService.MergePdfAndUpload(urlList,fileName,null,archivesAuto.getProjectId());
|
|
|
}
|
|
|
- String fileName = SnowFlakeUtil.getId().toString();
|
|
|
- url = archiveAutoPdfService.MergePdfAndUpload(urlList,fileName,null,archivesAuto.getProjectId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
return url;
|
|
|
}
|
|
@@ -2084,7 +2116,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
|
|
|
//刷新项目档号
|
|
|
log.info("[自动组卷]{}","开始刷新组卷档号。projectId:"+projectId+"-contractId:"+contractId+"-nodeId:"+nodeId);
|
|
|
- refreshFileNumberNoSlipt(projectId,contractId,nodeId);
|
|
|
+ refreshFileNumberNoSlipt(projectId,contractId,nodeId,true);
|
|
|
|
|
|
|
|
|
//设置自动组卷结束
|
|
@@ -2322,4 +2354,103 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchDownloadFileToZip(String ids, HttpServletResponse response) {
|
|
|
+ List<Long> longs = Func.toLongList(ids);
|
|
|
+ //获取档案下的文件
|
|
|
+ List<ArchiveFile> result = baseMapper.batchSearchArchiveFile(longs);
|
|
|
+ //判断是否存在文件
|
|
|
+ if (result != null && result.size() > 0) {
|
|
|
+ //获取选择的案卷,只要id和文件提名字段
|
|
|
+ Map<Long, String> nameMap = baseMapper.getArchives(longs).stream().filter(l -> StringUtils.isNotBlank(l.getName())).collect(Collectors.toMap(l -> l.getId(), l -> l.getName()));
|
|
|
+ //默认下载地址
|
|
|
+ String defaultDir = "/www/wwwroot/Users/hongchuangyanfa/Desktop/archiveDownload";
|
|
|
+ //项目下地址
|
|
|
+ String projectDir = defaultDir+"/" + result.get(0).getProjectId();
|
|
|
+ File file = new File(projectDir);
|
|
|
+ //获取项目名称
|
|
|
+ ProjectInfo projectInfo = projectClient.getById(result.get(0).getProjectId());
|
|
|
+ //判断文件夹是否存在,存在则该项目正在下载打包,不存在则生成
|
|
|
+ if (file.exists()) {
|
|
|
+ throw new ServiceException("当前项目正在下载档案,请稍后再试");
|
|
|
+ } else {
|
|
|
+ file.mkdir();
|
|
|
+ }
|
|
|
+ //删除掉pdfUrl为空的数据
|
|
|
+ result.removeIf(query -> StringUtils.isEmpty(query.getPdfFileUrl()));
|
|
|
+ //按照档案id分组
|
|
|
+ Map<Long, List<ArchiveFile>> map = result.stream().collect(Collectors.groupingBy(ArchiveFile::getArchiveId));
|
|
|
+ try {
|
|
|
+ //为每个档案分别设置
|
|
|
+ for (Long archiveId : map.keySet()) {
|
|
|
+ String initName = nameMap.get(archiveId);
|
|
|
+ String[] split = initName.split(")");
|
|
|
+ String name = split[split.length-1];
|
|
|
+ String archiveDir = projectDir + "/" + name;
|
|
|
+ //创建档案文件夹
|
|
|
+ File file2 = new File(archiveDir);
|
|
|
+ file2.mkdir();
|
|
|
+ //组卷,下载PDF
|
|
|
+ String mergeArchivesFile = this.getMergeArchivesFile(archiveId);
|
|
|
+ InputStream file_out2 = CommonUtil.getOSSInputStream(mergeArchivesFile);
|
|
|
+ if (file_out2 != null) {
|
|
|
+ CommonUtil.inputStreamToFile(file_out2, new File(archiveDir+"/" + name+".pdf"));
|
|
|
+ file_out2.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ //下载卷内文件
|
|
|
+ String archiveFileDir = archiveDir + "/" + "卷内文件";
|
|
|
+ File file3 = new File(archiveFileDir);
|
|
|
+ file3.mkdir();
|
|
|
+ List<ArchiveFile> files = map.get(archiveId);
|
|
|
+ for (ArchiveFile archiveFile : files) {
|
|
|
+ String fileUrl = archiveFile.getPdfFileUrl();
|
|
|
+ String initFileName = archiveFile.getFileName();
|
|
|
+ if (initFileName.length() > 100){
|
|
|
+ initFileName = initFileName.substring(0,100);
|
|
|
+ }
|
|
|
+ String fileName = "/" + initFileName+".pdf";
|
|
|
+ InputStream file_out = CommonUtil.getOSSInputStream(fileUrl);
|
|
|
+ if (file_out != null) {
|
|
|
+ CommonUtil.inputStreamToFile(file_out, new File(archiveFileDir + fileName));
|
|
|
+ file_out.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //下载完成,打包文件
|
|
|
+ this.packageZip2(defaultDir,projectDir,projectInfo.getId());
|
|
|
+ String zipFile = defaultDir + "/"+projectInfo.getId()+".zip";
|
|
|
+ Path path = Paths.get(zipFile);
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename="+projectInfo.getProjectName());
|
|
|
+ // 获取文件内容流并写入响应
|
|
|
+ Files.copy(path, response.getOutputStream());
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 压缩指定路径下的文件夹-直接执行linux命令,多线程,速度快几十倍
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void packageZip2(String defaultDir,String projectDir,Long id) throws Exception {
|
|
|
+ // 要被压缩的文件夹
|
|
|
+ File folder = new File(defaultDir);
|
|
|
+ if (!folder.exists() && !folder.isDirectory()) {
|
|
|
+ folder.mkdirs();
|
|
|
+ }
|
|
|
+ // 执行脚本文件
|
|
|
+ // 多条命令执行
|
|
|
+ String[] cmds = {"/bin/sh", "-c", "cd "+defaultDir+" && zip -q -r "+projectDir+".zip "+id};
|
|
|
+ System.out.println("开始执行命令:" + Arrays.toString(cmds));
|
|
|
+ //主要在这步写入后调用命令
|
|
|
+ Process process = Runtime.getRuntime().exec(cmds);
|
|
|
+ process.waitFor();
|
|
|
+ }
|
|
|
}
|