wangliang %!s(int64=4) %!d(string=hai) anos
pai
achega
f9f123b073

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

@@ -222,7 +222,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             examTaskDetail.setRelatePaperType(paperType);
 
                             //获取试卷pdf
-                            createPdfUtil.getPaperPdf(examTaskDetail, examPrintPlan.getBackupCount(), paperPdfTempList, backupPaperTempPdfList);
+                            boolean tag = createPdfUtil.getPaperPdf(paperType, examTaskDetail, examPrintPlan.getBackupCount(), paperPdfTempList, backupPaperTempPdfList);
                             paperPdfList.addAll(paperPdfTempList);
                             backupPaperPdfList.addAll(backupPaperTempPdfList);
 
@@ -257,7 +257,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                         if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
                                             createPdfUtil.createSignBook(basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
                                         } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAGE")) {//卷袋贴
-                                            createPdfUtil.createPaperPackage(basicAttachment, basicSchool.getName(), examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
+                                            createPdfUtil.createPaperPackage(tag, basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
                                         }
                                     }
                                 }

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

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.util;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -88,6 +89,7 @@ public class CreatePdfUtil {
     /**
      * 生成卷袋贴
      *
+     * @param tag
      * @param basicAttachment
      * @param schoolName
      * @param examDetailCourse
@@ -96,33 +98,76 @@ public class CreatePdfUtil {
      * @param printCount
      * @throws IOException
      */
-    public void createPaperPackage(BasicAttachment basicAttachment, String schoolName, ExamDetailCourse examDetailCourse, List<ExamStudent> examStudentList, List<PdfDto> variablePdfList, Integer 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 {
         if (Objects.isNull(basicAttachment)) {
             throw ExceptionResultEnum.ERROR.exception("找不到附件");
         }
         Map<String, Object> htmlMap = new HashMap<>();
         htmlMap.put("examDetailCourseId", examDetailCourse.getId());
         htmlMap.put("schoolName", schoolName);
-        htmlMap.put("examName", "测试exam1");
         htmlMap.put("courseName", examDetailCourse.getCourseName());
         htmlMap.put("courseCode", examDetailCourse.getCourseCode());
-        htmlMap.put("examSite", "测试examSite1");
-        htmlMap.put("examRoom", "测试examRoom1");
-        htmlMap.put("startTime", "2021-04-13 00:00:00");
-        htmlMap.put("endTime", "2021-04-14 00:00:00");
+        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", examDetailCourse.getPaperNumber());
         htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
 
-        htmlMap.put("startCollege", "测试startCollege1");
-        htmlMap.put("className", "测试className1");
-        htmlMap.put("proctorCollege", "测试proctorCollege1");
-        htmlMap.put("examManager", "测试examManager1");
+        List<String> extendColumnList = examStudentList.stream().map(m -> m.getExtendFields()).distinct().collect(Collectors.toList());
+        Set<String> startCollege = new HashSet();
+        Set<String> className = new HashSet();
+        Set<String> proctorCollege = new HashSet();
+        Set<String> examManager = new HashSet();
+
+        if (Objects.nonNull(extendColumnList) && extendColumnList.size() > 0) {
+            for (String s : extendColumnList) {
+                List<Map> mapList = JSONObject.parseArray(s, Map.class);
+                for (Map map : mapList) {
+                    if (Objects.equals("startCollege", map.get("code").toString())) {
+                        startCollege.add(map.get("value").toString());
+                    }
+                    if (Objects.equals("className", map.get("code").toString())) {
+                        className.add(map.get("value").toString());
+                    }
+                    if (Objects.equals("proctorCollege", map.get("code").toString())) {
+                        proctorCollege.add(map.get("value").toString());
+                    }
+                    if (Objects.equals("examManager", map.get("code").toString())) {
+                        examManager.add(map.get("value").toString());
+                    }
+                }
+            }
+        }
+
+        htmlMap.put("startCollege", String.join(",", startCollege));
+        htmlMap.put("className", String.join(",", className));
+        htmlMap.put("proctorCollege", String.join(",", proctorCollege));
+        htmlMap.put("examManager", String.join(",", examManager));
+
+        String minSite = examStudentList.stream().min((a, b) -> {
+            if (Objects.nonNull(a.getSiteNumber()) && Objects.nonNull(a.getSiteNumber())) {
+                return a.getSiteNumber().compareTo(b.getSiteNumber());
+            } else {
+                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())) {
+                return a.getSiteNumber().compareTo(b.getSiteNumber());
+            } else {
+                return 0;
+            }
+        }).get().getSiteNumber();
+        maxSite = Objects.isNull(maxSite) ? "" : maxSite;
 
-        htmlMap.put("minSite", "测试minSite1");
-        htmlMap.put("maxSite", "测试maxSite1");
+        htmlMap.put("minSite", minSite);
+        htmlMap.put("maxSite", maxSite);
         htmlMap.put("studentCount", examStudentList.size());
 
-        htmlMap.put("tag", "测试tag1");
+        htmlMap.put("tag", tag ? "订" : "");
 
         htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
         htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
@@ -135,6 +180,7 @@ public class CreatePdfUtil {
      *
      * @param basicAttachment
      * @param schoolName
+     * @param examDetail
      * @param examDetailCourse
      * @param examStudentList
      * @param variablePdfList
@@ -150,9 +196,22 @@ public class CreatePdfUtil {
         htmlMap.put("courseName", examDetailCourse.getCourseName());
         htmlMap.put("courseCode", examDetailCourse.getCourseCode());
         htmlMap.put("examRoom", examDetail.getExamRoom());
-        htmlMap.put("classTeacher", "测试老师1");
-        htmlMap.put("startTime", "2021-04-13 00:00:00");
-        htmlMap.put("endTime", "2021-04-14 00:00:00");
+
+        List<String> extendColumnList = examStudentList.stream().map(m -> m.getExtendFields()).distinct().collect(Collectors.toList());
+        Set<String> classTeacher = new HashSet();
+        if (Objects.nonNull(extendColumnList) && extendColumnList.size() > 0) {
+            for (String s : extendColumnList) {
+                List<Map> mapList = JSONObject.parseArray(s, Map.class);
+                for (Map map : mapList) {
+                    if (Objects.equals("classTeacher", map.get("code").toString())) {
+                        classTeacher.add(map.get("value").toString());
+                    }
+                }
+            }
+        }
+        htmlMap.put("classTeacher", String.join(",", classTeacher));
+        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", examDetailCourse.getPaperNumber());
         htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
 
@@ -245,13 +304,15 @@ public class CreatePdfUtil {
     /**
      * 获取试卷pdf
      *
+     * @param paperType
      * @param examTaskDetail
      * @param backupCount
      * @param pdfList
      * @return
      * @throws IOException
      */
-    public void getPaperPdf(ExamTaskDetail examTaskDetail, Integer backupCount, List<PdfDto>... pdfList) throws IOException {
+    public boolean getPaperPdf(String paperType, ExamTaskDetail examTaskDetail, Integer backupCount, List<PdfDto>... pdfList) throws IOException {
+        boolean tag = true;
         JSONArray jsonArrayPaper = JSONArray.parseArray(examTaskDetail.getPaperAttachmentIds());
         for (int i = 0; i < jsonArrayPaper.size(); i++) {
             JSONObject object = (JSONObject) jsonArrayPaper.get(i);
@@ -261,14 +322,20 @@ public class CreatePdfUtil {
                 if (Objects.isNull(basicAttachment)) {
                     throw ExceptionResultEnum.ERROR.exception("找不到附件");
                 }
-                File file = commonService.getFile(basicAttachment.getPath(), false);
-                int pageCount = PdfUtil.addPdfPage(file);
-                pdfList[0].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pageCount));
-                for (int j = 1; j <= backupCount; j++) {
-                    pdfList[1].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pageCount));
+                String name = (String) object.get("name");
+                if (Objects.equals(name.toUpperCase(), paperType.toUpperCase())) {
+                    File file = commonService.getFile(basicAttachment.getPath(), false);
+                    int pages = (int) object.get("pages");
+                    tag = pages > 2 ? true : false;
+                    int pageCount = PdfUtil.addPdfPage(file);
+                    pdfList[0].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pageCount));
+                    for (int j = 1; j <= backupCount; j++) {
+                        pdfList[1].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pageCount));
+                    }
                 }
             }
         }
