소스 검색

Merge branch 'dev' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev

xiaof 4 년 전
부모
커밋
b3bdbb111b
15개의 변경된 파일209개의 추가작업 그리고 158개의 파일을 삭제
  1. 15 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/annotation/ExcelDBFieldDesc.java
  2. 13 3
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExaminationImportDto.java
  3. 11 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamDetailCourse.java
  4. 0 57
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ExaminationDBFieldsEnum.java
  5. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/RequiredFieldsEnum.java
  6. 8 3
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java
  7. 41 19
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java
  8. 0 3
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java
  9. 1 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java
  10. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncExaminationExportTemplateService.java
  11. 55 38
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java
  12. 57 29
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java
  13. 5 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java
  14. 1 0
      distributed-print-business/src/main/resources/db/init-table.sql
  15. 0 3
      distributed-print/src/main/java/com/qmth/distributed/print/api/EnumsController.java

+ 15 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/annotation/ExcelDBFieldDesc.java

@@ -0,0 +1,15 @@
+package com.qmth.distributed.print.business.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @Description: excel导入考务数据数据库必填属性描述
+ * @Author: CaoZixuan
+ * @Date: 2021-04-26
+ */
+@Retention(RetentionPolicy.RUNTIME) //定义注解运行策略
+public @interface ExcelDBFieldDesc {
+    String name(); //属性名称
+    int length() default 0; //属性接收长度限制默认0,为0的不校验长度
+}

+ 13 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExaminationImportDto.java

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.bean.dto;
 
