Browse Source

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

xiaof 4 years ago
parent
commit
0a25569577

+ 61 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExtendFieldsDto.java

@@ -0,0 +1,61 @@
+package com.qmth.distributed.print.business.bean.dto;
+
+/**
+ * @Description: 考务学生-扩展字段
+ * @Author: CaoZixuan
+ * @Date: 2021-04-21
+ */
+public class ExtendFieldsDto {
+
+    /**
+     * 考务字段代码
+     */
+    private String code;
+
+    /**
+     * 考务字段名称
+     */
+    private String name;
+
+    /**
+     * 考务字段是否可用(仅考务规则有)
+     */
+    private Boolean enable;
+
+    /**
+     * 考务字段值(仅考生有)
+     */
+    private String value;
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}

+ 2 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CommonService.java

@@ -165,6 +165,8 @@ public interface CommonService {
      */
     public void checkData(Long schoolId, String courseCode, String paperNumber,SysUser user) throws IOException;
 
+//    public void checkDataForExamination()
+
     /**
      * 根据orgId查询所有子机构ID集合
      * @return

+ 8 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskService.java

@@ -93,4 +93,12 @@ public interface ExamTaskService extends IService<ExamTask> {
     ExamTask getByCourseCodeAndPaperNumber(Long schoolId, String courseCode, String paperNumber);
 
     IPage<ClientExamTaskDto> listTryTask(Long schoolId, String machineCode, Long orgId, Long printPlanId, String courseCode, String paperNumber, Boolean isTry, Boolean isPass, Integer pageNumber, Integer pageSize);
+
+    /**
+     * 检测考务数据的试卷编号和课程代码的正确性(根据试卷编号查询命题任务的试卷编号,如果存在,查询该命题任务记录对应的课程代码和考务数据导入的该条课程代码是否一致)
+     * @param schoolId 考务数据导入的学校代码
+     * @param paperNumber 考务数据导入的试卷编号
+     * @param courseCode 考务数据导入的课程代码
+     */
+    void verifyCourseCodeByPaperNumber(Long schoolId,String paperNumber,String courseCode);
 }

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

@@ -27,6 +27,7 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
 import org.apache.poi.xssf.usermodel.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -461,6 +462,9 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
             String paperNumber = String.valueOf(map.get("paperNumber"));
             String studentName = String.valueOf(map.get("studentName"));
             String studentCode = String.valueOf(map.get("studentCode"));
+
+            List<FieldsDto> fieldsDtoList = (List<FieldsDto>) map.get("secondaryFieldList");
+            List<ExtendFieldsDto> extendFieldsDtoList = this.getExtendFieldsByFields(fieldsDtoList);
             List<ExamDetail> examDetailList = this.list(new QueryWrapper<ExamDetail>().lambda()
                     .eq(ExamDetail::getPrintPlanId, printPlanId)
                     .eq(ExamDetail::getExamPlace, examPlace)
@@ -488,6 +492,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
             examStudent.setStudentName(studentName);
             examStudent.setStudentCode(studentCode);
             examStudent.setTicketNumber(studentCode);
+            examStudent.setExtendFields(JSON.toJSONString(extendFieldsDtoList));
             examStudent.setSiteNumber("");
             examStudent.setCreateId(userId);
             examStudent.setUpdateId(userId);
@@ -635,4 +640,14 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
         // 删除exam_student 表数据
         examStudentService.remove(new QueryWrapper<ExamStudent>().lambda().in(ExamStudent::getId, examStudentIds));
     }
+
+    private List<ExtendFieldsDto> getExtendFieldsByFields(List<FieldsDto> fieldsDtoList){
+        List<ExtendFieldsDto> extendFieldsDtoList = new ArrayList<>();
+        for (FieldsDto fieldsDto : fieldsDtoList) {
+            ExtendFieldsDto extendFieldsDto = new ExtendFieldsDto();
+            BeanUtils.copyProperties(fieldsDto,extendFieldsDto);
+            extendFieldsDtoList.add(extendFieldsDto);
+        }
+        return extendFieldsDtoList;
+    }
 }

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

@@ -739,4 +739,19 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         IPage<ClientExamTaskDto> examTaskDtoIPage = this.baseMapper.listClientExamTaskPage(page, schoolId, machineCode, printPlanId, courseCode, paperNumber, isTry, isPass, orgIds);
         return examTaskDtoIPage;
     }
+
+    @Transactional
+    @Override
+    public void verifyCourseCodeByPaperNumber(Long schoolId,String paperNumber, String courseCode) {
+        List<ExamTask> examTaskList = this.list(new QueryWrapper<ExamTask>().lambda()
+                .eq(ExamTask::getPaperNumber,paperNumber).eq(ExamTask::getSchoolId,schoolId));
+        if (examTaskList.size() > 1){
+            throw ExceptionResultEnum.ERROR.exception("异常 : 有多条命题任务记录 schoolId = " + schoolId + " paperNumber = " + paperNumber);
+        }else if (examTaskList.size() == 1){
+            ExamTask examTask = examTaskList.get(0);
+            if (!courseCode.equals(examTask.getCourseCode())){
+                throw ExceptionResultEnum.ERROR.exception("要导入的考务数据的试卷编号在命题任务中已存在,但该试卷编号对应的考务数据课程代码和命题任务中的课程代码不匹配  试卷编号 : " + paperNumber);
+            }
+        }
+    }
 }

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

@@ -109,6 +109,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     RedisTemplate<String, Object> redisTemplate;
 
+
     /**
      * 创建pdf逻辑
      *
@@ -222,7 +223,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 +258,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"));
                                         }
                                     }
                                 }
@@ -470,6 +471,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     }
                 }
             }
+            // 校验试卷编号
+            examTaskService.verifyCourseCodeByPaperNumber(schoolId,paperNumber,courseCode);
+
             // 校验课程信息
             basicCourseService.verifyCourseInfo(schoolId, courseCode, courseName, userId);
 
@@ -494,6 +498,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             dataMap.put("printPlanName", printPlanName);
             dataList.add(dataMap);
         }
+        System.out.println(JSON.toJSONString(dataList));
         // 校验课程代码和试卷编号在印刷计划下是1对1的关系
         List<String> courseCodeList = dataList.stream().map(e -> String.valueOf(e.get("courseCode"))).distinct().collect(Collectors.toList());
         List<String> paperNumberList = dataList.stream().map(e -> String.valueOf(e.get("paperNumber"))).distinct().collect(Collectors.toList());

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