ソースを参照

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

 Conflicts:
	distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfUtil.java
xiaof 2 年 前
コミット
9d09b6754d

+ 14 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicTemplateServiceImpl.java

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.business.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -31,14 +32,15 @@ import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.service.TeachcloudCommonService;
+import com.qmth.teachcloud.common.util.FileStoreUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.time.LocalDateTime;
 import java.util.List;
@@ -75,6 +77,9 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
     @Resource
     DictionaryConfig dictionaryConfig;
 
+    @Resource
+    FileStoreUtil fileStoreUtil;
+
     @Override
     public IPage<TemplateDto> list(Boolean enable, String type, String name, Long startTime, Long endTime, Integer pageNumber, Integer pageSize) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
@@ -106,6 +111,14 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
             if (basicTemplate != null && basicTemplate.getId().longValue() != template.getId().longValue()) {
                 throw ExceptionResultEnum.ERROR.exception("模板名称已存在");
             }
+            if (StringUtils.isNotBlank((basicTemplate.getPreviewPath()))) {
+                JSONObject jsonObject = JSONObject.parseObject(basicTemplate.getPreviewPath());
+                String type = jsonObject.getString(SystemConstant.TYPE);
+                if (Objects.nonNull(type) && type.equalsIgnoreCase(SystemConstant.LOCAL)) {
+                    FileUtils.forceDelete(new File(jsonObject.getString(SystemConstant.PATH)));
+                }
+            }
+
             template.setPreviewPath("");
             template.updateInfo(sysUser.getId());
             //删除权限

+ 11 - 20
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -949,7 +949,6 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
 
     @Override
     public void paperDownload(HttpServletResponse response, Long examTaskId) throws Exception {
-        String schoolId = ServletUtil.getRequestHeaderSchoolId().toString();
         ExamTask examTask = this.getById(examTaskId);
         QueryWrapper<ExamTaskDetail> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, examTaskId);
@@ -976,23 +975,15 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                 File file = teachcloudCommonService.copyFile(paperPath, fileName, attachment);
                 fileList.add(file);
             }
-        }
 
