Browse Source

生成pdf加入混排

wangliang 4 years ago
parent
commit
4ead5c0ef2

+ 62 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExamStudentCourseDto.java

@@ -0,0 +1,62 @@
+package com.qmth.distributed.print.business.bean.dto;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.distributed.print.business.entity.ExamStudent;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 考生科目 dto
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/5/14
+ */
+public class ExamStudentCourseDto extends ExamStudent {
+
+    @ApiModelProperty(value = "科目编码")
+    private String courseCode;
+
+    @ApiModelProperty(value = "科目名称")
+    private String courseName;
+
+    @ApiModelProperty(value = "A3数量")
+    private Integer paperPageA3;
+
+    @ApiModelProperty("试卷编号")
+    private String paperNumber;
+
+    public String getPaperNumber() {
+        return paperNumber;
+    }
+
+    public void setPaperNumber(String paperNumber) {
+        this.paperNumber = paperNumber;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public Integer getPaperPageA3() {
+        return paperPageA3;
+    }
+
+    public void setPaperPageA3(Integer paperPageA3) {
+        this.paperPageA3 = paperPageA3;
+    }
+}

+ 12 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamStudentMapper.java

@@ -1,8 +1,11 @@
 package com.qmth.distributed.print.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
 import com.qmth.distributed.print.business.entity.ExamStudent;
+import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -16,4 +19,13 @@ import java.util.Map;
 public interface ExamStudentMapper extends BaseMapper<ExamStudent> {
 
     Map<String, Object> getStudentDetail(Long id);
+
+    /**
+     * 根据科目查询考生
+     *
+     * @param schoolId
+     * @param examDetailCourseIds
+     * @return
+     */
+    List<ExamStudentCourseDto> queryBySchoolIdAndExamDetailCourseIds(@Param("schoolId") Long schoolId, @Param("examDetailCourseIds") List<Long> examDetailCourseIds);
 }

+ 10 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamStudentService.java

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
 import com.qmth.distributed.print.business.entity.ExamDetailCourse;
 import com.qmth.distributed.print.business.entity.ExamStudent;
 
@@ -22,4 +23,13 @@ public interface ExamStudentService extends IService<ExamStudent> {
     List<String> listByExamDetailCourseId(String examDetailCourseId);
 
     Map<String, Object> getStudentDetail(Long id);
+
+    /**
+     * 根据科目查询考生
+     *
+     * @param schoolId
+     * @param examDetailCourseIds
+     * @return
+     */
+    List<ExamStudentCourseDto> queryBySchoolIdAndExamDetailCourseIds(Long schoolId, List<Long> examDetailCourseIds);
 }

+ 20 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamStudentServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
 import com.qmth.distributed.print.business.entity.ExamDetailCourse;
 import com.qmth.distributed.print.business.entity.ExamStudent;
 import com.qmth.distributed.print.business.mapper.ExamStudentMapper;
@@ -11,6 +12,7 @@ import com.qmth.distributed.print.business.service.ExamStudentService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -27,6 +29,9 @@ import java.util.stream.Collectors;
 @Service
 public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamStudent> implements ExamStudentService {
 
+    @Resource
+    ExamStudentMapper examStudentMapper;
+
     @Override
     public void updatePaperType(List<Long> examDetailCourseIds, String relatePaperType) {
         UpdateWrapper<ExamStudent> updateWrapper = new UpdateWrapper<>();
@@ -39,8 +44,8 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
         QueryWrapper<ExamStudent> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(ExamStudent::getExamDetailCourseId, examDetailCourseId);
         List<ExamStudent> examStudents = this.list(queryWrapper);
-        if(!examStudents.isEmpty()){
-            List<String> strings = examStudents.stream().filter(m-> StringUtils.isNotBlank(m.getPaperType())).map(m->m.getPaperType()).distinct().collect(Collectors.toList());
+        if (!examStudents.isEmpty()) {
+            List<String> strings = examStudents.stream().filter(m -> StringUtils.isNotBlank(m.getPaperType())).map(m -> m.getPaperType()).distinct().collect(Collectors.toList());
             return strings;
         }
         return null;
@@ -50,10 +55,22 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamS
     public Map<String, Object> getStudentDetail(Long id) {
         Map<String, Object> map = this.baseMapper.getStudentDetail(id);
         Object extendFields = map.get("extendFields");
-        if(Objects.nonNull(extendFields)){
+        if (Objects.nonNull(extendFields)) {
             List<Map> list = JSONObject.parseArray(extendFields.toString(), Map.class);
             map.put("extendFields", list);
         }
         return map;
     }
+
+    /**
+     * 根据科目查询考生
+     *
+     * @param schoolId
+     * @param examDetailCourseIds
+     * @return
+     */
+    @Override
+    public List<ExamStudentCourseDto> queryBySchoolIdAndExamDetailCourseIds(Long schoolId, List<Long> examDetailCourseIds) {
+        return examStudentMapper.queryBySchoolIdAndExamDetailCourseIds(schoolId, examDetailCourseIds);
+    }
 }

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

@@ -171,8 +171,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
      * @param paperTypeParam
      * @param basicAttachmentList
      * @param attachmentIds
-     * @param ftlList
-     * @param basicSchool
      * @param list
      * @return
      * @throws IOException
@@ -186,25 +184,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                                     String paperTypeParam,
                                                     List<BasicAttachment> basicAttachmentList,
                                                     Set<Long> attachmentIds,
-                                                    Set<File> ftlList,
-                                                    BasicSchool basicSchool,
                                                     List<PdfDto>... list
     ) throws IOException, DocumentException {
         if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
             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")) && !Objects.equals("", jsonObjectOrdinary.get("attachmentId"))) {
-                            Long attachmentId = Long.parseLong((String) jsonObjectOrdinary.get("attachmentId"));
-                            BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
-                            createPdfUtil.createCheckIn(examDetail, basicAttachment, list[0], (Integer) jsonObjectOrdinary.get("backupCount"));
-                        }
-                    }
-                }
-
                 List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
                 List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
                 List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
@@ -262,7 +245,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     //获取试卷pdf
                     PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, examPrintPlan.getBackupCount(), backupPaperTempPdfList);
                     examDetailCourse.setPaperPagesA3(Objects.nonNull(pdfDto) ? pdfDto.getPageCount() : examDetailCourse.getPaperPagesA3());
