wangliang 4 роки тому
батько
коміт
607d038306

+ 4 - 0
distributed-print-business/pom.xml

@@ -93,6 +93,10 @@
             <groupId>com.google.zxing</groupId>
             <artifactId>javase</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 28 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExamStudentDto.java

@@ -0,0 +1,28 @@
+package com.qmth.distributed.print.business.bean.dto;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+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/4/12
+ */
+public class ExamStudentDto extends ExamStudent {
+
+    @ApiModelProperty(value = "序号")
+    private Integer index; //序号
+
+    public Integer getIndex() {
+        return index;
+    }
+
+    public void setIndex(Integer index) {
+        this.index = index;
+    }
+}

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

@@ -61,6 +61,16 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      */
     public BasicAttachment saveAttachmentPdf(String dirName, Long userId) throws IOException;
 
+    /**
+     * 保存附件
+     *
+     * @param basicAttachment
+     * @param variablePdfList
+     * @return
+     * @throws IOException
+     */
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<String> variablePdfList) throws IOException;
+
     /**
      * 删除附件
      *

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

@@ -113,6 +113,15 @@ public interface CommonService {
      */
     public InputStream getFileInputStream(String path, boolean pdf) throws IOException;
 
+    /**
+     * 获取文件byte数据
+     *
+     * @param path
+     * @param pdf
+     * @return
+     */
+    public byte[] getFileByte(String path, boolean pdf) throws IOException;
+
     /**
      * 获取文件
      *
@@ -124,7 +133,8 @@ public interface CommonService {
 
     /**
      * 下载文件到本地
-     * @param rootPath 保存目录
+     *
+     * @param rootPath   保存目录
      * @param attachment 附件表对象
      * @return
      */
@@ -132,8 +142,9 @@ public interface CommonService {
 
     /**
      * 下载文件到本地并压缩返回
+     *
      * @param filePath 文件根目录
-     * @param files 需要下载的文件集合
+     * @param files    需要下载的文件集合
      */
     public void downloadFileAndZip(HttpServletResponse response, String filePath, List<File> files);
 }

+ 30 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -197,6 +197,36 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
         return basicAttachment;
     }
 