-        // 题卡
-//        Long cardId = examTaskDetail.getCardId();
-        if (Objects.nonNull(examTaskDetail.getPaperAttachmentIds())) {
-            JSONArray jsonArrayPaper = JSONArray.parseArray(examTaskDetail.getPaperAttachmentIds());
-            String cardId = null;
-            for (int i = 0; i < jsonArrayPaper.size(); i++) {
-                JSONObject object = jsonArrayPaper.getJSONObject(i);
-                cardId = (String) object.get("cardId");
-            }
+            // 题卡
+            Long cardId = Long.parseLong(jsonObject.getString("cardId"));
             if (cardId != null) {
                 ExamCard examCard = examCardService.getById(cardId);
 
                 String cardPath = rootPath + File.separator + examTask.getPaperNumber();
-                String cardHtmlPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + SystemConstant.HTML_PREFIX;
-                String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + SystemConstant.PDF_PREFIX;
+                String cardHtmlPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + "_" + name + SystemConstant.HTML_PREFIX;
+                String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + "_" + name + SystemConstant.PDF_PREFIX;
 
                 ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
                 String htmlContent;
@@ -1734,13 +1725,11 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         }
         SysOrg schoolOrg = schoolOrgList.get(0);
         List<SysOrg> collegeList = orgList.stream().filter(e -> Objects.equals(schoolOrg.getId(), e.getParentId())).collect(Collectors.toList());
-        if (collegeList.size() != 1) {
-            throw ExceptionResultEnum.ERROR.exception("学院级机构信息异常");
+        SysOrg college = new SysOrg();
+        if (collegeList.size() == 1){
+            college = collegeList.get(0);
         }
 
-        SysOrg college = collegeList.get(0);
-
-
         // 流程id
         Long flowId = examTask.getFlowId();
 
@@ -1763,8 +1752,10 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         // ---- 组装Dto
         ExamTaskApprovalFormDto examTaskApprovalFormDto = new ExamTaskApprovalFormDto();
         BasicInfo basicInfo = new BasicInfo();
-        basicInfo.setCollegeId(college.getId());
-        basicInfo.setCollegeName(college.getName());
+        if (Objects.nonNull(college)){
+            basicInfo.setCollegeId(college.getId());
+            basicInfo.setCollegeName(college.getName());
+        }
         basicInfo.setTeachingRoomId(teachingRoomId);
         basicInfo.setTeachingRoomName(teachingRoomName);
         basicInfo.setPaperName(paperName);

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

@@ -387,58 +387,63 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     // 题卡数据组装
                     basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
                     if (printContent.contains("CARD")) {
-                        QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
-                        examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
-                        ExamCardDetail examCardDetail = examCardDetailService.getOne(examCardDetailQueryWrapper);
+                        for (String s : paperTypes) {
+                            examCard = examCardMap.get(s);
+                            Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("卷型" + s + "题卡不存在"));
 
-                        createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
+                            QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
+                            examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
+                            ExamCardDetail examCardDetail = examCardDetailService.getOne(examCardDetailQueryWrapper);
 
-                        //把模板页面上的 ${} 替换成实际内容
-                        String cardContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
+                            createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
 
-                        for (int i = 1; i <= backupCount; i++) {
-                            BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule);
-                            examDetailCourse.setCardPagesA3(basicAttachment.getPages());
-                            basicAttachmentList.add(basicAttachment);
-                        }
-                        // 备用题卡
-                        list[1].addAll(backupCardPdfList);
+                            //把模板页面上的 ${} 替换成实际内容
+                            String cardContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
 
-                        if (examStudentList != null && examStudentList.size() > 0) {
-                            for (ExamStudent t : examStudentList) {
-                                // 用带条码的模板
-                                basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetail.getHtmlContent(), t, paperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
+                            for (int i = 1; i <= backupCount; i++) {
+                                BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule);
+                                examDetailCourse.setCardPagesA3(basicAttachment.getPages());
+                                basicAttachmentList.add(basicAttachment);
                             }
-                        } else if (examDetail.getPrintCount() != null) {
-                            AtomicInteger atomicInteger = new AtomicInteger(0);
-                            Map<String, BasicAttachment> stringBasicAttachmentMap = new HashMap<>();
-                            int i = 0;
-                            while (i < examDetail.getPrintCount()) {
-                                int seq = atomicInteger.getAndIncrement();
-                                int mod = seq % examTaskDetail.getDrawCount();
-                                String tempPaperType = paperTypes.get(mod);
-                                BasicAttachment basicAttachment = createPdfUtil.examStudentHtml(cardContent, null, tempPaperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule);
-
-                                if (!stringBasicAttachmentMap.containsKey(tempPaperType)) {
-                                    stringBasicAttachmentMap.put(tempPaperType, basicAttachment);
-                                    JSONObject object = new JSONObject();
-                                    object.put("name", tempPaperType);
-                                    object.put("attachmentId", basicAttachment.getId());
-                                    stuJsonArray.add(object);
-
-                                    // 用不带条码的模板
-                                    basicAttachmentList.add(basicAttachment);
+                            // 备用题卡
+                            list[1].addAll(backupCardPdfList);
+
+                            if (examStudentList != null && examStudentList.size() > 0) {
+                                for (ExamStudent t : examStudentList) {
+                                    // 用带条码的模板
+                                    basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetail.getHtmlContent(), t, s, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
                                 }
-                                i++;
+                            } else if (examDetail.getPrintCount() != null) {
+                                AtomicInteger atomicInteger = new AtomicInteger(0);
+                                Map<String, BasicAttachment> stringBasicAttachmentMap = new HashMap<>();
+                                int i = 0;
+                                while (i < examDetail.getPrintCount()) {
+                                    int seq = atomicInteger.getAndIncrement();
+                                    int mod = seq % examTaskDetail.getDrawCount();
+                                    String tempPaperType = paperTypes.get(mod);
+                                    BasicAttachment basicAttachment = createPdfUtil.examStudentHtml(cardContent, null, tempPaperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule);
+
+                                    if (!stringBasicAttachmentMap.containsKey(tempPaperType)) {
+                                        stringBasicAttachmentMap.put(tempPaperType, basicAttachment);
+                                        JSONObject object = new JSONObject();
+                                        object.put("name", tempPaperType);
+                                        object.put("attachmentId", basicAttachment.getId());
+                                        stuJsonArray.add(object);
+
+                                        // 用不带条码的模板
+                                        basicAttachmentList.add(basicAttachment);
+                                    }
+                                    i++;
+                                }
+                            } else {
+                                throw ExceptionResultEnum.ERROR.exception("数据错误:未找到考生或者印刷数量");
                             }
-                        } else {
-                            throw ExceptionResultEnum.ERROR.exception("数据错误:未找到考生或者印刷数量");
+                            // 题卡
+                            list[3].addAll(studentCardPdfList);
+                            jsonObject.put("card", jsonArray);
+                            examDetailCourse.setAttachmentId(jsonObject.toJSONString());
+                            examDetailCourse.setCommonAttachmentId(stuJsonArray.toJSONString());
                         }
-                        // 题卡
-                        list[3].addAll(studentCardPdfList);
-                        jsonObject.put("card", jsonArray);
-                        examDetailCourse.setAttachmentId(jsonObject.toJSONString());
-                        examDetailCourse.setCommonAttachmentId(stuJsonArray.toJSONString());
                     }
                     examStudentService.saveOrUpdateBatch(examStudentList);
                 }
@@ -1022,10 +1027,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 Long attachmentId = paperInfo.getAttachmentId();
                 Long cardId = paperInfo.getCardId();
                 String paperType = paperInfo.getName();
-                if (SystemConstant.longNotNull(attachmentId)){
+                if (SystemConstant.longNotNull(attachmentId)) {
                     attPaperIds.add(attachmentId);
                 }
-                if (SystemConstant.longNotNull(cardId)){
+                if (SystemConstant.longNotNull(cardId)) {
                     ExamCardDto examCardDto = new ExamCardDto();
                     examCardDto.setCardId(cardId);
                     examCardDto.setPaperType(paperType);
@@ -1094,7 +1099,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
                     // 题卡路径
                     String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
-                    if (SystemConstant.strNotNull(paperType)){
+                    if (SystemConstant.strNotNull(paperType)) {
                         cardPath = cardPath + "(" + paperType + ")";
                     }
                     UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
@@ -1115,7 +1120,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
                     // 题卡路径
                     String cardPath = firstPath + File.separator + "题卡" + File.separator + examCard.getTitle();
-                    if (SystemConstant.strNotNull(paperType)){
+                    if (SystemConstant.strNotNull(paperType)) {
                         cardPath = cardPath + "(" + paperType + ")";
                     }
                     cardPath = cardPath + SystemConstant.HTML_PREFIX;

+ 13 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/Zip4jUtil.java

@@ -130,10 +130,18 @@ public class Zip4jUtil {
      */
     private static void commonUnZipFile(String scrPath, String destPath, String password) {
         try {
+            File file = new File(scrPath);
+            if (!file.exists()) {
+                file.getParentFile().mkdirs();
+            }
             ZipFile zipFile = new ZipFile(scrPath);
             if (Objects.nonNull(password) && zipFile.isEncrypted()) {
                 zipFile.setPassword(password);
             }
+            File currentFile = new File(destPath);
+            if (!currentFile.exists()) {
+                throw ExceptionResultEnum.ERROR.exception("待解压的路径不存在");
+            }
             zipFile.extractAll(destPath);
         } catch (ZipException e) {
             log.error(SystemConstant.LOG_ERROR, e);
@@ -151,6 +159,10 @@ public class Zip4jUtil {
      */
     private static void commonZipFile(String scrPath, String destPath, List<File> files, String password) {
         try {
+            File file = new File(scrPath);
+            if (!file.exists()) {
+                file.getParentFile().mkdirs();
+            }
             // 生成的压缩文件
             ZipFile zipFile = new ZipFile(scrPath);
             ZipParameters parameters = new ZipParameters();
@@ -168,7 +180,7 @@ public class Zip4jUtil {
             File[] fs = null;
             if (!CollectionUtil.isEmpty(files)) {
                 // 要打包的文件夹
-                fs = files.toArray(new File[0]);
+                fs = files.toArray(new File[files.size()]);
             } else if (Objects.nonNull(destPath)) {
                 File currentFile = new File(destPath);
                 if (!currentFile.exists()) {