wangliang 4 лет назад
Родитель
Сommit
086d11fc10

+ 8 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -297,15 +297,19 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             }
             JSONObject attachmentPath = JSONObject.parseObject(examDetailCourse.getAttachmentPath());
             attachmentPath = Objects.isNull(attachmentPath) ? new JSONObject() : attachmentPath;
-            JSONArray jsonArray = (JSONArray) attachmentPath.get("path");
+            JSONArray jsonArray = (JSONArray) attachmentPath.get(SystemConstant.PATH);
             jsonArray = Objects.isNull(jsonArray) ? new JSONArray() : jsonArray;
             JSONObject object = new JSONObject();
-            object.put(SystemConstant.TYPE, printType);
+            object.put("printType", printType);
             object.put(SystemConstant.HTML_PATH, filePath);
             object.put(SystemConstant.PDF_PATH, pdfDirName);
-            object.put(SystemConstant.UPLOAD_TYPE, oss);
+            object.put(SystemConstant.TYPE, oss);
+            object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
+                    UploadFileEnum.HTML,
+                    UploadFileEnum.PDF
+            });
             jsonArray.add(object);
-            attachmentPath.put("path", jsonArray);
+            attachmentPath.put(SystemConstant.PATH, jsonArray);
             examDetailCourse.setAttachmentPath(attachmentPath.toJSONString());
             basicAttachment.setPages(pdfDto.getActualPageCount());
             for (int i = 0; i < printCount; i++) {

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncExaminationExportTemplateService.java

@@ -44,7 +44,7 @@ public class AsyncExaminationExportTemplateService extends AsyncExportTaskTemple
             TaskLogicService taskLogicService = SpringContextHolder.getBean(TaskLogicService.class);
             Map<String, Object> result = taskLogicService.executeExaminationLogic(map);
             stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", FORMAT_TIME, FINISH_TITLE, result.size(), FINISH_SIZE));
-            String path = String.valueOf(result.get("path"));
+            String path = String.valueOf(result.get(SystemConstant.PATH));
             System.out.println("path = " + path);
             tbTask.setImportFileName(TaskTypeEnum.EXAMINATION_EXPORT.getTitle());
             tbTask.setResultFilePath(path);

+ 20 - 12
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -47,6 +47,7 @@ import java.io.*;
 import java.lang.reflect.Field;
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 /**
@@ -114,6 +115,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     BasicExamRuleService basicExamRuleService;
 
+    private static volatile ConcurrentHashMap<Integer, String> paperTypeMap = null;
+
     /**
      * 创建pdf逻辑
      *
@@ -165,6 +168,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             }
             attachmentIds = Objects.isNull(attachmentIds) ? attachmentIds = new HashSet<>() : attachmentIds;
             ftlList = Objects.isNull(ftlList) ? ftlList = new HashSet<>() : ftlList;
+            paperTypeMap = Objects.isNull(paperTypeMap) ? paperTypeMap = new ConcurrentHashMap<>() : paperTypeMap;
             for (ExamDetail examDetail : examDetailList) {
                 tbTask.setObjName(examDetail.getExamRoom() + "-" + examDetail.getExamPlace());
                 //查询examDetailCourse
@@ -234,12 +238,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
 
                             //抽取卷型
-                            String paperType = Objects.nonNull(paperTypeParam) ? paperTypeParam : createPdfUtil.getPaperType(examPrintPlan, examTaskDetail);
+                            String paperType = Objects.nonNull(paperTypeParam) ? paperTypeParam : createPdfUtil.getPaperType(examPrintPlan, examTaskDetail, examDetail, examDetailCourse);
                             examTaskDetail.setRelatePaperType(paperType);
 
                             //获取试卷pdf
                             PdfDto pdfDto = createPdfUtil.getPaperPdf(paperType, examTaskDetail, examPrintPlan.getBackupCount(), paperPdfTempList, backupPaperTempPdfList);
-                            examDetailCourse.setPaperPagesA3(pdfDto.getPageCount());
+                            examDetailCourse.setPaperPagesA3(Objects.nonNull(pdfDto) ? pdfDto.getPageCount() : examDetailCourse.getPaperPagesA3());
                             paperPdfList.addAll(paperPdfTempList);
                             backupPaperPdfList.addAll(backupPaperTempPdfList);
 
@@ -353,7 +357,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
         jsonObject.put(SystemConstant.PATH, dirName);
         jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
-        map.put("path", jsonObject.toString());
+        map.put(SystemConstant.PATH, jsonObject.toString());
         return map;
     }
 
@@ -384,7 +388,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         }
         String importFilePath = tbTask.getImportFilePath();
         Map importFilePathMap = JSONObject.parseObject(importFilePath);
-        String path = String.valueOf(importFilePathMap.get("path"));
+        String path = String.valueOf(importFilePathMap.get(SystemConstant.PATH));
         Workbook workbook;
         if (path.endsWith(SystemConstant.XLSX)) {
             workbook = new XSSFWorkbook(inputStream);
@@ -452,7 +456,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
                 for (Field examinationImportDtoField : examinationImportDtoFields) {
                     ExcelDBFieldDesc excelDBFieldDesc = examinationImportDtoField.getAnnotation(ExcelDBFieldDesc.class);
-                    if (excelDBFieldDesc == null){
+                    if (excelDBFieldDesc == null) {
                         // 如果没有注解,说明该数据库必须字段不是从excel中获得的,直接跳过
                         continue;
                     }
@@ -460,12 +464,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     // 如果数据库字段中文名和必填字段中文名称对应,则通过反射为数据库必选字段赋值
                     String dbName = excelDBFieldDesc.name();
                     int dbLength = excelDBFieldDesc.length();
-                    if (dbName.equals(name)){
+                    if (dbName.equals(name)) {
                         if (dbLength > 0) {
                             ConvertUtil.verifyLength(cellValue, dbLength, dbName);
                         }
                         examinationImportDtoField.setAccessible(true);
-                        examinationImportDtoField.set(examinationImportDto,cellValue);
+                        examinationImportDtoField.set(examinationImportDto, cellValue);
                         match = true;
                         break;
                     }
@@ -594,8 +598,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
                         StringJoiner stringJoinerPdf = new StringJoiner("")
                                 .add(SystemConstant.TEMP_FILES_DIR).add(File.separator)
-                                .add((String) jsonObject.get("path"));
-                        sourceFiles.add(ossUtil.ossDownload((String) jsonObject.get("path"), stringJoinerPdf.toString()));
+                                .add((String) jsonObject.get(SystemConstant.PATH));
+                        sourceFiles.add(ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString()));
                     }
                     FileUtil.doZip(zipFile, sourceFiles);
                     ossUtil.ossUpload(dirName.toString(), zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
@@ -676,7 +680,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 for (BasicAttachment paperAttachment : paperAttachmentList) {
                     JSONObject jsonObject = JSONObject.parseObject(paperAttachment.getPath());
                     String paperPath = firstPath + File.separator + "试卷" + File.separator + paperAttachment.getName() + paperAttachment.getType();
-                    ossUtil.ossDownload((String) jsonObject.get("path"), paperPath);
+                    ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath);
                     count++;
                 }
             }
@@ -697,7 +701,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 for (BasicAttachment confirmAttachment : confirmAttachmentList) {
                     JSONObject jsonObject = JSONObject.parseObject(confirmAttachment.getPath());
                     String confirmPath = firstPath + File.separator + "审核样本" + File.separator + confirmAttachment.getName() + confirmAttachment.getType();
-                    ossUtil.ossDownload((String) jsonObject.get("path"), confirmPath);
+                    ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), confirmPath);
                     count++;
                 }
             }
@@ -728,7 +732,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 }
                 JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
                 String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
-                ossUtil.ossDownload((String) jsonObject.get("path"), cardPath);
+                ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath);
                 count++;
             } else {
                 List<ExamCardDetail> examCardDetailList = examCardDetailService.list(new QueryWrapper<ExamCardDetail>().lambda().eq(ExamCardDetail::getCardId, cardId));
@@ -759,4 +763,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         map.put("count", count);
         return map;
     }
+
+    public static ConcurrentHashMap<Integer, String> getPaperTypeMap() {
+        return paperTypeMap;
+    }
 }

+ 45 - 23
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -16,6 +16,7 @@ import com.qmth.distributed.print.business.enums.PrintMethodEnum;
 import com.qmth.distributed.print.business.service.BasicAttachmentService;
 import com.qmth.distributed.print.business.service.CommonService;
 import com.qmth.distributed.print.business.service.ExamDetailService;
+import com.qmth.distributed.print.business.templete.service.impl.TaskLogicServiceImpl;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -28,6 +29,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.*;
+import java.util.concurrent.ConcurrentMap;
 import java.util.stream.Collectors;
 
 /**
@@ -324,9 +326,12 @@ public class CreatePdfUtil {
                         pdfList[1].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
                     }
                 }
+                return new PdfDto(PageSizeEnum.A3, pages, tag);
+            } else {
+                return null;
             }
         }
-        return new PdfDto(PageSizeEnum.A3, pages, tag);
+        return null;
     }
 
     /**
@@ -334,34 +339,51 @@ public class CreatePdfUtil {
      *
      * @param examPrintPlan
      * @param examTaskDetail
+     * @param examDetail
+     * @param examDetailCourse
      * @return
      */
-    public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail) {
-        //抽取卷型
-        DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
-        //未曝光卷型
-        String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
-        //已曝光卷型
-        String exposedPaperType = examTaskDetail.getExposedPaperType();
-        String[] paperTypes = null;
-        if (drawRule == DrawRuleEnum.ONE) {
-            if (Objects.isNull(unexposedPaperType)) {
-                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
-            } else {
-                paperTypes = unexposedPaperType.split(",");
-            }
+    public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail, ExamDetail examDetail, ExamDetailCourse examDetailCourse) {
+        ConcurrentMap<Integer, String> paperTypeMap = TaskLogicServiceImpl.getPaperTypeMap();
+        StringJoiner key = new StringJoiner("")
+                .add(examDetail.getSchoolId() + "")
+                .add((examDetail.getExamStartTime() + examDetail.getExamEndTime()) + "")
+                .add(examDetail.getExamPlace())
+                .add(examDetailCourse.getCourseCode())
+                .add(examDetailCourse.getPaperNumber());
+        String paperType = null;
+        if (paperTypeMap.containsKey(key.hashCode())) {
+            paperType = paperTypeMap.get(key.hashCode());
         } else {
-            if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
-                throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
-            }
-            if (Objects.nonNull(unexposedPaperType)) {
-                paperTypes = unexposedPaperType.split(",");
+            //抽取卷型
+            DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
+            //未曝光卷型
+            String unexposedPaperType = examTaskDetail.getUnexposedPaperType();
+            //已曝光卷型
+            String exposedPaperType = examTaskDetail.getExposedPaperType();
+            String[] paperTypes = null;
+            if (drawRule == DrawRuleEnum.ONE) {
+                if (Objects.isNull(unexposedPaperType)) {
+                    throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
+                } else {
+                    paperTypes = unexposedPaperType.split(",");
+                }
             } else {
-                paperTypes = exposedPaperType.split(",");
+                if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
+                    throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
+                }
+                if (Objects.nonNull(unexposedPaperType)) {
+                    paperTypes = unexposedPaperType.split(",");
+                } else {
+                    paperTypes = exposedPaperType.split(",");
+                }
             }
+            int paperRandom = new Random().nextInt(paperTypes.length);
+            paperType = paperTypes[paperRandom];
+            String finalPaperType = paperType;
+            paperTypeMap.computeIfAbsent(key.hashCode(), v -> finalPaperType);
         }
-        int paperRandom = new Random().nextInt(paperTypes.length);
-        return paperTypes[paperRandom];
+        return paperType;
     }
 
     /**