-                    list[1].addAll(backupPaperTempPdfList);
+                    list[0].addAll(backupPaperTempPdfList);
 
                     basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
                     for (ExamCardDetail examCardDetail : examCardDetailList) {
@@ -277,7 +260,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             examDetailCourse.setCardPagesA3(basicAttachment.getPages());
                             basicAttachmentList.add(basicAttachment);
                         }
-                        list[2].addAll(cardPdfTempList);
+                        list[1].addAll(cardPdfTempList);
 
                         //查询考生
                         QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
@@ -285,42 +268,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                 .eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
                         List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
 
-                        if (Objects.nonNull(examPrintPlan.getVariableContent())) {
-                            //获取变量印品
-                            JSONArray jsonArrayVariable = JSONArray.parseArray(examPrintPlan.getVariableContent());
-                            for (int i = 0; i < jsonArrayVariable.size(); i++) {
-                                JSONObject jsonObjectVariable = jsonArrayVariable.getJSONObject(i);
-                                String type = (String) jsonObjectVariable.get("type");
-                                if (Objects.nonNull(jsonObjectVariable.get("attachmentId")) && !Objects.equals("", jsonObjectVariable.get("attachmentId"))) {
-                                    Long attachmentId = Long.parseLong((String) jsonObjectVariable.get("attachmentId"));
-                                    BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
-                                    ftlList.add(commonService.getFile(basicAttachment.getPath(), false));
-                                    if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
-                                        createPdfUtil.createSignBook(basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, list[3], (Integer) jsonObjectVariable.get("backupCount"));
-                                    } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAGE")) {//卷袋贴
-                                        if (Objects.nonNull(pdfDto)) {
-                                            createPdfUtil.createPaperPackage(pdfDto.isTag(), basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, list[3], (Integer) jsonObjectVariable.get("backupCount"));
-                                        }
-                                    }
-                                }
-                            }
-                        }
-
-                        Collections.sort(list[3], new Comparator<PdfDto>() {
-                            @Override
-                            public int compare(PdfDto o1, PdfDto o2) {
-                                return o1.getSequence() > o2.getSequence() ? 1 : -1;
-                            }
-                        });
-
                         for (ExamStudent t : examStudentList) {
                             if (Objects.nonNull(pdfDto)) {
                                 createPdfUtil.getExamStudentPaperPdf(paperPdfDto, paperPdfTempList);
                             }
                             basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, examDetail, examDetailCourse, sysUser.getId(), examStudentTempPdfList));
                         }