+    /**
+     * 保存附件
+     *
+     * @param basicAttachment
+     * @return
+     * @throws IOException
+     */
+    @Override
+    @Transactional
+    public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<String> variablePdfList) throws IOException {
+        boolean oss = dictionaryConfig.sysDomain().isOss();
+        JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
+        String filePath = (String) jsonObject.get(SystemConstant.PATH);
+        String url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
+        File localHtmlFile = ossUtil.ossDownload(filePath, url);
+        String pdfDirName = filePath.replaceAll(SystemConstant.HTML_PREFIX, SystemConstant.PDF_PREFIX).replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
+        String destUrl = SystemConstant.PDF_TEMP_FILES_DIR + File.separator + pdfDirName;
+        HtmlToPdfUtil.convert(localHtmlFile.getPath(), destUrl, PageSizeEnum.A4);
+        File pdf = new File(destUrl);
+        String fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdf));
+        if (oss) {//上传至oss
+            ossUtil.ossUpload(pdfDirName, pdf, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
+            localHtmlFile.delete();
+            jsonObject.put(SystemConstant.PDF_PATH, pdfDirName);
+        }
+        variablePdfList.add(pdf.getPath());
+        this.updateById(basicAttachment);
+        return basicAttachment;
+    }
+
     /**
      * 删除附件
      *

+ 27 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CommonServiceImpl.java

@@ -24,6 +24,7 @@ import com.qmth.distributed.print.common.contant.SpringContextHolder;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.SessionUtil;
+import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -380,6 +381,32 @@ public class CommonServiceImpl implements CommonService {
         return inputStream;
     }
 
+    /**
+     * 获取文件数组
+     *
+     * @param path
+     * @param pdf
+     * @return
+     * @throws IOException
+     */
+    @Override
+    public byte[] getFileByte(String path, boolean pdf) throws IOException {
+        byte[] data = null;
+        JSONObject jsonObject = JSONObject.parseObject(path);
+        String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
+        String filePath = pdf ? (String) jsonObject.get(SystemConstant.PDF_PATH) : (String) jsonObject.get(SystemConstant.PATH);
+        if (Objects.equals(attachmentType, SystemConstant.OSS)) {
+            data = ossUtil.ossDownload(filePath);
+        } else {
+            StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
+            InputStream inputStream = new FileInputStream(new File(localPath.toString()));
+            ByteArrayOutputStream ou = new ByteArrayOutputStream();
+            IOUtils.copy(inputStream, ou);
+            data = ou.toByteArray();
+        }
+        return data;
+    }
+
     /**
      * 获取文件
      *

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

@@ -6,16 +6,14 @@ import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.gson.Gson;
 import com.qmth.boot.api.exception.ApiException;
+import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
 import com.qmth.distributed.print.business.bean.dto.excel.UserImportDto;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.DrawRuleEnum;
 import com.qmth.distributed.print.business.enums.ExamStatusEnum;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.service.TaskLogicService;
-import com.qmth.distributed.print.business.util.GoogleBarCodeUtil;
-import com.qmth.distributed.print.business.util.OssUtil;
-import com.qmth.distributed.print.business.util.PdfUtil;
-import com.qmth.distributed.print.business.util.ServletUtil;
+import com.qmth.distributed.print.business.util.*;
 import com.qmth.distributed.print.business.util.excel.ExcelError;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
@@ -33,6 +31,7 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -86,6 +85,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     OssUtil ossUtil;
 
+    @Resource
+    CacheService cacheService;
+
+    @Resource
+    FreemarkerUtil freemarkerUtil;
+
     /**
      * 执行导入用户逻辑
      *
@@ -160,123 +165,129 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 throw ExceptionResultEnum.ERROR.exception("印刷计划为空");
             }
 
+            BasicSchool basicSchool = cacheService.schoolCache(examPrintPlan.getSchoolId());
+
             //查询examDetail
             QueryWrapper<ExamDetail> examDetailQueryWrapper = new QueryWrapper<>();
             examDetailQueryWrapper.lambda().eq(ExamDetail::getSchoolId, sysUser.getSchoolId())
                     .eq(ExamDetail::getPrintPlanId, tbTask.getPrintPlanId());
-            ExamDetail examDetail = detailService.getOne(examDetailQueryWrapper);
-            if (Objects.isNull(examDetail)) {
+            List<ExamDetail> examDetailList = detailService.list(examDetailQueryWrapper);
+            if (Objects.isNull(examDetailList) || examDetailList.size() == 0) {
                 throw ExceptionResultEnum.ERROR.exception("考务计划为空");
             }
             attachmentIds = Objects.isNull(attachmentIds) ? attachmentIds = new HashSet<>() : attachmentIds;
-            if (Objects.nonNull(examDetail.getAttachmentId())) {
-                attachmentIds.add(examDetail.getAttachmentId());
-            }
-
-            //查询examDetailCourse
-            QueryWrapper<ExamDetailCourse> examDetailCourseQueryWrapper = new QueryWrapper<>();
-            examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
-            List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
-
-            List<String> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
-            List<String> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
-            List<String> paperPdfList = new ArrayList<>();//所有试卷
-            List<String> examStudentPdfList = new ArrayList<>();//所有题卡
-            List<String> backupPaperPdfList = new ArrayList<>();//备份试卷
-            List<String> cardPdfList = new ArrayList<>();//备份题卡
-
-            if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
-                //获取普通印品
-                JSONArray jsonArrayOrdinary = JSONArray.parseArray(examPrintPlan.getOrdinaryContent());
-            }
+            for (ExamDetail examDetail : examDetailList) {
+                if (Objects.nonNull(examDetail.getAttachmentId())) {
+                    attachmentIds.add(examDetail.getAttachmentId());
+                }
 
-            for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
-                //查询试卷
-                QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
-                examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
-                        .eq(ExamTask::getCourseCode, examDetailCourse.getCourseCode())
-                        .eq(ExamTask::getCourseName, examDetailCourse.getCourseName())
-                        .eq(ExamTask::getPaperNumber, examDetailCourse.getPaperNumber())
-                        .eq(ExamTask::getEnable, true)
-                        .eq(ExamTask::getStatus, ExamStatusEnum.FINISH);
-                List<ExamTask> examTaskList = examTaskService.list(examTaskQueryWrapper);
-                if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
-                    throw ExceptionResultEnum.ERROR.exception("命题任务为空");
+                //查询examDetailCourse
+                QueryWrapper<ExamDetailCourse> examDetailCourseQueryWrapper = new QueryWrapper<>();
+                examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
+                List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
+
+                List<String> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
+                List<String> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
+                List<String> paperPdfList = new ArrayList<>();//所有试卷
+                List<String> examStudentPdfList = new ArrayList<>();//所有题卡
+                List<String> backupPaperPdfList = new ArrayList<>();//备份试卷
+                List<String> cardPdfList = new ArrayList<>();//备份题卡
+
+                if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
+                    //获取普通印品
+                    JSONArray jsonArrayOrdinary = JSONArray.parseArray(examPrintPlan.getOrdinaryContent());
                 }
-                Set<Long> examTaskIds = examTaskList.stream().map(s -> s.getId()).collect(Collectors.toSet());
-
-                QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
-                examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds)
-                        .eq(ExamTaskDetail::getEnable, true);
-                List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
-                JSONObject jsonObject = new JSONObject();
-                JSONArray jsonArray = new JSONArray();
-                for (ExamTaskDetail examTaskDetail : examTaskDetailList) {
-                    //查询题卡
-                    ExamCard examCard = examCardService.getById(examTaskDetail.getCardId());
-                    if (Objects.isNull(examCard)) {
-                        throw ExceptionResultEnum.ERROR.exception("题卡为空");
+
+                for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
+                    //查询试卷
+                    QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
+                    examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
+                            .eq(ExamTask::getCourseCode, examDetailCourse.getCourseCode())
+                            .eq(ExamTask::getCourseName, examDetailCourse.getCourseName())
+                            .eq(ExamTask::getPaperNumber, examDetailCourse.getPaperNumber())
+                            .eq(ExamTask::getEnable, true)
+                            .eq(ExamTask::getStatus, ExamStatusEnum.FINISH);
+                    List<ExamTask> examTaskList = examTaskService.list(examTaskQueryWrapper);
+                    if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
+                        throw ExceptionResultEnum.ERROR.exception("命题任务为空");
                     }
-                    QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
-                    examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
-                    List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
+                    Set<Long> examTaskIds = examTaskList.stream().map(s -> s.getId()).collect(Collectors.toSet());
+
+                    QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
+                    examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds)
+                            .eq(ExamTaskDetail::getEnable, true);
+                    List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
+                    JSONObject jsonObject = new JSONObject();
+                    JSONArray jsonArray = new JSONArray();
+                    for (ExamTaskDetail examTaskDetail : examTaskDetailList) {
+                        //查询题卡
+                        ExamCard examCard = examCardService.getById(examTaskDetail.getCardId());
+                        if (Objects.isNull(examCard)) {
+                            throw ExceptionResultEnum.ERROR.exception("题卡为空");
+                        }
+                        QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
+                        examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
+                        List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
 
-                    //抽取卷型
-                    String paperType = getPaperType(examPrintPlan, examTaskDetail);
+                        //抽取卷型
+                        String paperType = getPaperType(examPrintPlan, examTaskDetail);
 
-                    //获取试卷pdf
-                    getPaperPdf(examTaskDetail, examPrintPlan.getBackupCount(), paperPdfList, backupPaperPdfList);
+                        //获取试卷pdf
+                        getPaperPdf(examTaskDetail, examPrintPlan.getBackupCount(), paperPdfList, backupPaperPdfList);
 
-                    basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
-                    for (ExamCardDetail examCardDetail : examCardDetailList) {
-                        getCardAttachmentId(examCardDetail, attachmentIds);
+                        basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
+                        for (ExamCardDetail examCardDetail : examCardDetailList) {
+                            getCardAttachmentId(examCardDetail, attachmentIds);
 
-                        //把模板页面上的 ${} 替换成实际内容
-                        String cardContent = replaceHtmlTemplete(examCardDetail);
-                        String studentContent = cardContent;
+                            //把模板页面上的 ${} 替换成实际内容
+                            String cardContent = replaceHtmlTemplete(examCardDetail);
+                            String studentContent = cardContent;
 
-                        for (int i = 1; i <= examPrintPlan.getBackupCount(); i++) {
-                            basicAttachmentList.add(cardHtml(cardContent, paperType, examDetailCourse, examCard, examTaskDetail, jsonArray, sysUser.getId(), cardPdfList));
-                        }
+                            for (int i = 1; i <= examPrintPlan.getBackupCount(); i++) {
+                                basicAttachmentList.add(cardHtml(cardContent, paperType, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfList));
+                            }
 
-                        //查询考生
-                        QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
-                        examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
-                                .eq(ExamStudent::getExamDetailCourseId, examTaskDetail.getId());
-                        List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
+                            //查询考生
+                            QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
+                            examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
+                                    .eq(ExamStudent::getExamDetailCourseId, examTaskDetail.getId());
+                            List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
 
-                        Integer signVariableBackupCount = null, packagVariableBackupCount = null;
-                        for (ExamStudent t : examStudentList) {
+                            Integer signVariableBackupCount = null, packagVariableBackupCount = null;
                             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");
-                                    Long templeteId = (Long) jsonObjectVariable.get("templeteId");
-                                    BasicAttachment basicAttachment = basicAttachmentService.getById(templeteId);
+                                    Long attachmentId = (Long) jsonObjectVariable.get("attachmentId");
+                                    BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
+                                    String htmlContent = new String(commonService.getFileByte(basicAttachment.getPath(), false), StandardCharsets.UTF_8);
+                                    log.info("htmlContent:{}", htmlContent);
                                     if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
                                         signVariableBackupCount = (Integer) jsonObjectVariable.get("backupCount");
-//                                        String filePath = basicAttachment.getPath();
-//                                        ossUtil.ossDownload();
                                     } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAG")) {//卷袋贴
                                         packagVariableBackupCount = (Integer) jsonObjectVariable.get("backupCount");
                                     }
+//                                    createSignBook(basicAttachment, htmlContent, examDetailCourse, basicSchool.getName(), examStudentList, variablePdfList);
+                                    createSignBook(basicAttachment, examDetailCourse, basicSchool.getName(), examStudentList, variablePdfList);
                                 }
                             }
-                            basicAttachmentList.add(examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentPdfList));
+
+                            for (ExamStudent t : examStudentList) {
+                                basicAttachmentList.add(examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentPdfList));
+                            }
+                            examStudentService.saveOrUpdateBatch(examStudentList);
+                            jsonObject.put("card", jsonArray);
+                            examCardDetail.setAttachmentId(jsonObject.toJSONString());
                         }
-                        examStudentService.saveOrUpdateBatch(examStudentList);
-                        jsonObject.put("card", jsonArray);
-                        examCardDetail.setAttachmentId(jsonObject.toJSONString());
+                        examCardDetailService.saveOrUpdateBatch(examCardDetailList);
                     }
-                    examCardDetailService.saveOrUpdateBatch(examCardDetailList);
+                    examTaskDetailService.saveOrUpdateBatch(examTaskDetailList);
                 }
-                examTaskDetailService.saveOrUpdateBatch(examTaskDetailList);
+                //合并pdf
+                basicAttachmentList.add(mergePdf(tbTask, examDetail, sysUser.getId(), variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
             }
-            //合并pdf
-            basicAttachmentList.add(mergePdf(tbTask, examDetail, sysUser.getId(), variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
-
             //最后一步删除附件
             deleteAttachment(attachmentIds);
         } catch (Exception e) {
@@ -291,6 +302,220 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return map;
     }
 
+    /**
+     * 创建签到表
+     *
+     * @param basicAttachment
+     * @param examDetailCourse
+     * @param schoolName
+     * @param examStudentList
+     * @param variablePdfList
+     * @throws IOException
+     */
+    private void createSignBook(BasicAttachment basicAttachment,
+//                                String htmlContent,
+                                ExamDetailCourse examDetailCourse, String schoolName, List<ExamStudent> examStudentList, List<String> variablePdfList) throws IOException {
+        /**html
+         htmlContent = htmlContent.replaceAll("\\$\\{examDetailCourseId\\}", examDetailCourse.getId() + "");
+         htmlContent = htmlContent.replaceAll("\\$\\{schoolName\\}", schoolName);
+         htmlContent = htmlContent.replaceAll("\\$\\{courseName\\}", examDetailCourse.getCourseName());
+         htmlContent = htmlContent.replaceAll("\\$\\{courseCode\\}", examDetailCourse.getCourseCode());
+
+         //        htmlMap.put("examName", exam.getExamName());
+         //        htmlMap.put("examRoom", examDetailMap.get("examRoom"));
+         //        htmlMap.put("examRoomId", examDetailMap.get("examRoomId"));
+         //        htmlMap.put("startTime", examDetailMap.get("startTime"));
+         //        htmlMap.put("endTime", examDetailMap.get("endTime"));
+         //        htmlMap.put("sceneNumberId", examDetailMap.get("sceneNumberId"));
+
+         htmlContent = htmlContent.replaceAll("\\$\\{paperCode\\}", examDetailCourse.getPaperNumber());
+         htmlContent = htmlContent.replaceAll("\\$\\{paperCodeImg\\}", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
+
+         //        List<Map> students = tcPExamStudentService.clientStudentByDetailId(examDetailId);
+
+         //        List<String> extendColumnList = students.stream().map(m -> m.get("extendColumn").toString()).distinct().collect(Collectors.toList());
+         //        Set<String> classTeacher = new HashSet();
+         //        if (extendColumnList != null && 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));
+
+         int totalCount = examStudentList.size();
+         if (totalCount > 0) {
+         //            List<Map> subList = new ArrayList<>();
+         int pageCount = totalCount % 80 == 0 ? totalCount / 80 : totalCount / 80 + 1;
+         for (int i = 0; i < pageCount; i++) {
+         Map subMap = new HashMap();
+         subMap.put("index", i + 1);
+         int studentCount;
+         List<ExamStudent> subStudents;
+         if (pageCount == 1) {
+         studentCount = totalCount;
+         subStudents = examStudentList;
+         } else if (pageCount > 1 && i == pageCount - 1) {
+         studentCount = totalCount - (pageCount - 1) * 80;
+         subStudents = examStudentList.subList(80 * i, examStudentList.size());
+         } else {
+         studentCount = 80;
+         subStudents = examStudentList.subList(80 * i, 80 * (i + 1));
+         }
+         subMap.put("studentCount", studentCount);
+         List<ExamStudentDto> examStudentList1 = new ArrayList<>();
+         List<ExamStudentDto> examStudentList2 = new ArrayList<>();
+
+         Gson gson = new Gson();
+         int mod = subStudents.size() % 2;
+         int htmlTableCount = mod == 0 ? subStudents.size() / 2 : subStudents.size() / 2 + 1;
+         for (int j = 0; j < htmlTableCount; j++) {
+         ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+         examStudentDto.setIndex(j + 1);
+         examStudentList1.add(examStudentDto);
+         //                    Map map = subStudents.get(j);
+         //                    TcPExamStudent tcPExamStudent = new TcPExamStudent();
+         //                    tcPExamStudent.setIndex(j + 1);
+         //                    tcPExamStudent.setSiteNumber(String.valueOf(map.get("siteNumber")));
+         //                    tcPExamStudent.setStudentCode(String.valueOf(map.get("studentCode")));
+         //                    tcPExamStudent.setName(String.valueOf(map.get("name")));
+         //                    tcPExamStudent.setExtendColumn(getClassName(map.get("extendColumn").toString()));
+         //                    tcPExamStudentList1.add(tcPExamStudent);
+         }
+         for (int j = htmlTableCount; j < subStudents.size(); j++) {
+         ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+         examStudentDto.setIndex(j + 1);
+         examStudentList2.add(examStudentDto);
+         //                    Map map = students.get(j);
+         //                    TcPExamStudent tcPExamStudent = new TcPExamStudent();
+         //                    tcPExamStudent.setIndex(j + 1);
+         //                    tcPExamStudent.setSiteNumber(String.valueOf(map.get("siteNumber")));
+         //                    tcPExamStudent.setStudentCode(String.valueOf(map.get("studentCode")));
+         //                    tcPExamStudent.setName(String.valueOf(map.get("name")));
+         //                    tcPExamStudent.setExtendColumn(getClassName(map.get("extendColumn").toString()));
+         //                    tcPExamStudentList2.add(tcPExamStudent);
+         }
+         if (examStudentList1.size() > examStudentList2.size()) {
+         for (int j = subStudents.size() - htmlTableCount; j < examStudentList1.size(); j++) {
+         examStudentList2.add(new ExamStudentDto());
+         }
+         }
+
+         //                subMap.put("studentList1", examStudentList1);
+         //                subMap.put("studentList2", examStudentList2);
+
+         //                  htmlContent = htmlContent.replaceAll("\\$\\{studentList1\\}", examStudentList1);
+         //                  htmlContent = htmlContent.replaceAll("\\$\\{studentList2\\}", examStudentList2);
+
+         //                subList.add(subMap);
+         }
+         //            htmlMap.put("subList", subList);
+         }
+         basicAttachmentService.saveAttachmentPdf(basicAttachment, variablePdfList);
+         **/
+
+        Map<String, Object> htmlMap = new HashMap<>();
+        htmlMap.put("examDetailCourseId", examDetailCourse.getId());
+        htmlMap.put("schoolName", schoolName);
+
+        htmlMap.put("courseName", examDetailCourse.getCourseName());
+        htmlMap.put("courseCode", examDetailCourse.getCourseCode());
+//        htmlMap.put("examName", exam.getExamName());
+//        htmlMap.put("examRoom", examDetailMap.get("examRoom"));
+//        htmlMap.put("examRoomId", examDetailMap.get("examRoomId"));
+//        htmlMap.put("startTime", examDetailMap.get("startTime"));
+//        htmlMap.put("endTime", examDetailMap.get("endTime"));
+//        htmlMap.put("sceneNumberId", examDetailMap.get("sceneNumberId"));
+        htmlMap.put("paperCode", examDetailCourse.getPaperNumber());
+        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetailCourse.getPaperNumber(), false));
+
+//        List<String> extendColumnList = students.stream().map(m -> m.get("extendColumn").toString()).distinct().collect(Collectors.toList());
+//        Set<String> classTeacher = new HashSet();
+//        if (extendColumnList != null && 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));
+
+        int totalCount = examStudentList.size();
+        if (totalCount > 0) {
+            List<Map> subList = new ArrayList<>();
+            int pageCount = totalCount % 80 == 0 ? totalCount / 80 : totalCount / 80 + 1;
+            for (int i = 0; i < pageCount; i++) {
+                Map subMap = new HashMap();
+                subMap.put("index", i + 1);
+                int studentCount;
+                List<ExamStudent> subStudents;
+                if (pageCount == 1) {
+                    studentCount = totalCount;
+                    subStudents = examStudentList;
+                } else if (pageCount > 1 && i == pageCount - 1) {
+                    studentCount = totalCount - (pageCount - 1) * 80;
+                    subStudents = examStudentList.subList(80 * i, examStudentList.size());
+                } else {
+                    studentCount = 80;
+                    subStudents = examStudentList.subList(80 * i, 80 * (i + 1));
+                }
+                subMap.put("studentCount", studentCount);
+                List<ExamStudentDto> examStudentList1 = new ArrayList<>();
+                List<ExamStudentDto> examStudentList2 = new ArrayList<>();
+
+                Gson gson = new Gson();
+                int mod = subStudents.size() % 2;
+                int htmlTableCount = mod == 0 ? subStudents.size() / 2 : subStudents.size() / 2 + 1;
+                for (int j = 0; j < htmlTableCount; j++) {
+                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+                    examStudentDto.setIndex(j + 1);
+                    examStudentList1.add(examStudentDto);
+//                    Map map = subStudents.get(j);
+//                    TcPExamStudent tcPExamStudent = new TcPExamStudent();
+//                    tcPExamStudent.setIndex(j + 1);
+//                    tcPExamStudent.setSiteNumber(String.valueOf(map.get("siteNumber")));
+//                    tcPExamStudent.setStudentCode(String.valueOf(map.get("studentCode")));
+//                    tcPExamStudent.setName(String.valueOf(map.get("name")));
+//                    tcPExamStudent.setExtendColumn(getClassName(map.get("extendColumn").toString()));
+//                    tcPExamStudentList1.add(tcPExamStudent);
+                }
+                for (int j = htmlTableCount; j < subStudents.size(); j++) {
+                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+                    examStudentDto.setIndex(j + 1);
+                    examStudentList2.add(examStudentDto);
+//                    Map map = students.get(j);
+//                    TcPExamStudent tcPExamStudent = new TcPExamStudent();
+//                    tcPExamStudent.setIndex(j + 1);
+//                    tcPExamStudent.setSiteNumber(String.valueOf(map.get("siteNumber")));
+//                    tcPExamStudent.setStudentCode(String.valueOf(map.get("studentCode")));
+//                    tcPExamStudent.setName(String.valueOf(map.get("name")));
+//                    tcPExamStudent.setExtendColumn(getClassName(map.get("extendColumn").toString()));
+//                    tcPExamStudentList2.add(tcPExamStudent);
+                }
+                if (examStudentList1.size() > examStudentList2.size()) {
+                    for (int j = subStudents.size() - htmlTableCount; j < examStudentList1.size(); j++) {
+                        examStudentList2.add(new ExamStudentDto());
+                    }
+                }
+
+                subMap.put("studentList1", examStudentList1);
+                subMap.put("studentList2", examStudentList2);
+                subList.add(subMap);
+            }
+            htmlMap.put("subList", subList);
+        }
+        freemarkerUtil.createSignBook(htmlMap);
+    }
+
+
     /**
      * 替换html通用模版
      *
@@ -372,7 +597,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 paperTypes = unexposedPaperType.split("/");
             }
         } else {
-            if (Objects.isNull(exposedPaperType) || Objects.isNull(unexposedPaperType)) {
+            if (Objects.isNull(exposedPaperType) && Objects.isNull(unexposedPaperType)) {
                 throw ExceptionResultEnum.ERROR.exception("当前没有未曝光的卷型");
             }
             if (Objects.nonNull(unexposedPaperType)) {
@@ -482,14 +707,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
      * @param paperType
      * @param examDetailCourse
      * @param examCard
-     * @param examTaskDetail
      * @param jsonArray
      * @param userId
      * @param cardPdfList
      * @return
      * @throws IOException
      */