+import com.qmth.distributed.print.business.annotation.ExcelDBFieldDesc;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.util.List;
@@ -12,30 +13,39 @@ import java.util.List;
 public class ExaminationImportDto {
 
     @ApiModelProperty(value = "学号")
+    @ExcelDBFieldDesc(name = "学号",length = 10)
     private String studentCode;
 
-    @ApiModelProperty(value = "学生姓名")
+    @ApiModelProperty(value = "姓名")
+    @ExcelDBFieldDesc(name = "姓名",length = 15)
     private String studentName;
 
     @ApiModelProperty(value = "课程代码")
+    @ExcelDBFieldDesc(name = "课程代码",length = 10)
     private String courseCode;
 
     @ApiModelProperty(value = "课程名称")
+    @ExcelDBFieldDesc(name = "课程名称",length = 20)
     private String courseName;
 
-    @ApiModelProperty(value = "考场")
+    @ApiModelProperty(value = "考点")
+    @ExcelDBFieldDesc(name = "考点",length = 10)
     private String examPlace;
 
-    @ApiModelProperty(value = "考点")
+    @ApiModelProperty(value = "考场")
+    @ExcelDBFieldDesc(name = "考场",length = 10)
     private String examRoom;
 
     @ApiModelProperty(value = "考试日期")
+    @ExcelDBFieldDesc(name = "考试日期")
     private String examDate;
 
     @ApiModelProperty(value = "考试时间")
+    @ExcelDBFieldDesc(name = "考试时间")
     private String examTime;
 
     @ApiModelProperty(value = "试卷编号")
+    @ExcelDBFieldDesc(name = "试卷编号",length = 15)
     private String paperNumber;
 
     @ApiModelProperty(value = "备选字段集合")

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamDetailCourse.java

@@ -45,6 +45,17 @@ public class ExamDetailCourse extends BaseEntity implements Serializable {
     @TableField("card_pages_a3")
     private Integer cardPagesA3;
 
+    @TableField("attachment_path")
+    private String attachmentPath;
+
+    public String getAttachmentPath() {
+        return attachmentPath;
+    }
+
+    public void setAttachmentPath(String attachmentPath) {
+        this.attachmentPath = attachmentPath;
+    }
+
     public Long getSchoolId() {
         return schoolId;
     }

+ 0 - 57
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ExaminationDBFieldsEnum.java

@@ -1,57 +0,0 @@
-package com.qmth.distributed.print.business.enums;
-
-import com.qmth.distributed.print.business.enums.result.EnumResult;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Description: 考务数据导入-数据库所必须字段枚举
- * @Author: CaoZixuan
- * @Date: 2021-04-20
- */
-public enum ExaminationDBFieldsEnum {
-    STUDENT_CODE("学号", "studentCode", 10),
-    STUDENT_NAME("姓名", "studentName", 15),
-    COURSE_CODE("课程代码", "courseCode", 10),
-    COURSE_NAME("课程名称", "courseName", 20),
-    EXAM_PLACE("考点", "examPlace", 10),
-    EXAM_ROOM("考场", "examRoom", 10),
-    EXAM_DATE("考试日期", "examDate", 0),
-    EXAM_TIME("考试时间", "examTime", 0),
-    PAPER_NUMBER("试卷编号", "paperNumber", 15);
-    private final String desc;
-    private final String code;
-    private final int length;
-
-    ExaminationDBFieldsEnum(String desc, String code, int length) {
-        this.desc = desc;
-        this.code = code;
-        this.length = length;
-    }
-
-    public String getDesc() {
-        return desc;
-    }
-
-    public String getCode() {
-        return code;
-    }
-
-    public int getLength() {
-        return length;
-    }
-
-    public static List<EnumResult> listTypes() {
-        List<EnumResult> list = new ArrayList<>();
-        for (ExaminationDBFieldsEnum value : ExaminationDBFieldsEnum.values()) {
-            EnumResult result = new EnumResult();
-            result.setName(value.name());
-            result.setOrdinal(value.ordinal());
-            result.setCode(value.getCode());
-            result.setDesc(value.getDesc());
-            list.add(result);
-        }
-        return list;
-    }
-}

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/RequiredFieldsEnum.java

@@ -6,7 +6,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * 考务必选字段
+ * 考务必选字段(此枚举类中的字段必须在ExaminationImportDto类中有对应的属性code作为属性名,同时该属性必须加@ExcelDBFieldDesc注解,且name必须和desc对应)
  * @Date: 2021/3/29.
  */
 public enum RequiredFieldsEnum {

+ 8 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.itextpdf.text.DocumentException;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.entity.BasicAttachment;
+import com.qmth.distributed.print.business.entity.ExamDetailCourse;
+import com.qmth.distributed.print.business.enums.ClassifyEnum;
 import com.qmth.distributed.print.business.enums.UploadFileEnum;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -56,8 +58,9 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
 
     /**
      * 保存html文件
-     * @param rootPath 文件路径
-     * @param fileName 文件名
+     *
+     * @param rootPath    文件路径
+     * @param fileName    文件名
      * @param htmlContent 文件内容
      * @return
      */
@@ -76,6 +79,8 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
     /**
      * 保存附件
      *
+     * @param classifyEnum
+     * @param examDetailCourse
      * @param basicAttachment
      * @param pdfList
      * @param printCount
@@ -83,7 +88,7 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException;
+    public BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetailCourse examDetailCourse, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException;
 
     /**
      * 删除附件

+ 41 - 19
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -9,7 +10,9 @@ import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.config.DictionaryConfig;
 import com.qmth.distributed.print.business.entity.BasicAttachment;
+import com.qmth.distributed.print.business.entity.ExamDetailCourse;
 import com.qmth.distributed.print.business.entity.SysUser;
+import com.qmth.distributed.print.business.enums.ClassifyEnum;
 import com.qmth.distributed.print.business.enums.PageSizeEnum;
 import com.qmth.distributed.print.business.enums.UploadFileEnum;
 import com.qmth.distributed.print.business.mapper.BasicAttachmentMapper;
@@ -238,6 +241,8 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
     /**
      * 保存附件
      *
+     * @param classifyEnum
+     * @param examDetailCourse
      * @param basicAttachment
      * @param pdfList
      * @param printCount
@@ -247,7 +252,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
+    public BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetailCourse examDetailCourse, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
@@ -264,36 +269,53 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                 url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
                 htmlFile = ossUtil.ossDownload(filePath, url);
             }
-            String pdfDirName = filePath.replaceAll(SystemConstant.HTML_PREFIX, SystemConstant.PDF_PREFIX).replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
+            LocalDateTime nowTime = LocalDateTime.now();
+            StringJoiner pdfStringJoiner = new StringJoiner("");
+            if (!oss) {
+                pdfStringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
+            }
+            pdfStringJoiner.add(UploadFileEnum.PDF.getTitle()).add(File.separator);
+            pdfStringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
+                    .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
+                    .add(String.format("%02d", nowTime.getDayOfMonth()));
+            pdfStringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.PDF_PREFIX);
+
+            String pdfDirName = pdfStringJoiner.toString();
             String destUrl = SystemConstant.PDF_TEMP_FILES_DIR + File.separator + pdfDirName;
-            HtmlToPdfUtil.convert(htmlFile.getPath(), destUrl, PageSizeEnum.A4);
             File pdfFile = new File(destUrl);
+            if (!pdfFile.exists()) {
+                pdfFile.getParentFile().mkdirs();
+                pdfFile.createNewFile();
+            }
+
+            HtmlToPdfUtil.convert(htmlFile.getPath(), destUrl, PageSizeEnum.A4);
             String fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
             PdfDto pdfDto = null;
             if (oss) {//上传至oss
                 pdfDto = PdfUtil.addPdfPage(pdfFile);
                 ossUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
-                jsonObject.put(SystemConstant.PDF_PATH, pdfDirName);
-                if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.FTL_PREFIX)) {
-                    jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
-                            UploadFileEnum.FILE,
-                            UploadFileEnum.HTML,
-                            UploadFileEnum.PDF
-                    });
-                } else {
-                    jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
-                            UploadFileEnum.FILE,
-                            UploadFileEnum.PDF
-                    });
-                    htmlFile.delete();
-                }
+                htmlFile.delete();
             }
-            basicAttachment.setPath(jsonObject.toJSONString());
+            JSONObject attachmentPath = JSONObject.parseObject(examDetailCourse.getAttachmentPath());
+            attachmentPath = Objects.isNull(attachmentPath) ? new JSONObject() : attachmentPath;
+            JSONArray jsonArray = (JSONArray) attachmentPath.get(SystemConstant.PATH);
+            jsonArray = Objects.isNull(jsonArray) ? new JSONArray() : jsonArray;
+            JSONObject object = new JSONObject();
+            object.put("printType", classifyEnum.name());
+            object.put(SystemConstant.HTML_PATH, filePath);
+            object.put(SystemConstant.PDF_PATH, pdfDirName);
+            object.put(SystemConstant.TYPE, SystemConstant.OSS);
+            object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
+                    UploadFileEnum.HTML,
+                    UploadFileEnum.PDF
+            });
+            jsonArray.add(object);
+            attachmentPath.put(SystemConstant.PATH, jsonArray);
+            examDetailCourse.setAttachmentPath(attachmentPath.toJSONString());
             basicAttachment.setPages(pdfDto.getActualPageCount());
             for (int i = 0; i < printCount; i++) {
                 pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), sequence));
             }
-            this.updateById(basicAttachment);
         } catch (Exception e) {
             log.error("请求出错", e);
             if (e instanceof ApiException) {

+ 0 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java

@@ -7,7 +7,6 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.qmth.distributed.print.business.base.BaseEntity;
 import com.qmth.distributed.print.business.bean.dto.*;
 import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.bean.result.ExaminationDetailResult;
@@ -15,7 +14,6 @@ import com.qmth.distributed.print.business.bean.result.ExaminationResult;
 import com.qmth.distributed.print.business.bean.result.SummarizedDataResult;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
-import com.qmth.distributed.print.business.enums.ExaminationDBFieldsEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.enums.TaskTypeEnum;
 import com.qmth.distributed.print.business.mapper.ExamDetailMapper;
@@ -25,7 +23,6 @@ import com.qmth.distributed.print.business.util.ConvertUtil;
 import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
-import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.HorizontalAlignment;
 import org.apache.poi.xssf.usermodel.*;
 import org.slf4j.Logger;

+ 1 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -578,6 +578,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             taskReviewLog.setOperateId(sysUser.getId());
             taskReviewLog.setOperateTime(System.currentTimeMillis());
             taskReviewLog.setExamTaskId(examTaskId);
+            taskReviewLog.setId(SystemConstant.getDbUuid());
             examTaskReviewLogService.save(taskReviewLog);
 
             // 更新命题任务状态

+ 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);

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

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.boot.api.exception.ApiException;
+import com.qmth.distributed.print.business.annotation.ExcelDBFieldDesc;
 import com.qmth.distributed.print.business.bean.dto.ExaminationExportDto;
 import com.qmth.distributed.print.business.bean.dto.ExaminationImportDto;
 import com.qmth.distributed.print.business.bean.dto.FieldsDto;
@@ -46,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;
 
 /**
@@ -113,6 +115,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     BasicExamRuleService basicExamRuleService;
 
+    private static volatile ConcurrentHashMap<Integer, String> paperTypeMap = null;
+
     /**
      * 创建pdf逻辑
      *
@@ -164,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
@@ -182,20 +187,20 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     List<PdfDto> backupPaperPdfList = new ArrayList<>();//备份试卷
                     List<PdfDto> cardPdfList = new ArrayList<>();//备份题卡
 
-                    if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
-                        //获取普通印品
-                        JSONArray jsonArrayOrdinary = JSONArray.parseArray(examPrintPlan.getOrdinaryContent());
-                        for (int i = 0; i < jsonArrayOrdinary.size(); i++) {
-                            JSONObject jsonObjectOrdinary = jsonArrayOrdinary.getJSONObject(i);
-                            if (Objects.nonNull(jsonObjectOrdinary.get("attachmentId"))) {
-                                Long attachmentId = Long.parseLong((String) jsonObjectOrdinary.get("attachmentId"));
-                                BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
-                                createPdfUtil.createCheckIn(basicAttachment, ordinaryPdfList, (Integer) jsonObjectOrdinary.get("backupCount"));
+                    for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
+                        if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
+                            //获取普通印品
+                            JSONArray jsonArrayOrdinary = JSONArray.parseArray(examPrintPlan.getOrdinaryContent());
+                            for (int i = 0; i < jsonArrayOrdinary.size(); i++) {
+                                JSONObject jsonObjectOrdinary = jsonArrayOrdinary.getJSONObject(i);
+                                if (Objects.nonNull(jsonObjectOrdinary.get("attachmentId"))) {
+                                    Long attachmentId = Long.parseLong((String) jsonObjectOrdinary.get("attachmentId"));
+                                    BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
+                                    createPdfUtil.createCheckIn(examDetailCourse, basicAttachment, ordinaryPdfList, (Integer) jsonObjectOrdinary.get("backupCount"));
+                                }
                             }
                         }
-                    }
 
-                    for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
                         List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
                         List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
                         List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
@@ -233,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);
 
@@ -352,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;
     }
 
@@ -383,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);
@@ -411,6 +416,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             String cellValue = String.valueOf(ExcelUtil.convert(head.getCell(i)));
             for (FieldsDto fieldsDto : fieldsDtoList) {
                 if (cellValue.equals(fieldsDto.getName())) {
+                    // 如果通用规则必填字段和excel表头匹配上了,则为该必选字段设置其在excel中的索引
                     fieldsDto.setIndex(i);
                 }
             }
@@ -431,6 +437,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             List<FieldsDto> secondaryFieldList = new ArrayList<>(); // 备选字段
 
             ExaminationImportDto examinationImportDto = new ExaminationImportDto();
+            Field[] examinationImportDtoFields = examinationImportDto.getClass().getDeclaredFields();
             for (FieldsDto fieldsDto : fieldsDtoList) {
                 boolean match = false;
                 String name = fieldsDto.getName();
@@ -447,18 +454,22 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     throw ExceptionResultEnum.ERROR.exception("excel中第[" + (r + 1) + "]行,第[" + (index + 1) + "]列,字段[" + name + "]必填");
                 }
 
-                for (ExaminationDBFieldsEnum value : ExaminationDBFieldsEnum.values()) {
-                    String dbName = value.getDesc();
-                    String dbCode = value.getCode();
-                    int dbLength = value.getLength();
+                for (Field examinationImportDtoField : examinationImportDtoFields) {
+                    ExcelDBFieldDesc excelDBFieldDesc = examinationImportDtoField.getAnnotation(ExcelDBFieldDesc.class);
+                    if (excelDBFieldDesc == null) {
+                        // 如果没有注解,说明该数据库必须字段不是从excel中获得的,直接跳过
+                        continue;
+                    }
+
+                    // 如果数据库字段中文名和必填字段中文名称对应,则通过反射为数据库必选字段赋值
+                    String dbName = excelDBFieldDesc.name();
+                    int dbLength = excelDBFieldDesc.length();
                     if (dbName.equals(name)) {
                         if (dbLength > 0) {
                             ConvertUtil.verifyLength(cellValue, dbLength, dbName);
                         }
-                        // 使用反射 -> 根据db枚举类的code字段为对应的dbDto类中的对应属性赋值(因此要求枚举必须被dto类包含)
-                        Field field = examinationImportDto.getClass().getDeclaredField(dbCode);
-                        field.setAccessible(true);
-                        field.set(examinationImportDto, cellValue);
+                        examinationImportDtoField.setAccessible(true);
+                        examinationImportDtoField.set(examinationImportDto, cellValue);
                         match = true;
                         break;
                     }
@@ -492,6 +503,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             examinationImportDto.setPrintPlanName(printPlanName);
             examinationImportDtoList.add(examinationImportDto);
         }
+
         System.out.println(JSON.toJSONString(examinationImportDtoList));
 
         // 校验课程代码和试卷编号在印刷计划下是1对1的关系
@@ -586,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)))));
@@ -654,21 +666,23 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
             // 处理试卷样品
             List<Map> paperInfo = JSONObject.parseArray(examTaskDetail.getPaperAttachmentIds(), Map.class);
+            if (Objects.isNull(paperInfo)){
+                throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
+            }
             System.out.println("paperInfo = " + JSON.toJSONString(paperInfo));
             Set<Long> attPaperIds = new HashSet<>();
             for (Map paperMap : paperInfo) {
-                if (Objects.isNull(paperMap.get("attachmentId"))) {
-                    throw ExceptionResultEnum.ERROR.exception("未找到附件id");
+                if (Objects.nonNull(paperMap.get("attachmentId")) && String.valueOf(paperMap.get("attachmentId")).length() > 0 && !String.valueOf(paperMap.get("attachmentId")).equals("null")) {
+                    Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
+                    attPaperIds.add(attachmentId);
                 }
-                Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
-                attPaperIds.add(attachmentId);
             }
-            List<BasicAttachment> paperAttachmentList = basicAttachmentService.listByIds(attPaperIds);
-            if (Objects.nonNull(paperAttachmentList)) {
+            if (attPaperIds.size() > 0) {
+                List<BasicAttachment> paperAttachmentList = basicAttachmentService.listByIds(attPaperIds);
                 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++;
                 }
             }
@@ -684,12 +698,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 Long attachmentId = Long.valueOf(String.valueOf(confirmMap.get("attachmentId")));
                 attConfirmIds.add(attachmentId);
             }
-            List<BasicAttachment> confirmAttachmentList = basicAttachmentService.listByIds(attConfirmIds);
-            if (Objects.nonNull(confirmAttachmentList)) {
+            if (attConfirmIds.size() > 0) {
+                List<BasicAttachment> confirmAttachmentList = basicAttachmentService.listByIds(attConfirmIds);
                 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++;
                 }
             }
@@ -720,8 +734,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);
-                count++;
+                ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath);
             } else {
                 List<ExamCardDetail> examCardDetailList = examCardDetailService.list(new QueryWrapper<ExamCardDetail>().lambda().eq(ExamCardDetail::getCardId, cardId));
                 if (examCardDetailList.size() != 1) {
@@ -736,8 +749,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     localFile.getParentFile().mkdirs();
                 }
                 FileCopyUtils.copy(bytes, localFile);
-                count++;
             }
+            count ++;
         }
         ZipUtil.zip(zipLocalRootPath, zipFile.getPath(), true);
         ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
@@ -751,4 +764,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         map.put("count", count);
         return map;
     }
+
+    public static ConcurrentHashMap<Integer, String> getPaperTypeMap() {
+        return paperTypeMap;
+    }
 }

+ 57 - 29
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -9,13 +9,11 @@ import com.itextpdf.text.DocumentException;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.entity.*;
-import com.qmth.distributed.print.business.enums.DrawRuleEnum;
-import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
-import com.qmth.distributed.print.business.enums.PageSizeEnum;
-import com.qmth.distributed.print.business.enums.PrintMethodEnum;
+import com.qmth.distributed.print.business.enums.*;
 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 +26,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;
 
 /**
@@ -59,11 +58,12 @@ public class CreatePdfUtil {
     /**
      * 创建登记表
      *
+     * @param examDetailCourse
      * @param basicAttachment
      * @param ordinaryPdfList
      * @param printCount
      */
-    public void createCheckIn(BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
+    public void createCheckIn(ExamDetailCourse examDetailCourse, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
         if (Objects.isNull(basicAttachment)) {
             throw ExceptionResultEnum.ERROR.exception("找不到附件");
         }
@@ -78,7 +78,7 @@ public class CreatePdfUtil {
                 ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount()));
             }
         } else {
-            basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount, 0);
+            basicAttachmentService.saveAttachmentPdf(ClassifyEnum.CHECK_IN, examDetailCourse, basicAttachment, ordinaryPdfList, printCount, 0);
         }
     }
 
