|
|
@@ -68,6 +68,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.InputStream;
|
|
|
@@ -2569,4 +2570,70 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+ @Override
|
|
|
+ public void download(String ids, Integer classify, Integer type, HttpServletResponse response) {
|
|
|
+ List<TrialSelfInspectionRecord> recordList = baseMapper.selectList(Wrappers.<TrialSelfInspectionRecord>lambdaQuery().in(TrialSelfInspectionRecord::getId, Func.toLongList(ids)));
|
|
|
+// .eq(TrialSelfInspectionRecord::getTaskStatus, "已审批"));
|
|
|
+ if (recordList.isEmpty()) {
|
|
|
+ throw new ServiceException("请选择已审批的记录");
|
|
|
+ }
|
|
|
+ List<String> pdfList = null;
|
|
|
+ List<String> deletedFileUrls = new ArrayList<>();
|
|
|
+ //打包下载
|
|
|
+ try {
|
|
|
+ if (type == 1) {
|
|
|
+ // 整份下载
|
|
|
+ List<String> tempUrls = new ArrayList<>();
|
|
|
+ recordList.forEach(record -> {
|
|
|
+ //合并的pdfUrl
|
|
|
+ try {
|
|
|
+ String pdf = this.getMergePdfToTrialNew(record.getContractId(), record.getId(), classify);
|
|
|
+ if (StringUtil.hasText(pdf)) {
|
|
|
+ tempUrls.add(pdf + "@@@" + record.getRecordNo().replaceAll("\\\\", "_").replaceAll("/", "_"));
|
|
|
+ deletedFileUrls.add(pdf);
|
|
|
+ }
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ pdfList = tempUrls;
|
|
|
+ } else if (type == 2) {
|
|
|
+ // 报告表下载
|
|
|
+ pdfList = recordList.stream().filter(item -> StringUtil.hasText(item.getReportPdfUrl())).map(item -> item.getReportPdfUrl() + "@@@" + item.getReportNo().replaceAll("\\\\", "_").replaceAll("/", "_")).collect(Collectors.toList());
|
|
|
+ } else if (type == 3) {
|
|
|
+ // 记录表下载
|
|
|
+ pdfList = recordList.stream().filter(item -> StringUtil.hasText(item.getRecordPdfUrl())).map(item -> item.getRecordPdfUrl() + "@@@" + item.getRecordNo().replaceAll("\\\\", "_").replaceAll("/", "_")).collect(Collectors.toList());
|
|
|
+ } else if (type == 4) {
|
|
|
+ // 委托单下载
|
|
|
+ Set<Long> entrustIds = recordList.stream().filter(record -> record.getEntrustId() != null && record.getEntrustId() > 0).map(TrialSelfInspectionRecord::getEntrustId).collect(Collectors.toSet());
|
|
|
+ if (entrustIds.isEmpty()) {
|
|
|
+ throw new ServiceException("未找到委托单记录");
|
|
|
+ }
|
|
|
+ List<EntrustInfo> entrustInfoList = entrustInfoService.listByIds(entrustIds);
|
|
|
+ pdfList = entrustInfoList.stream().filter(item -> item.getEntrustEPdf() != null && StringUtil.hasText(item.getEntrustEPdf()))
|
|
|
+ .map(item -> item.getEntrustEPdf() + "@@@" + item.getEntrustNo().replaceAll("\\\\", "_").replaceAll("/", "_")).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (pdfList == null || pdfList.isEmpty()) {
|
|
|
+ if (type == 1) {
|
|
|
+ throw new ServiceException("未找到试验自检记录的pdf");
|
|
|
+ } else if (type == 2) {
|
|
|
+ throw new ServiceException("未找到报告表pdf");
|
|
|
+ } else if (type == 3) {
|
|
|
+ throw new ServiceException("未找到记录表pdf");
|
|
|
+ } else if (type == 4) {
|
|
|
+ throw new ServiceException("未找到委托单pdf");
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("未找到pdf");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FileUtils.batchDownloadFileToZip(pdfList, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (!deletedFileUrls.isEmpty()) {
|
|
|
+ newIOSSClient.removeFiles(deletedFileUrls);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|