xiaofei hai 10 meses
pai
achega
2978a1cb27

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

@@ -27,10 +27,12 @@ import com.qmth.distributed.print.business.mapper.ExamTaskMapper;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.execute.AsyncPaperReviewPdfExportService;
 import com.qmth.distributed.print.business.util.CreatePdfUtil;
+import com.qmth.distributed.print.business.util.HtmlToJpgUtil;
 import com.qmth.distributed.print.business.util.PdfUtil;
 import com.qmth.teachcloud.common.bean.dto.AssignTeacherDto;
 import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
 import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
+import com.qmth.teachcloud.common.bean.marking.ConvertJpgStorage;
 import com.qmth.teachcloud.common.bean.result.SysUserResult;
 import com.qmth.teachcloud.common.bean.result.TbTaskDetailResult;
 import com.qmth.teachcloud.common.bean.tiku.TikuPaperInfo;
@@ -108,6 +110,8 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Resource
     private ExamDetailService examDetailService;
     @Resource
+    private HtmlToJpgUtil htmlToJpgUtil;
+    @Resource
     TBTaskService tbTaskService;
     @Resource
     private TBTaskPdfService tbTaskPdfService;
@@ -1096,6 +1100,19 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             examTaskDetail.setUnexposedPaperType(examTaskDetail.getPaperType());
             examTaskDetail.setExamTaskId(examTask.getId());
             examTaskDetail.insertInfo(sysUser.getId());
+            List<PaperInfoVo> filePathVoList = examTaskDetail.getPaperInfoVoList(null);
+            for (PaperInfoVo paperInfoVo : filePathVoList) {
+                BasicAttachment basicAttachment = basicAttachmentService.getById(paperInfoVo.getAttachmentId());
+                FilePathVo  filePathVo = JSON.parseObject(basicAttachment.getPath(), FilePathVo.class);
+                InputStream inputStream = fileUploadService.downloadFile(filePathVo.getPath(), filePathVo.getUploadType(), filePathVo.getType());
+                List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertPdfToJpg(Long.valueOf(paperInfoVo.getAttachmentId()), inputStream, sysUser.getId());
+                if (convertJpgStorageList.size() > 0) {
+                    paperInfoVo.setJpgAttachmentId(JSON.toJSONString(convertJpgStorageList));
+                } else {
+                    paperInfoVo.setJpgAttachmentId(null);
+                }
+            }
+            examTaskDetail.setPaperAttachmentIds(JSON.toJSONString(filePathVoList));
             examTaskDetailService.save(examTaskDetail);
 
             String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();

+ 34 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/HtmlToJpgUtil.java

@@ -9,12 +9,14 @@ import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.service.FileUploadService;
 import com.qmth.teachcloud.common.util.ConvertUtil;
+import jdk.internal.util.xml.impl.Input;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.io.File;
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
@@ -65,4 +67,36 @@ public class HtmlToJpgUtil {
         }
         return convertJpgStorages;
     }
+
+    /**
+     * pdf转图片
+     *
+     * @param id
+     * @param inputStream
+     * @param userId
+     * @return
+     */
+    public List<ConvertJpgStorage> convertPdfToJpg(Long id, InputStream inputStream, Long userId) {
+        // jpg临时路径
+        List<ConvertJpgStorage> convertJpgStorages = new ArrayList<>();
+        List<BasicAttachment> basicAttachmentList = new ArrayList<>();
+        // html
+        try {
+            // pdf文件转jpg
+            List<File> jpgFileList = ConvertUtil.pdfToImageFile(inputStream);
+            for (int i = 0; i < jpgFileList.size(); i++) {
+                int index = i + 1;
+                String fileName = id + "-" + index + SystemConstant.JPG_PREFIX;
+                FilePathVo filePathVo = fileUploadService.uploadFile(jpgFileList.get(i), UploadFileEnum.IMAGE, fileName);
+                BasicAttachment basicAttachment = new BasicAttachment(JSON.toJSONString(filePathVo), fileName, SystemConstant.JPG_PREFIX, new BigDecimal(inputStream.available()), filePathVo.getMd5(), userId);
+                basicAttachmentService.save(basicAttachment);
+                basicAttachmentList.add(basicAttachment);
+
+                convertJpgStorages.add(new ConvertJpgStorage(basicAttachment.getId(), index));
+            }
+        } catch (Exception e) {
+            basicAttachmentService.batchDeleteAttachment(basicAttachmentList);
+        }
+        return convertJpgStorages;
+    }
 }

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/admin/SysToolsController.java