@@ -154,6 +154,8 @@ public class CreatePdfUtil {
         htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
         htmlMap.computeIfAbsent("printCount", v -> printCount);
         htmlMap.computeIfAbsent("sequence", v -> 1);
+        htmlMap.computeIfAbsent("examDetailCourse", v -> examDetailCourse);
+        htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.PACKAGE);
         freemarkerUtil.createPaperPackage(htmlMap);
     }
 
@@ -250,6 +252,8 @@ public class CreatePdfUtil {
         htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
         htmlMap.computeIfAbsent("printCount", v -> printCount);
         htmlMap.computeIfAbsent("sequence", v -> 2);
+        htmlMap.computeIfAbsent("examDetailCourse", v -> examDetailCourse);
+        htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.SIGN);
         freemarkerUtil.createSignBook(htmlMap);
     }
 
@@ -319,9 +323,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;
     }
 
     /**
@@ -329,34 +336,50 @@ 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();
+        String key = examDetail.getSchoolId()
+                + Math.abs(examDetail.getExamStartTime() + examDetail.getExamEndTime())
+                + examDetail.getExamPlace()
+                + examDetailCourse.getCourseCode()
+                + 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;
     }
 
     /**
@@ -373,11 +396,13 @@ 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> mergePdfA4List = new ArrayList<>();
         int pageA3Count = 0;
         int pageA4Count = 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();
+                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]);
@@ -401,6 +426,9 @@ public class CreatePdfUtil {
         for (PdfDto pdfDto : mergePdfList) {
             new File(pdfDto.getPath()).delete();
         }
+        for (PdfDto pdfDto : mergePdfA4List) {
+            new File(pdfDto.getPath()).delete();
+        }
         return basicAttachment;
     }
 

+ 5 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.config.DictionaryConfig;
 import com.qmth.distributed.print.business.entity.BasicAttachment;
+import com.qmth.distributed.print.business.entity.ExamDetailCourse;
+import com.qmth.distributed.print.business.enums.ClassifyEnum;
 import com.qmth.distributed.print.business.enums.UploadFileEnum;
 import com.qmth.distributed.print.business.service.BasicAttachmentService;
 import com.qmth.distributed.print.common.contant.SystemConstant;
@@ -79,6 +81,8 @@ public class FreemarkerUtil {
         Writer out = null;
         try {
             BasicAttachment basicAttachment = (BasicAttachment) dataMap.get("basicAttachment");
+            ExamDetailCourse examDetailCourse = (ExamDetailCourse) dataMap.get("examDetailCourse");
+            ClassifyEnum classifyEnum = (ClassifyEnum) dataMap.get("printType");
             JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
             String path = (String) jsonObject.get(SystemConstant.PATH);
             String ftlPath = path.substring(0, path.lastIndexOf("/"));
@@ -116,7 +120,7 @@ public class FreemarkerUtil {
                         UploadFileEnum.HTML
                 });
                 basicAttachment.setPath(jsonObject.toJSONString());
-                basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"), (Integer) dataMap.get("sequence"));
+                basicAttachmentService.saveAttachmentPdf(classifyEnum, examDetailCourse, basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"), (Integer) dataMap.get("sequence"));
             }
             htmlFile.delete();
         } catch (Exception e) {

+ 1 - 0
distributed-print-business/src/main/resources/db/init-table.sql

@@ -278,6 +278,7 @@ CREATE TABLE `exam_detail`  (
   `create_time` bigint(20) NULL DEFAULT NULL,
   `update_id` bigint(20) NULL DEFAULT NULL,
   `update_time` bigint(20) NULL DEFAULT NULL,
+  `attachment_path` mediumtext COMMENT '附件路径',
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '考务数据' ROW_FORMAT = Dynamic;
 

+ 0 - 3
distributed-print/src/main/java/com/qmth/distributed/print/api/EnumsController.java

@@ -101,9 +101,6 @@ public class EnumsController {
         } else if (type.equals(EnumType.EXAM_DETAIL_STATUS_ENUM.name())){
             // 考场状态
             list = ExamDetailStatusEnum.listTypes();
-        } else if (type.equals(EnumType.EXAMINATION_DB_FIELDS_ENUM.name())){
-            // 考务数据导入-数据库所必须字段枚举
-            list = ExaminationDBFieldsEnum.listTypes();
         }
         return ResultUtil.ok(list);
     }