xiaof il y a 4 ans
Parent
commit
4a497623cf

+ 98 - 137
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ClientServiceImpl.java

@@ -58,7 +58,7 @@ public class ClientServiceImpl implements ClientService {
     }
 
     @Override
-    public Map<String, String>  getUrl(Long schoolId, Long examTaskId) {
+    public Map<String, String> getUrl(Long schoolId, Long examTaskId) {
         return examTaskDetailService.getUrl(schoolId, examTaskId);
     }
 
@@ -87,47 +87,9 @@ public class ClientServiceImpl implements ClientService {
         // 取考生
         List<Map> studentList = examDetailService.listStudentByExamDetailId(schoolId, examDetailId, ticketNumber, type);
         // 生成试卷List
-        List<ClientPrintDataDto> paperList = studentList.stream().map(m -> {
-            ClientPrintDataDto printDataDto = new ClientPrintDataDto();
-            String courseCode = m.get("courseCode").toString();
-            String courseName = m.get("courseName").toString();
-            String paperNumber = m.get("paperNumber").toString();
-            String studentName = m.get("studentName").toString();
-            String studentCode = m.get("studentCode").toString();
-            String paperType = m.get("paperType").toString();
-            printDataDto.setCourseCode(courseCode);
-            printDataDto.setCourseName(courseName);
-            printDataDto.setStudentName(studentName);
-            printDataDto.setStudentCode(studentCode);
-            printDataDto.setPaperType(paperType);
-
-            StringJoiner sj = new StringJoiner(SystemConstant.DELIMITER);
-            String key = sj.add(courseCode).add(paperNumber).add(paperType).toString();
-            printDataDto.setMd5(map.get(key).get("md5"));
-            printDataDto.setUrl(map.get(key).get("url"));
-            return printDataDto;
-        }).collect(Collectors.toList());
-        finalMap.put("paper", paperList);
+        finalMap.put("paper", splicePaperContent(studentList, map));
         // 生成题卡List
-        List<ClientPrintDataDto> cardList = studentList.stream().map(m -> {
-            ClientPrintDataDto printDataDto = new ClientPrintDataDto();
-            String courseCode = m.get("courseCode").toString();
-            String courseName = m.get("courseName").toString();
-            String studentName = m.get("studentName").toString();
-            String studentCode = m.get("studentCode").toString();
-            String paperType = m.get("paperType").toString();
-            String attachmentId = m.get("attachmentId").toString();
-            printDataDto.setCourseCode(courseCode);
-            printDataDto.setCourseName(courseName);
-            printDataDto.setStudentName(studentName);
-            printDataDto.setStudentCode(studentCode);
-            printDataDto.setPaperType(paperType);
-            Map<String, String> urlMap = commonService.filePreviewByAttachmentId(Long.valueOf(attachmentId), false);
-            printDataDto.setMd5(urlMap.get("md5"));
-            printDataDto.setUrl(urlMap.get("url"));
-            return printDataDto;
-        }).collect(Collectors.toList());
-        finalMap.put("card", cardList);
+        finalMap.put("card", spliceCardContent(studentList));
         //
         ExamDetail examDetail = examDetailService.getById(examDetailId);
         ExamPrintPlan examPrintPlan = examPrintPlanService.getById(examDetail.getPrintPlanId());
@@ -141,35 +103,13 @@ public class ClientServiceImpl implements ClientService {
             JSONObject jsonObject = JSONObject.parseObject(attachmentPath);
             String pathString = jsonObject.getString("path");
             List<Map> pathList = JSONObject.parseArray(pathString, Map.class);
-            if(!pathList.isEmpty()) {
-                for (Map variable : variableList) {
-                    Map vMap = new HashMap();
-                    vMap.put("type", variable.get("type"));
-                    for (Map path : pathList) {
-                        String printType = path.get("printType").toString();
-                        if(printType.equals(variable.get("type").toString())){
-                            vMap.put("htmlUrl", commonService.filePreviewByPathAndType(path.get("htmlPath").toString(), path.get("type").toString(), false));
-                            vMap.put("htmlMd5", path.get("htmlMd5"));
-                            vMap.put("pdfUrl", commonService.filePreviewByPathAndType(path.get("pdfPath").toString(), path.get("type").toString(), false));
-                            vMap.put("pdfMd5", path.get("pdfMd5"));
-                        }
-                    }
-                    otherList.add(vMap);
+            if (!pathList.isEmpty()) {
+                for (Map contentMap : variableList) {
+                    spliceOtherContent(otherList, pathList, contentMap);
                 }
                 List<Map> ordinaryList = JSONObject.parseArray(ordinaryContent, Map.class);
-                for (Map ordinary : ordinaryList) {
-                    Map vMap = new HashMap();
-                    vMap.put("type", ordinary.get("type"));
-                    for (Map path : pathList) {
-                        String printType = path.get("printType").toString();
-                        if(printType.equals(ordinary.get("type").toString())){
-                            vMap.put("htmlUrl", commonService.filePreviewByPathAndType(path.get("htmlPath").toString(), path.get("type").toString(), false));
-                            vMap.put("htmlMd5", path.get("htmlMd5"));
-                            vMap.put("pdfUrl", commonService.filePreviewByPathAndType(path.get("pdfPath").toString(), path.get("type").toString(), false));
-                            vMap.put("pdfMd5", path.get("pdfMd5"));
-                        }
-                    }
-                    otherList.add(vMap);
+                for (Map contentMap : ordinaryList) {
+                    spliceOtherContent(otherList, pathList, contentMap);
                 }
             }
         }
@@ -214,47 +154,11 @@ public class ClientServiceImpl implements ClientService {
         // 3.2取考生
         List<Map> studentList = examDetailService.listStudentByExamDetailId(schoolId, examDetailId, "1", "1");
         // 3.3生成试卷List
-        List<ClientPrintDataDto> paperList = studentList.stream().map(m -> {
-            ClientPrintDataDto printDataDto = new ClientPrintDataDto();
-            String courseCode = m.get("courseCode").toString();
-            String courseName = m.get("courseName").toString();
-            String paperNumber = m.get("paperNumber").toString();
-            String studentName = m.get("studentName").toString();
-            String studentCode = m.get("studentCode").toString();
-            String paperType = m.get("paperType").toString();
-            printDataDto.setCourseCode(courseCode);
-            printDataDto.setCourseName(courseName);
-            printDataDto.setStudentName(studentName);
-            printDataDto.setStudentCode(studentCode);
-            printDataDto.setPaperType(paperType);
 
-            StringJoiner sj = new StringJoiner(SystemConstant.DELIMITER);
-            String key = sj.add(courseCode).add(paperNumber).add(paperType).toString();
-            printDataDto.setMd5(map.get(key).get("md5"));
-            printDataDto.setUrl(map.get(key).get("url"));
-            return printDataDto;
-        }).collect(Collectors.toList());
-        detailMap.put("paper", paperList);
+        detailMap.put("paper", splicePaperContent(studentList, map));
         // 3.4生成题卡List
-        List<ClientPrintDataDto> cardList = studentList.stream().map(m -> {
-            ClientPrintDataDto printDataDto = new ClientPrintDataDto();
-            String courseCode = m.get("courseCode").toString();
-            String courseName = m.get("courseName").toString();
-            String studentName = m.get("studentName").toString();
-            String studentCode = m.get("studentCode").toString();
-            String paperType = m.get("paperType").toString();
-            String attachmentId = m.get("attachmentId").toString();
-            printDataDto.setCourseCode(courseCode);
-            printDataDto.setCourseName(courseName);
-            printDataDto.setStudentName(studentName);
-            printDataDto.setStudentCode(studentCode);
-            printDataDto.setPaperType(paperType);
-            Map<String, String> urlMap = commonService.filePreviewByAttachmentId(Long.valueOf(attachmentId), false);
-            printDataDto.setMd5(urlMap.get("md5"));
-            printDataDto.setUrl(urlMap.get("url"));
-            return printDataDto;
-        }).collect(Collectors.toList());
-        detailMap.put("card", cardList);
+
+        detailMap.put("card", spliceCardContent(studentList));
 
         //3.4备用试卷、题卡
         ExamPrintPlan examPrintPlan = examPrintPlanService.getById(examDetail.getPrintPlanId());
@@ -320,40 +224,18 @@ public class ClientServiceImpl implements ClientService {
             JSONObject jsonObject = JSONObject.parseObject(attachmentPath);
             String pathString = jsonObject.getString("path");
             List<Map> pathList = JSONObject.parseArray(pathString, Map.class);
-            if(!pathList.isEmpty()) {
-                for (Map variable : variableList) {
-                    int count = Integer.parseInt(variable.get("backupCount").toString());
+            if (!pathList.isEmpty()) {
+                for (Map contentMap : variableList) {
+                    int count = Integer.parseInt(contentMap.get("backupCount").toString());
                     for (int i = 0; i < count; i++) {
-                        Map vMap = new HashMap();
-                        vMap.put("type", variable.get("type"));
-                        for (Map path : pathList) {
-                            String printType = path.get("printType").toString();
-                            if(printType.equals(variable.get("type").toString())){
-                                vMap.put("htmlUrl", commonService.filePreviewByPathAndType(path.get("htmlPath").toString(), path.get("type").toString(), false));
-                                vMap.put("htmlMd5", path.get("htmlMd5"));
-                                vMap.put("pdfUrl", commonService.filePreviewByPathAndType(path.get("pdfPath").toString(), path.get("type").toString(), false));
-                                vMap.put("pdfMd5", path.get("pdfMd5"));
-                            }
-                        }
-                        otherList.add(vMap);
+                        spliceOtherContent(otherList, pathList, contentMap);
                     }
                 }
                 List<Map> ordinaryList = JSONObject.parseArray(ordinaryContent, Map.class);
-                for (Map ordinary : ordinaryList) {
-                    int count = Integer.parseInt(ordinary.get("backupCount").toString());
+                for (Map contentMap : ordinaryList) {
+                    int count = Integer.parseInt(contentMap.get("backupCount").toString());
                     for (int i = 0; i < count; i++) {
-                        Map vMap = new HashMap();
-                        vMap.put("type", ordinary.get("type"));
-                        for (Map path : pathList) {
-                            String printType = path.get("printType").toString();
-                            if(printType.equals(ordinary.get("type").toString())){
-                                vMap.put("htmlUrl", commonService.filePreviewByPathAndType(path.get("htmlPath").toString(), path.get("type").toString(), false));
-                                vMap.put("htmlMd5", path.get("htmlMd5"));
-                                vMap.put("pdfUrl", commonService.filePreviewByPathAndType(path.get("pdfPath").toString(), path.get("type").toString(), false));
-                                vMap.put("pdfMd5", path.get("pdfMd5"));
-                            }
-                        }
-                        otherList.add(vMap);
+                        spliceOtherContent(otherList, pathList, contentMap);
                     }
 
                 }
@@ -515,7 +397,6 @@ public class ClientServiceImpl implements ClientService {
             for (Map attaMap : attachementIds) {
                 String name = attaMap.get("name").toString();
                 String attachmentId = attaMap.get("attachmentId").toString();
-                BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
                 Map<String, String> stringMap = commonService.filePreviewByAttachmentId(Long.valueOf(attachmentId), false);
                 StringJoiner sj = new StringJoiner(SystemConstant.DELIMITER);
                 String key = sj.add(courseCode).add(paperNumber).add(name).toString();
@@ -524,4 +405,84 @@ public class ClientServiceImpl implements ClientService {
         }
         return map;
     }
+
+
+    /**
+     * 生成印品url公共方法
+     *
+     * @param otherList
+     * @param pathList
+     * @param contentMap
+     */
+    private void spliceOtherContent(List<Map> otherList, List<Map> pathList, Map contentMap) {
+        Map vMap = new HashMap();
+        vMap.put("type", contentMap.get("type"));
+        for (Map path : pathList) {
+            String printType = path.get("printType").toString();
+            if (printType.equals(contentMap.get("type").toString())) {
+                vMap.put("htmlUrl", commonService.filePreviewByPathAndType(path.get("htmlPath").toString(), path.get("type").toString(), false));
+                vMap.put("htmlMd5", path.get("htmlMd5"));
+                vMap.put("pdfUrl", commonService.filePreviewByPathAndType(path.get("pdfPath").toString(), path.get("type").toString(), false));
+                vMap.put("pdfMd5", path.get("pdfMd5"));
+            }
+        }
+        otherList.add(vMap);
+    }
+
+    /**
+     * 生成试卷url公共方法
+     *
+     * @param studentList
+     * @param map
+     * @return
+     */
+    private List<ClientPrintDataDto> splicePaperContent(List<Map> studentList, Map<String, Map<String, String>> map) {
+        List<ClientPrintDataDto> paperList = studentList.stream().map(m -> {
+            ClientPrintDataDto printDataDto = newClientPrintDataDto(m);
+            StringJoiner sj = new StringJoiner(SystemConstant.DELIMITER);
+            String key = sj.add(printDataDto.getCourseCode()).add(m.get("paperNumber").toString()).add(printDataDto.getPaperType()).toString();
+            printDataDto.setMd5(map.get(key).get("md5"));
+            printDataDto.setUrl(map.get(key).get("url"));
+            return printDataDto;
+        }).collect(Collectors.toList());
+        return paperList;
+    }
+
+    /**
+     * 生成题卡url公共方法
+     *
+     * @param studentList
+     * @return
+     */
+    private List<ClientPrintDataDto> spliceCardContent(List<Map> studentList) {
+        List<ClientPrintDataDto> cardList = studentList.stream().map(m -> {
+            ClientPrintDataDto printDataDto = newClientPrintDataDto(m);
+            Map<String, String> urlMap = commonService.filePreviewByAttachmentId(Long.valueOf(m.get("attachmentId").toString()), false);
+            printDataDto.setMd5(urlMap.get("md5"));
+            printDataDto.setUrl(urlMap.get("url"));
+            return printDataDto;
+        }).collect(Collectors.toList());
+        return cardList;
+    }
+
+    /**
+     * new ClientPrintDataDto
+     *
+     * @param m
+     * @return
+     */
+    private ClientPrintDataDto newClientPrintDataDto(Map m) {
+        ClientPrintDataDto printDataDto = new ClientPrintDataDto();
+        String courseCode = m.get("courseCode").toString();
+        String courseName = m.get("courseName").toString();
+        String studentName = m.get("studentName").toString();
+        String studentCode = m.get("studentCode").toString();
+        String paperType = m.get("paperType").toString();
+        printDataDto.setCourseCode(courseCode);
+        printDataDto.setCourseName(courseName);
+        printDataDto.setStudentName(studentName);
+        printDataDto.setStudentCode(studentCode);
+        printDataDto.setPaperType(paperType);
+        return printDataDto;
+    }
 }

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

@@ -66,6 +66,9 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
         // 新增
         ExamCard examCard;
         ExamCardDetail examCardDetail;
+        if(examCardParams.getTitle().getBytes().length > 80){
+            throw ExceptionResultEnum.ERROR.exception("标题最长只能输入80个字符");
+        }
         if (examCardParams.getId() == null) {
             examCard = new ExamCard();
             examCard.setId(SystemConstant.getDbUuid());

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

@@ -203,9 +203,9 @@ public class ExamPrintPlanServiceImpl extends ServiceImpl<ExamPrintPlanMapper, E
         if (Objects.isNull(basicExamRule)) {
             throw ExceptionResultEnum.ERROR.exception("未找到学校的通用规则");
         }
-        if (basicExamRule.getIncludePaper() && !printContentList.contains("PAPER")) {
+        /*if (basicExamRule.getIncludePaper() && !printContentList.contains("PAPER")) {
             throw ExceptionResultEnum.ERROR.exception("学校通用规则设置了强制包含试卷的必须选择试卷印品!");
-        }
+        }*/
         if (printContentList.contains("PAPER") && !printContentList.contains("CARD")) {
             throw ExceptionResultEnum.ERROR.exception("如果试卷题卡印品选择了试卷,题卡必须被选择");
         }

+ 9 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -740,15 +740,22 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
 
             // 是否强制包含试卷
             BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
+            List<Map> paperAttachmentIds = JSONObject.parseArray(examTaskDetail.getPaperAttachmentIds(), Map.class);
+            // 未上传试卷的类型个数
+            long count = paperAttachmentIds.stream().filter(m -> StringUtils.isBlank(m.get("attachmentId").toString())).count();
             if (basicExamRule.getIncludePaper()) {
                 if (StringUtils.isBlank(examTaskDetail.getPaperAttachmentIds())) {
                     throw ExceptionResultEnum.ERROR.exception("试卷文件未上传");
                 }
-                List<Map> paperAttachmentIds = JSONObject.parseArray(examTaskDetail.getPaperAttachmentIds(), Map.class);
-                long count = paperAttachmentIds.stream().filter(m -> StringUtils.isBlank(m.get("attachmentId").toString())).count();
                 if (count > 0) {
                     throw ExceptionResultEnum.ERROR.exception("所有类型的试卷文件必须全部上传");
                 }
+            } else {
+                // count == 0为全部上传
+                // paperAttachmentIds.size() == count 为全部未上传
+                if (count != 0 && paperAttachmentIds.size() != count) {
+                    throw ExceptionResultEnum.ERROR.exception("所有类型的试卷文件必须全部上传或全部不上传");
+                }
             }
         }
 

+ 3 - 2
distributed-print-business/src/main/resources/mapper/ExamDetailMapper.xml

@@ -42,7 +42,8 @@
             ifnull(b.pages_a3, 0) pagesA3,
             ifnull(b.pages_a4, 0) pagesA4,
             c.singlePagesA3,
-            b.status
+            b.status,
+            b.validate
         FROM
             exam_print_plan a
                  JOIN
@@ -344,7 +345,7 @@
             and c.ticket_number = #{ticketNumber}
         </if>
         <if test="type == 'MORE'">
-            and c.ticket_number > #{ticketNumber}
+            and c.ticket_number >= #{ticketNumber}
         </if>
     </select>
     <select id="selectPaperCount" resultType="java.lang.Integer">