wangliang 4 năm trước cách đây
mục cha
commit
b5b595d8c9

+ 18 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PdfDto.java

@@ -21,6 +21,9 @@ public class PdfDto {
     @ApiModelProperty(name = "页面大小")
     PageSizeEnum pageSize;
 
+    @ApiModelProperty(name = "序号")
+    Integer sequence = 0;
+
     public PdfDto() {
 
     }
@@ -36,6 +39,21 @@ public class PdfDto {
         this.pageCount = pageCount;
     }
 
+    public PdfDto(String path, PageSizeEnum pageSize, Integer pageCount, Integer sequence) {
+        this.path = path;
+        this.pageSize = pageSize;
+        this.pageCount = pageCount;
+        this.sequence = sequence;
+    }
+
+    public Integer getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(Integer sequence) {
+        this.sequence = sequence;
+    }
+
     public String getPath() {
         return path;
     }

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java

@@ -69,10 +69,11 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      * @param basicAttachment
      * @param pdfList
      * @param printCount
+     * @param sequence
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount) throws IOException, DocumentException;
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException;
 
     /**
      * 删除附件

+ 3 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -211,12 +211,13 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
      * @param basicAttachment
      * @param pdfList
      * @param printCount
+     * @param sequence
      * @return
      * @throws IOException
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount) throws IOException, DocumentException {
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
@@ -259,7 +260,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             }
             basicAttachment.setPath(jsonObject.toJSONString());
             for (int i = 0; i < printCount; i++) {
-                pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pageCount));
+                pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pageCount, sequence));
             }
             this.updateById(basicAttachment);
         } catch (Exception e) {

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

@@ -24,6 +24,7 @@ import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.FileUtil;
 import com.qmth.distributed.print.common.util.HexUtils;
+import com.qmth.distributed.print.common.util.JacksonUtil;
 import com.qmth.distributed.print.common.util.ResultUtil;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -263,6 +264,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                     }
                                 }
 
+                                Collections.sort(variablePdfList, new Comparator<PdfDto>() {
+                                    @Override
+                                    public int compare(PdfDto o1, PdfDto o2) {
+                                        return o1.getSequence() > o2.getSequence() ? 1 : -1;
+                                    }
+                                });
+
                                 for (ExamStudent t : examStudentList) {
                                     basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentTempPdfList));
                                 }
@@ -472,7 +480,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 }
             }
             // 校验试卷编号
-            examTaskService.verifyCourseCodeByPaperNumber(schoolId,paperNumber,courseCode);
+            examTaskService.verifyCourseCodeByPaperNumber(schoolId, paperNumber, courseCode);
 
             // 校验课程信息
             basicCourseService.verifyCourseInfo(schoolId, courseCode, courseName, userId);
@@ -536,7 +544,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             // 按照考场检验命题任务是否全部完成,完成生成pdf
             SysUser user = (SysUser) map.get(SystemConstant.USER);
             for (Long examDetailId : examDetailIdList) {
-                examTaskService.checkDataByExamination(examDetailId,user);
+                examTaskService.checkDataByExamination(examDetailId, user);
             }
 
 //            List<Map<String, Object>> checkList = dataList.stream().flatMap(e -> {

+ 22 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -82,7 +82,7 @@ public class CreatePdfUtil {
                 ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pageCount));
             }
         } else {
-            basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount);
+            basicAttachmentService.saveAttachmentPdf(basicAttachment, ordinaryPdfList, printCount, 0);
         }
     }
 
@@ -152,7 +152,6 @@ public class CreatePdfUtil {
                 return 0;
             }
         }).get().getSiteNumber();
-        minSite = Objects.isNull(minSite) ? "" : minSite;
 
         String maxSite = examStudentList.stream().max((a, b) -> {
             if (Objects.nonNull(a.getSiteNumber()) && Objects.nonNull(a.getSiteNumber())) {
@@ -161,17 +160,17 @@ public class CreatePdfUtil {
                 return 0;
             }
         }).get().getSiteNumber();
-        maxSite = Objects.isNull(maxSite) ? "" : maxSite;
 
         htmlMap.put("minSite", minSite);
         htmlMap.put("maxSite", maxSite);
         htmlMap.put("studentCount", examStudentList.size());
 
-        htmlMap.put("tag", tag ? "订" : "");
+        htmlMap.put("tag", tag ? "订" : null);
 
         htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
         htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
         htmlMap.computeIfAbsent("printCount", v -> printCount);
+        htmlMap.computeIfAbsent("sequence", v -> 1);
         freemarkerUtil.createPaperPackage(htmlMap);
     }
 
@@ -244,11 +243,13 @@ public class CreatePdfUtil {
                 for (int j = 0; j < htmlTableCount; j++) {
                     ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
                     examStudentDto.setIndex(j + 1);
+                    examStudentDto.setExtendFields(getClassName(examStudentDto.getExtendFields()));
                     examStudentList1.add(examStudentDto);
                 }
                 for (int j = htmlTableCount; j < subStudents.size(); j++) {
                     ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
                     examStudentDto.setIndex(j + 1);
+                    examStudentDto.setExtendFields(getClassName(examStudentDto.getExtendFields()));
                     examStudentList2.add(examStudentDto);
                 }
                 if (examStudentList1.size() > examStudentList2.size()) {
@@ -265,6 +266,7 @@ public class CreatePdfUtil {
         htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
         htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
         htmlMap.computeIfAbsent("printCount", v -> printCount);
+        htmlMap.computeIfAbsent("sequence", v -> 2);
         freemarkerUtil.createSignBook(htmlMap);
     }
 
@@ -513,4 +515,20 @@ public class CreatePdfUtil {
         jsonArray.add(object);
         return cardAttachment;
     }
+
+    /**
+     * 获取班级名称
+     *
+     * @param extendCloumn
+     * @return
+     */
+    private String getClassName(String extendCloumn) {
+        List<Map> mapList = JSONObject.parseArray(extendCloumn, Map.class);
+        for (Map map : mapList) {
+            if (Objects.equals("className", map.get("code").toString())) {
+                return map.get("value").toString();
+            }
+        }
+        return null;
+    }
 }

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

@@ -116,9 +116,8 @@ public class FreemarkerUtil {
                         UploadFileEnum.HTML
                 });
                 basicAttachment.setPath(jsonObject.toJSONString());
-                basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"));
+                basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"), (Integer) dataMap.get("sequence"));
             }
-            log.info("{}文件创建成功", htmlFile.toString());
             htmlFile.delete();
         } catch (Exception e) {
             log.error("请求出错", e);