-    public BasicAttachment cardHtml(String cardContent, String paperType, ExamDetailCourse examDetailCourse, ExamCard examCard, ExamTaskDetail examTaskDetail, JSONArray jsonArray, Long userId, List<String> cardPdfList) throws IOException {
+    public BasicAttachment cardHtml(String cardContent, String paperType, ExamDetailCourse examDetailCourse, ExamCard examCard, JSONArray jsonArray, Long userId, List<String> cardPdfList) throws IOException {
         //通用题卡
         String cardTemp = cardContent;
         cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", paperType);
@@ -503,7 +727,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, userId, cardPdfList);
         JSONObject object = new JSONObject();
         object.put("name", paperType);
-        object.put("examTaskDetailId", examTaskDetail.getId());
+        object.put("examDetailCourseId", examDetailCourse.getId());
         object.put("attachmentId", cardAttachment.getId());
         jsonArray.add(object);
         return cardAttachment;

+ 122 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java

@@ -0,0 +1,122 @@
+package com.qmth.distributed.print.business.util;
+
+import com.qmth.distributed.print.business.config.DictionaryConfig;
+import com.qmth.distributed.print.business.enums.UploadFileEnum;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ResourceUtils;
+
+import javax.annotation.Resource;
+import java.io.*;
+import java.util.Map;
+import java.util.Objects;
+import java.util.StringJoiner;
+
+/**
+ * @Description: freemarker util
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/11
+ */
+@Component
+public class FreemarkerUtil {
+    private final static Logger log = LoggerFactory.getLogger(FreemarkerUtil.class);
+
+    @Resource
+    DictionaryConfig dictionaryConfig;
+
+    @Resource
+    OssUtil ossUtil;
+
+    /**
+     * 单独生成签到表
+     *
+     * @param dataMap
+     * @throws IOException
+     */
+    public void createSignBook(Map<String, Object> dataMap) throws IOException {
+        if (Objects.isNull(dataMap) || dataMap.size() == 0) {
+            throw ExceptionResultEnum.ERROR.exception("签到表数据为空");
+        }
+        Configuration configuration = new Configuration(Configuration.VERSION_2_3_29);
+        if (SystemConstant.TEMP_FILES_DIR.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+            File templates = ResourceUtils.getFile(SystemConstant.TEMP_FILES_DIR);
+            configuration.setDirectoryForTemplateLoading(templates);
+        } else {
+//            templates = new File(dictionaryConfig.sysDomain().getFreemarkerPath());
+            configuration.setClassForTemplateLoading(this.getClass(), SystemConstant.TEMP_FILES_DIR);//classes下读取
+        }
+        this.createSignBookAndPaperPackageHtml(configuration, "signBook", (String) dataMap.get("schoolName"), dataMap);
+    }
+
+    /**
+     * 单独生成签到表
+     *
+     * @param dataMap
+     * @throws IOException
+     */
+    public void createPaperPackage(Map<String, Object> dataMap) throws IOException {
+        if (Objects.isNull(dataMap) || dataMap.size() == 0) {
+            throw ExceptionResultEnum.ERROR.exception("卷袋贴数据为空");
+        }
+        Configuration configuration = new Configuration(Configuration.VERSION_2_3_29);
+        if (SystemConstant.TEMP_FILES_DIR.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+            File templates = ResourceUtils.getFile(SystemConstant.TEMP_FILES_DIR);
+            configuration.setDirectoryForTemplateLoading(templates);
+        } else {
+//            templates = new File(dictionaryConfig.sysDomain().getFreemarkerPath());
+            configuration.setClassForTemplateLoading(this.getClass(), SystemConstant.TEMP_FILES_DIR);//classes下读取
+        }
+        this.createSignBookAndPaperPackageHtml(configuration, "paperPackage", (String) dataMap.get("schoolName"), dataMap);
+    }
+
+    /**
+     * 创建签到表
+     *
+     * @param configuration
+     * @param schoolName
+     * @param dataMap
+     * @throws IOException
+     */
+    private void createSignBookAndPaperPackageHtml(Configuration configuration, String ftlName, String schoolName, Map<String, Object> dataMap) throws IOException {
+        Writer out = null;
+        try {
+            // step1 加载模版文件
+            Template template = configuration.getTemplate(ftlName + ".ftl");
+            // step2 生成数据
+            String serverUpload = dictionaryConfig.sysDomain().getServerUpload();
+            File mkdir = null;
+            if (Objects.nonNull(serverUpload) && !Objects.equals(serverUpload, "")) {
+                mkdir = new File(serverUpload + File.separator + UploadFileEnum.HTML.name());
+                if (!mkdir.exists()) {
+                    mkdir.mkdirs();
+                }
+            }
+            File htmlFile = new File(new StringJoiner("").add(mkdir.toString()).add(File.separator).add(schoolName).add(ftlName).add(".html").toString());
+            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile)));
+            // step3 输出文件
+            template.process(dataMap, out);
+            out.flush();
+            boolean oss = dictionaryConfig.sysDomain().isOss();
+            if (oss) {
+                StringJoiner stringJoiner = new StringJoiner("").add(UploadFileEnum.HTML.name())
+                        .add(File.separator).add(schoolName).add(htmlFile.getName());
+                ossUtil.ossUpload(stringJoiner.toString(), new FileInputStream(htmlFile), DigestUtils.md5Hex(new FileInputStream(htmlFile)));
+            }
+            log.info("{}文件创建成功", htmlFile.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (Objects.nonNull(out)) {
+                out.close();
+            }
+        }
+    }
+}

