|
@@ -32,6 +32,7 @@ import org.apache.commons.lang.StringUtils;
|
|
import org.springblade.archive.entity.ArchiveProjectConfig;
|
|
import org.springblade.archive.entity.ArchiveProjectConfig;
|
|
import org.springblade.archive.entity.ArchivesAuto;
|
|
import org.springblade.archive.entity.ArchivesAuto;
|
|
import org.springblade.archive.service.IArchiveAutoPdfService;
|
|
import org.springblade.archive.service.IArchiveAutoPdfService;
|
|
|
|
+import org.springblade.archive.service.IArchiveOfflineVersionInfoService;
|
|
import org.springblade.archive.service.IArchiveProjectConfigService;
|
|
import org.springblade.archive.service.IArchiveProjectConfigService;
|
|
import org.springblade.archive.utils.ArchiveTreeUtil;
|
|
import org.springblade.archive.utils.ArchiveTreeUtil;
|
|
import org.springblade.archive.utils.FileTransJavaDemo;
|
|
import org.springblade.archive.utils.FileTransJavaDemo;
|
|
@@ -82,9 +83,14 @@ import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
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.time.LocalDateTime;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -120,6 +126,8 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
|
|
|
|
private final MetadataClassificationClient metadataClassificationClient;
|
|
private final MetadataClassificationClient metadataClassificationClient;
|
|
|
|
|
|
|
|
+ private final IArchiveOfflineVersionInfoService versionInfoService;
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public IPage<ArchivesAutoVO> selectArchivesAutoPage(IPage<ArchivesAutoVO> page, ArchivesAutoVO archivesAuto) {
|
|
public IPage<ArchivesAutoVO> selectArchivesAutoPage(IPage<ArchivesAutoVO> page, ArchivesAutoVO archivesAuto) {
|
|
@@ -2322,4 +2330,103 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
|
|
}
|
|
}
|
|
return null;
|
|
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();
|
|
|
|
+ }
|
|
}
|
|
}
|