-                        list[4].addAll(paperPdfTempList);
-                        list[5].addAll(examStudentTempPdfList);
+                        list[2].addAll(paperPdfTempList);
+                        list[3].addAll(examStudentTempPdfList);
                         examStudentService.saveOrUpdateBatch(examStudentList);
                         jsonObject.put("card", jsonArray);
                         examCardDetail.setAttachmentId(jsonObject.toJSONString());
@@ -334,6 +289,64 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return basicAttachmentList;
     }
 
+    /**
+     * 创建A4文件
+     *
+     * @param examPrintPlan
+     * @param examDetail
+     * @param basicSchool
+     * @param ftlList
+     * @param examDetailCourseListIds
+     * @param list
+     * @throws IOException
+     * @throws DocumentException
+     */
+    @Transactional
+    public void createA4File(ExamPrintPlan examPrintPlan, ExamDetail examDetail, BasicSchool basicSchool, Set<File> ftlList, List<Long> examDetailCourseListIds, List<PdfDto>... list) throws IOException, DocumentException {
+        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")) && !Objects.equals("", jsonObjectOrdinary.get("attachmentId"))) {
+                    Long attachmentId = Long.parseLong((String) jsonObjectOrdinary.get("attachmentId"));
+                    BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
+                    createPdfUtil.createCheckIn(examDetail, basicAttachment, list[0], (Integer) jsonObjectOrdinary.get("backupCount"));
+                }
+            }
+        }
+
+        if (Objects.nonNull(examPrintPlan.getVariableContent())) {
+            List<ExamStudentCourseDto> examStudentCourseDtoList = examStudentService.queryBySchoolIdAndExamDetailCourseIds(basicSchool.getId(), examDetailCourseListIds);
+            int count = (int) examStudentCourseDtoList.stream().filter(s -> s.getPaperPageA3() > 2).count();
+            boolean tag = count > 0 ? true : false;
+
+            //获取变量印品
+            JSONArray jsonArrayVariable = JSONArray.parseArray(examPrintPlan.getVariableContent());
+            for (int i = 0; i < jsonArrayVariable.size(); i++) {
+                JSONObject jsonObjectVariable = jsonArrayVariable.getJSONObject(i);
+                String type = (String) jsonObjectVariable.get("type");
+                if (Objects.nonNull(jsonObjectVariable.get("attachmentId")) && !Objects.equals("", jsonObjectVariable.get("attachmentId"))) {
+                    Long attachmentId = Long.parseLong((String) jsonObjectVariable.get("attachmentId"));
+                    BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
+                    ftlList.add(commonService.getFile(basicAttachment.getPath(), false));
+                    if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
+                        createPdfUtil.createSignBook(basicAttachment, basicSchool.getName(), examDetail, examStudentCourseDtoList, list[1], (Integer) jsonObjectVariable.get("backupCount"));
+                    } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAGE")) {//卷袋贴
+                        createPdfUtil.createPaperPackage(tag, basicAttachment, basicSchool.getName(), examDetail, examStudentCourseDtoList, list[1], (Integer) jsonObjectVariable.get("backupCount"));
+                    }
+                }
+            }
+        }
+
+        Collections.sort(list[1], new Comparator<PdfDto>() {
+            @Override
+            public int compare(PdfDto o1, PdfDto o2) {
+                return o1.getSequence() > o2.getSequence() ? 1 : -1;
+            }
+        });
+    }
+
     /**
      * 创建pdf逻辑
      *
@@ -390,6 +403,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
                 }
                 List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
+                List<Long> examDetailCourseListIds = examDetailCourseList.stream().map(s -> s.getId()).collect(Collectors.toList());
+
                 List<PdfDto> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
                 List<PdfDto> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
                 List<PdfDto> paperPdfList = new ArrayList<>();//所有试卷
@@ -405,16 +420,21 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         paperTypeParam,
                         basicAttachmentList,
                         attachmentIds,
-                        ftlList,
-                        basicSchool,
-                        ordinaryPdfList,
                         backupPaperPdfList,
                         cardPdfList,
-                        variablePdfList,
                         paperPdfList,
                         examStudentPdfList);
+
+                createA4File(examPrintPlan, examDetail, basicSchool, ftlList, examDetailCourseListIds, ordinaryPdfList, variablePdfList);
+
                 //合并pdf
-                basicAttachmentList.add(createPdfUtil.mergePdf(basicExamRule, tbTask, examDetail, sysUser.getId(), variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
+                String dirNameA3 = createPdfUtil.mergeA3Pdf(paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList);
+                String dirNameA4 = createPdfUtil.mergeA4Pdf(variablePdfList, ordinaryPdfList);
+
+                List<PdfDto> mergePdfDeleteList = new ArrayList<>();
+                mergePdfDeleteList.addAll(examStudentPdfList);
+                mergePdfDeleteList.addAll(cardPdfList);
+                basicAttachmentList.add(createPdfUtil.mergePdfSaveDb(dirNameA4, dirNameA3, tbTask, sysUser.getId(), examDetail, basicExamRule, mergePdfDeleteList));
             }
             updateExamPrintPlan(basicExamRule, examPrintPlan);
             map.computeIfAbsent("size", v -> examDetailList.size());

+ 43 - 39
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.gson.Gson;
 import com.itextpdf.text.DocumentException;
+import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
 import com.qmth.distributed.print.business.bean.dto.PaperPdfDto;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
@@ -92,29 +93,32 @@ public class CreatePdfUtil {
      * @param tag
      * @param basicAttachment
      * @param schoolName
-     * @param examDetailCourse
      * @param examStudentList
      * @param variablePdfList
      * @param printCount
      * @throws IOException
      */
