|
@@ -17,6 +17,7 @@ import com.qmth.distributed.print.business.service.CommonService;
|
|
|
import com.qmth.distributed.print.business.service.ExamDetailService;
|
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.distributed.print.common.util.JacksonUtil;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -27,6 +28,7 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -457,33 +459,38 @@ public class CreatePdfUtil {
|
|
|
*/
|
|
|
public BasicAttachment mergePdf(BasicExamRule basicExamRule, TBTask tbTask, ExamDetail examDetail, Long userId, Long schoolId, List<PdfDto>... list) throws IOException {
|
|
|
StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
|
|
|
- List<PdfDto> mergePdfList = new ArrayList<>();
|
|
|
+ List<PdfDto> mergePdfA3List = new ArrayList<>();
|
|
|
List<PdfDto> mergePdfA4List = new ArrayList<>();
|
|
|
- int pageA3Count = 0;
|
|
|
- int pageA4Count = 0;
|
|
|
+// AtomicInteger pageA4Count = new AtomicInteger(0);
|
|
|
+ AtomicInteger pageA3Count = new AtomicInteger(0);
|
|
|
for (int i = 0; i < list.length; i++) {
|
|
|
if (list[i].size() > 0 && list[i].get(0).getPageSize() == PageSizeEnum.A4) {
|
|
|
- pageA4Count = pageA4Count + list[i].stream().mapToInt(PdfDto::getPageCount).sum();
|
|
|
+// pageA4Count.addAndGet(list[i].stream().mapToInt(PdfDto::getPageCount).sum());
|
|
|
mergePdfA4List.addAll(list[i]);
|
|
|
} else if (list[i].size() > 0 && list[i].get(0).getPageSize() == PageSizeEnum.A3) {
|
|
|
- pageA3Count = pageA3Count + list[i].stream().mapToInt(PdfDto::getPageCount).sum();
|
|
|
- mergePdfList.addAll(list[i]);
|
|
|
+ pageA3Count.addAndGet(list[i].stream().mapToInt(PdfDto::getPageCount).sum());
|
|
|
+ mergePdfA3List.addAll(list[i]);
|
|
|
}
|
|
|
}
|
|
|
- List<String> pathList = mergePdfList.stream().map(PdfDto::getPath).collect(Collectors.toList());
|
|
|
- String dirName = PdfUtil.mergePdf(pathList.toArray(new String[mergePdfList.size()]), null);
|
|
|
+ List<String> pathA4List = mergePdfA4List.stream().map(PdfDto::getPath).collect(Collectors.toList());
|
|
|
+ List<String> pathA3List = mergePdfA3List.stream().map(PdfDto::getPath).collect(Collectors.toList());
|
|
|
+ String dirNameA4 = PdfUtil.mergePdf(pathA4List.toArray(new String[mergePdfA4List.size()]), null);
|
|
|
+ String dirNameA3 = PdfUtil.mergePdf(pathA3List.toArray(new String[mergePdfA3List.size()]), null);
|
|
|
// oss上只认"/",windows生成的路径分隔符全部替换为"/"
|
|
|
- dirName = dirName.replaceAll("\\\\", "/");
|
|
|
- File localPdfFile = new File(stringJoiner.toString() + File.separator + dirName);
|
|
|
- BasicAttachment basicAttachment = basicAttachmentService.saveAttachmentPdf(dirName, userId);
|
|
|
+ dirNameA4 = dirNameA4.replaceAll("\\\\", "/");
|
|
|
+ dirNameA3 = dirNameA3.replaceAll("\\\\", "/");
|
|
|
+ File localA4PdfFile = new File(stringJoiner.toString() + File.separator + dirNameA4);
|
|
|
+ File localA3PdfFile = new File(stringJoiner.toString() + File.separator + dirNameA3);
|
|
|
+ BasicAttachment basicAttachment = basicAttachmentService.saveAttachmentPdf(dirNameA3, userId);
|
|
|
tbTask.setImportFileName(basicAttachment.getName());
|
|
|
tbTask.setImportFilePath(basicAttachment.getPath());
|
|
|
examDetail.setAttachmentId(basicAttachment.getId());
|
|
|
- examDetail.setPagesA3(pageA3Count);
|
|
|
- examDetail.setPagesA4(pageA4Count);
|
|
|
+ examDetail.setPagesA3(PdfUtil.getPdfPages(localA3PdfFile));
|
|
|
+ examDetail.setPagesA4(PdfUtil.getPdfPages(localA4PdfFile));
|
|
|
+ log.info("pageA3Count:{},examDetail:{}", pageA3Count.get(), JacksonUtil.parseJson(examDetail));
|
|
|
examDetail.setStatus(PrintMethodEnum.AUTO == basicExamRule.getPrintMethod() ? ExamDetailStatusEnum.WAITING : ExamDetailStatusEnum.READY);
|
|
|
detailService.saveOrUpdate(examDetail);
|
|
|
- ossUtil.ossUpload(dirName, localPdfFile, DigestUtils.md5Hex(new FileInputStream(localPdfFile)));
|
|
|
+ ossUtil.ossUpload(dirNameA3, localA3PdfFile, DigestUtils.md5Hex(new FileInputStream(localA3PdfFile)));
|
|
|
// localPdfFile.delete();
|
|
|
// for (PdfDto pdfDto : mergePdfList) {
|
|
|
// new File(pdfDto.getPath()).delete();
|