+ 7 - 0
distributed-print-common/src/main/java/com/qmth/distributed/print/common/contant/SystemConstant.java

@@ -28,6 +28,7 @@ public class SystemConstant {
     public static final String USER_DIR = "user.dir";
     public static final String PDF_TEMP = "pdf-temp";
     public static final String FILE_TEMP = "file-temp";
+    public static final String FTL_TEMP = "ftl-temp";
     public static final String DOWNLOAD_TEMP = "download-temp";
     public static final String SESSION = "session:";
     public static final String TASK = "task";
@@ -101,6 +102,7 @@ public class SystemConstant {
     /**
      * 变量
      */
+    public static String ftl_FILES_DIR;
     public static String TEMP_FILES_DIR;
     public static String PDF_TEMP_FILES_DIR;
 
@@ -124,8 +126,13 @@ public class SystemConstant {
         if (!pdfTempDir.exists()) {
             pdfTempDir.mkdirs();
         }
+        File ftlTempDir = new File(new StringBuffer(mkdir).append(File.separator).append(FTL_TEMP).toString());
+        if (!ftlTempDir.exists()) {
+            ftlTempDir.mkdirs();
+        }
         TEMP_FILES_DIR = fileTempDir.getPath();
         PDF_TEMP_FILES_DIR = pdfTempDir.getPath();
+        ftl_FILES_DIR = ftlTempDir.getPath();
     }
 
     /**

+ 6 - 0
pom.xml

@@ -42,6 +42,7 @@
         <netty-all.version>4.1.49.Final</netty-all.version>
         <itextpdf.version>5.5.13</itextpdf.version>
         <googleBar.version>3.4.0</googleBar.version>
+        <freemarker.version>2.3.30</freemarker.version>
     </properties>
 
     <dependencyManagement>
@@ -224,6 +225,11 @@
                 <artifactId>javase</artifactId>
                 <version>${googleBar.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.freemarker</groupId>
+                <artifactId>freemarker</artifactId>
+                <version>${freemarker.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>