@@ -34,7 +34,7 @@ public class SysToolsController {
     @RequestMapping(value = "/upload", method = RequestMethod.POST)
     public Result upload(@ApiParam(value = "上传文件", required = true) @RequestParam(value = "file") MultipartFile file,
                         @ApiParam(value = "文件MD5", required = true) @RequestParam(value = "md5") String md5,
-                        @ApiParam(value = "工具类型", required = true) @RequestParam(value = "type") ToolsTypeEnum type) {
+                        @ApiParam(value = "工具类型", required = true) @RequestParam(value = "type", defaultValue = "PICTURE_DOWNLOAD") ToolsTypeEnum type) {
         sysToolsService.upload(file, md5, type);
         return ResultUtil.ok(true);
     }

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/mark/MarkSettingController.java

@@ -222,7 +222,7 @@ public class MarkSettingController {
                                  @ApiParam(value = "md5", required = true) @RequestParam String md5) {
         BasicExam basicExam = basicExamService.getById(examId);
         if (basicExam == null || !ExamModelEnum.MODEL4.equals(basicExam.getExamModel())) {
-            throw ExceptionResultEnum.ERROR.exception("当前考试无法使用此功能");
+            throw ExceptionResultEnum.ERROR.exception("数据包导入方式仅支持模式4考试");
         }
         markPaperService.importCardJsonData(examId, file, md5);
         return ResultUtil.success(true);

+ 9 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/vo/PaperInfoVo.java

@@ -4,6 +4,7 @@ public class PaperInfoVo {
 
     private String name;
     private String attachmentId;
+    private String jpgAttachmentId;
     private Long paperId;
     private String uuid;
     private String cardId;
@@ -33,6 +34,14 @@ public class PaperInfoVo {
         this.attachmentId = attachmentId;
     }
 
+    public String getJpgAttachmentId() {
+        return jpgAttachmentId;
+    }
+
+    public void setJpgAttachmentId(String jpgAttachmentId) {
+        this.jpgAttachmentId = jpgAttachmentId;
+    }
+
     public Long getPaperId() {
         return paperId;
     }

+ 7 - 6
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/ConvertUtil.java

@@ -562,15 +562,16 @@ public class ConvertUtil {
     }
 
     public static List<File> pdfToImageFile(File pdfFile) throws Exception {
+        return pdfToImageFile(new FileInputStream(pdfFile));
+    }
+
+    public static List<File> pdfToImageFile(InputStream inputStream) throws Exception {
         PDDocument doc = null;
         ByteArrayOutputStream os = null;
-        InputStream stream = null;
         List<File> fileList = new ArrayList<>();
         try {
-            // pdf路径
-            stream = new FileInputStream(pdfFile);
             // 加载解析PDF文件
-            doc = PDDocument.load(stream);
+            doc = PDDocument.load(inputStream);
             PDFRenderer pdfRenderer = new PDFRenderer(doc);
             PDPageTree pages = doc.getPages();
             int pageCount = pages.getCount();
@@ -598,8 +599,8 @@ public class ConvertUtil {
             if (os != null) {
                 os.close();
             }
-            if (stream != null) {
-                stream.close();
+            if (inputStream != null) {
+                inputStream.close();
             }
         }
         return fileList;

+ 12 - 18
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/bean/cardJson/Description.java

@@ -1,32 +1,26 @@
 package com.qmth.teachcloud.mark.bean.cardJson;
 
-import org.apache.commons.collections4.CollectionUtils;
-
-import java.util.ArrayList;
 import java.util.List;
 
 public class Description {
 
-    private List<DescriptionCode> list;
+    private String code;
+    private List<DescriptionCourse> courses;
+
+    public String getCode() {
+        return code;
+    }
 
-    public List<DescriptionCode> getList() {
-        return list;
+    public void setCode(String code) {
+        this.code = code;
     }
 
-    public void setList(List<DescriptionCode> list) {
-        this.list = list;
+    public List<DescriptionCourse> getCourses() {
+        return courses;
     }
 
-    public List<CourseCard> getCourseCardList() {
-        List<CourseCard> courseCardList = new ArrayList<>();
-        if (CollectionUtils.isNotEmpty(list)) {
-            for (DescriptionCode descriptionCode : list) {
-                for (DescriptionCourse course : descriptionCode.getCourses()) {
-                    courseCardList.add(new CourseCard(descriptionCode.getCode(), course.getCode(), course.getName()));
-                }
-            }
-        }
-        return courseCardList;
+    public void setCourses(List<DescriptionCourse> courses) {
+        this.courses = courses;
     }
 
 }

+ 0 - 25
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/bean/cardJson/DescriptionCode.java

@@ -1,25 +0,0 @@
-package com.qmth.teachcloud.mark.bean.cardJson;
-
-import java.util.List;
-
-public class DescriptionCode {
-
-    private String code;
-    private List<DescriptionCourse> courses;
-
-    public String getCode() {
-        return code;
-    }
-
-    public void setCode(String code) {
-        this.code = code;
-    }
-
-    public List<DescriptionCourse> getCourses() {
-        return courses;
-    }
-
-    public void setCourses(List<DescriptionCourse> courses) {
-        this.courses = courses;
-    }
-}

+ 17 - 4
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkPaperServiceImpl.java

@@ -38,6 +38,7 @@ import com.qmth.teachcloud.mark.bean.archivescore.ArchiveScoreQuery;
 import com.qmth.teachcloud.mark.bean.archivescore.ArchiveScoreVo;
 import com.qmth.teachcloud.mark.bean.cardJson.CourseCard;
 import com.qmth.teachcloud.mark.bean.cardJson.Description;
+import com.qmth.teachcloud.mark.bean.cardJson.DescriptionCourse;
 import com.qmth.teachcloud.mark.bean.document.ArchivePaperQuery;
 import com.qmth.teachcloud.mark.bean.document.ArchivePaperVo;
 import com.qmth.teachcloud.mark.bean.vo.parseCard.Struct;
@@ -536,16 +537,24 @@ public class MarkPaperServiceImpl extends ServiceImpl<MarkPaperMapper, MarkPaper
             parentDirVar = SystemConstant.getFileTempDirVar(SystemConstant.ZIP_PREFIX);
             FileUtils.copyToFile(file.getInputStream(), parentDirVar);
             ZipReader zipReader = new ZipReader(parentDirVar);
+            String zipRoot = "cards";
             String descriptionJson = "description.json";
 
             // 读取指定文件内容description.json
-            String descriptionContent = SystemConstant.readJson(zipReader.read(descriptionJson));
+            String descriptionContent = SystemConstant.readJson(zipReader.read(zipRoot + "/" + descriptionJson));
             if (StringUtils.isBlank(descriptionContent)) {
                 throw ExceptionResultEnum.ERROR.exception("数据包description.json文件内容为空");
             }
             // 解析description.json内容
-            Description description = JSON.parseObject(descriptionContent, Description.class);
-            List<CourseCard> courseCardList = description.getCourseCardList();
+            List<Description> descriptionList = JSON.parseArray(descriptionContent, Description.class);
+            List<CourseCard> courseCardList = new ArrayList<>();
+            if (CollectionUtils.isNotEmpty(descriptionList)) {
+                for (Description description : descriptionList) {
+                    for (DescriptionCourse course : description.getCourses()) {
+                        courseCardList.add(new CourseCard(description.getCode(), course.getCode(), course.getName()));
+                    }
+                }
+            }
             if (CollectionUtils.isEmpty(courseCardList)) {
                 throw ExceptionResultEnum.ERROR.exception("没有可导入文件");
             }
@@ -555,7 +564,7 @@ public class MarkPaperServiceImpl extends ServiceImpl<MarkPaperMapper, MarkPaper
             for (Map.Entry<String, CourseCard> entry : courseCardMap.entrySet()) {
                 String courseCode = entry.getKey();
                 CourseCard courseCard = entry.getValue();
-                String jsonFileName = courseCard.getCode() + SystemConstant.ZIP_PREFIX;
+                String jsonFileName = zipRoot + "/" + courseCard.getCode() + SystemConstant.JSON_PREFIX;
                 String jsonContent = SystemConstant.readJson(zipReader.read(jsonFileName));
 
                 // 解析试卷结构,结构为空,跳过导入
@@ -582,6 +591,10 @@ public class MarkPaperServiceImpl extends ServiceImpl<MarkPaperMapper, MarkPaper
                     throw ExceptionResultEnum.ERROR.exception(String.format("课程[%s(%s)]存在多个试卷", courseCard.getCourseName(), courseCard.getCourseCode()));
                 }
                 MarkPaper markPaper = markPaperList.get(0);
+                // 结束阅卷,跳过导入
+                if(MarkPaperStatus.FINISH.equals(markPaper.getStatus())){
+                    continue;
+                }
 
                 List<ScanAnswerCard> scanAnswerCardList = scanAnswerCardService.listByExamIdAndPaperNumber(examId, markPaper.getPaperNumber());
                 // 已创建自定义卡格式,跳过导入

+ 1 - 1
teachcloud-mark/src/main/resources/mapper/MarkRejectHistoryMapper.xml

@@ -44,7 +44,7 @@
                         and group_number = #{groupNumber}
                     </if>
                     <if test="studentCode != null and studentCode != ''">
-                        and student_code = #{studentCode}
+                        and student_code like concat('%', #{studentCode}, '%')
                     </if>
                     <if test="secretNumber != null and secretNumber != ''">
                         and secret_number = #{secretNumber}

+ 1 - 1
teachcloud-mark/src/main/resources/mapper/MarkTaskMapper.xml

@@ -317,7 +317,7 @@
                         and group_number = #{groupNumber}
                     </if>
                     <if test="studentCode != null and studentCode != ''">
-                        and student_code = #{studentCode}
+                        and student_code like concat('%', #{studentCode}, '%')
                     </if>
                     <if test="secretNumber != null and secretNumber != ''">
                         and secret_number = #{secretNumber}