-    public void createPaperPackage(boolean tag, BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
+    public void createPaperPackage(boolean tag, BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
         if (Objects.isNull(basicAttachment)) {
             throw ExceptionResultEnum.ERROR.exception("找不到附件");
         }
         Map<String, Object> htmlMap = new HashMap<>();
-        htmlMap.put("examDetailCourseId", examDetailCourse.getId());
+        if (Objects.nonNull(examStudentList) && examStudentList.size() > 0) {
+            htmlMap.put("examDetailCourseId", examStudentList.get(0).getExamDetailCourseId());
+            htmlMap.put("courseName", examStudentList.get(0).getCourseName());
+            htmlMap.put("courseCode", examStudentList.get(0).getCourseCode());
+        } else {
+            htmlMap.put("examDetailCourseId", "");
+            htmlMap.put("courseName", "");
+            htmlMap.put("courseCode", "");
+        }
         htmlMap.put("schoolName", schoolName);
-        htmlMap.put("courseName", examDetailCourse.getCourseName());
-        htmlMap.put("courseCode", examDetailCourse.getCourseCode());
         htmlMap.put("examSite", examDetail.getExamPlace());
         htmlMap.put("examRoom", examDetail.getExamRoom());
         htmlMap.put("startTime", DateUtil.format(new Date(examDetail.getExamStartTime()), SystemConstant.DEFAULT_DATE_PATTERN));
         htmlMap.put("endTime", DateUtil.format(new Date(examDetail.getExamEndTime()), SystemConstant.DEFAULT_DATE_PATTERN));
         htmlMap.put("paperCode", examDetail.getPackageCode());
-        if (Objects.nonNull(examDetailCourse.getPaperNumber())) {
-            htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
-        }
+        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
 
         List<String> extendColumnList = examStudentList.stream().map(m -> m.getExtendFields()).distinct().collect(Collectors.toList());
         Set<String> startCollege = new HashSet();
@@ -175,20 +179,25 @@ public class CreatePdfUtil {
      * @param basicAttachment
      * @param schoolName
      * @param examDetail
-     * @param examDetailCourse
      * @param examStudentList
      * @param variablePdfList
      * @param printCount
      */
-    public void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
+    public void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount) throws IOException {
         if (Objects.isNull(basicAttachment)) {
             throw ExceptionResultEnum.ERROR.exception("找不到附件");
         }
         Map<String, Object> htmlMap = new HashMap<>();
-        htmlMap.put("examDetailCourseId", examDetailCourse.getId());
+        if (Objects.nonNull(examStudentList) && examStudentList.size() > 0) {
+            htmlMap.put("examDetailCourseId", examStudentList.get(0).getExamDetailCourseId());
+            htmlMap.put("courseName", examStudentList.get(0).getCourseName());
+            htmlMap.put("courseCode", examStudentList.get(0).getCourseCode());
+        } else {
+            htmlMap.put("examDetailCourseId", "");
+            htmlMap.put("courseName", "");
+            htmlMap.put("courseCode", "");
+        }
         htmlMap.put("schoolName", schoolName);
-        htmlMap.put("courseName", examDetailCourse.getCourseName());
-        htmlMap.put("courseCode", examDetailCourse.getCourseCode());
         htmlMap.put("examRoom", examDetail.getExamRoom());
 
         List<String> extendColumnList = examStudentList.stream().map(m -> m.getExtendFields()).distinct().collect(Collectors.toList());
@@ -207,9 +216,7 @@ public class CreatePdfUtil {
         htmlMap.put("startTime", DateUtil.format(new Date(examDetail.getExamStartTime()), SystemConstant.DEFAULT_DATE_PATTERN));
         htmlMap.put("endTime", DateUtil.format(new Date(examDetail.getExamEndTime()), SystemConstant.DEFAULT_DATE_PATTERN));
         htmlMap.put("paperCode", examDetail.getPackageCode());
-        if (Objects.nonNull(examDetailCourse.getPaperNumber())) {
-            htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
-        }
+        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
 
         int totalCount = examStudentList.size();
         if (totalCount > 0) {
@@ -219,7 +226,7 @@ public class CreatePdfUtil {
                 Map subMap = new HashMap();
                 subMap.put("index", i + 1);
                 int studentCount;
-                List<ExamStudent> subStudents;
+                List<ExamStudentCourseDto> subStudents;
                 if (pageCount == 1) {
                     studentCount = totalCount;
                     subStudents = examStudentList;
@@ -446,38 +453,35 @@ public class CreatePdfUtil {
     }
 
     /**
-     * 合并pdf
+     * 合并A3 pdf
      *
-     * @param tbTask
-     * @param examDetail
-     * @param userId
      * @param list
      * @return
      * @throws IOException
      */
-    public BasicAttachment mergePdf(BasicExamRule basicExamRule, TBTask tbTask, ExamDetail examDetail, Long userId, List<PdfDto>... list) throws IOException {
+    public String mergeA3Pdf(List<PdfDto>... list) throws IOException {
         List<PdfDto> mergePdfA3List = new ArrayList<>();
+        for (int i = 0; i < list.length; i++) {
+            mergePdfA3List.addAll(list[i]);
+        }
+        List<String> pathA3List = mergePdfA3List.stream().map(PdfDto::getPath).collect(Collectors.toList());
+        return PdfUtil.mergePdf(pathA3List.toArray(new String[mergePdfA3List.size()]), null);
+    }
+
+    /**
+     * 合并A4 pdf
+     *
+     * @param list
+     * @return
+     * @throws IOException
+     */
+    public String mergeA4Pdf(List<PdfDto>... list) throws IOException {
         List<PdfDto> mergePdfA4List = new ArrayList<>();
-        List<PdfDto> mergePdfDeleteList = new ArrayList<>();
-//        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.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.addAndGet(list[i].stream().mapToInt(PdfDto::getPageCount).sum());
-                mergePdfA3List.addAll(list[i]);
-            }
+            mergePdfA4List.addAll(list[i]);
         }
-//        mergePdfDeleteA3List.addAll(list[2]);
-        mergePdfDeleteList.addAll(list[3]);
-        mergePdfDeleteList.addAll(list[5]);
         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);
-        return mergePdfSaveDb(dirNameA4, dirNameA3, tbTask, userId, examDetail, basicExamRule, mergePdfDeleteList);
+        return PdfUtil.mergePdf(pathA4List.toArray(new String[mergePdfA4List.size()]), null);
     }
 
     /**

+ 40 - 0
distributed-print-business/src/main/resources/mapper/ExamStudentMapper.xml

@@ -46,4 +46,44 @@
             a.id = #{id}
     </select>
 
+    <select id="queryBySchoolIdAndExamDetailCourseIds" resultType="com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto">
+        select
+            es.id,
+            es.school_id as schoolId,
+            es.exam_detail_course_id as examDetailCourseId,
+            es.student_name as studentName,
+            es.student_code as studentCode,
+            es.ticket_number as ticketNumber,
+            es.site_number as siteNumber,
+            es.print_paper as printPaper,
+            es.print_card as printCard,
+            es.extend_fields as extendFields,
+            es.paper_type as paperType,
+            es.create_id as createId,
+            es.create_time as createTime,
+            es.update_id as updateId,
+            es.update_time as updateTime,
+            es.attachment_id as attachmentId,
+            edc.course_code as courseCode,
+            edc.course_name as courseName,
+            edc.paper_pages_a3 as paperPageA3,
+            edc.paper_number as paperNumber
+        from
+            exam_student es
+        left join exam_detail_course edc on
+            edc.id = es.exam_detail_course_id
+            <where>
+                <if test="schoolId != null and schoolId != ''">
+                    and es.school_id = #{schoolId}
+                </if>
+                <if test="examDetailCourseIds != null">
+                    AND edc.id IN
+                    <foreach collection="examDetailCourseIds" item="examDetailCourseId" index="index" open="(" separator="," close=")">
+                        #{examDetailCourseId}
+                    </foreach>
+                </if>
+            </where>
+            order by edc.course_code
+    </select>
+
 </mapper>