+        return tag;
     }
 
     /**

+ 23 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfUtil.java

@@ -103,7 +103,7 @@ public class PdfUtil {
                 IOUtils.write(baos.toByteArray(), fileOutputStream);
             }
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("请求出错", e);
         } finally {
             if (Objects.nonNull(reader)) {
                 reader.close();
@@ -116,6 +116,28 @@ public class PdfUtil {
         return Objects.nonNull(reader) ? reader.getNumberOfPages() : 0;
     }
 
+    /**
+     * 获取pdfPages
+     *
+     * @param pdfFile
+     * @return
+     * @throws IOException
+     */
+    public static int getPdfPages(File pdfFile) throws IOException {
+        PdfReader reader = null;
+        try {
+            reader = new PdfReader(pdfFile.getPath());
+            return reader.getNumberOfPages();
+        } catch (Exception e) {
+            log.error("请求出错", e);
+        } finally {
+            if (Objects.nonNull(reader)) {
+                reader.close();
+            }
+        }
+        return 0;
+    }
+
 //    public static void main(String[] args) {
 //        String[] files = {
 //                "/Users/king/Downloads/测试附件/101_148382537591291904_signAndSticker.pdf",

+ 1 - 0
distributed-print-business/src/main/resources/mapper/TBTaskMapper.xml

@@ -39,5 +39,6 @@
                     and tbt.result = #{result}
                 </if>
             </where>
+            order by tbt.create_time desc
     </select>
 </mapper>