浏览代码

Merge remote-tracking branch 'origin/dev_v3.3.1' into dev_v3.3.1

wangliang 1 年之前
父节点
当前提交
759c0330db

+ 8 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/marking/ConvertJpgStorage.java

@@ -14,6 +14,14 @@ public class ConvertJpgStorage {
     @ApiModelProperty("jpg是题卡的第几页")
     private Integer index;
 
+    public ConvertJpgStorage() {
+    }
+
+    public ConvertJpgStorage(Long attachmentId, Integer index) {
+        this.attachmentId = attachmentId;
+        this.index = index;
+    }
+
     public Long getAttachmentId() {
         return attachmentId;
     }

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamCard.java

@@ -102,6 +102,9 @@ public class ExamCard extends BaseEntity implements Serializable {
     @TableField(value = "jpg_attachment", updateStrategy = FieldStrategy.IGNORED)
     private String jpgAttachment;
 
+    @TableField(value = "blank_card_path", updateStrategy = FieldStrategy.IGNORED)
+    private String blankCardPath;
+
     @TableField(exist = false)
     private List<SysOrg> orgs;
     @TableField(exist = false)
@@ -271,6 +274,14 @@ public class ExamCard extends BaseEntity implements Serializable {
         this.jpgAttachment = jpgAttachment;
     }
 
+    public String getBlankCardPath() {
+        return blankCardPath;
+    }
+
+    public void setBlankCardPath(String blankCardPath) {
+        this.blankCardPath = blankCardPath;
+    }
+
     public List<String> getImageUrls() {
         return imageUrls;
     }

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

@@ -44,4 +44,6 @@ public interface ExamCardService extends IService<ExamCard> {
     void cardDownload(HttpServletResponse response, String id);
 
     List<CardJpgResult> listCardImage(Long examId, String paperNumber, String paperType);
+
+    ExamCard createJpgImage(ExamCard examCard);
 }

+ 49 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ClientServiceImpl.java

@@ -1,10 +1,12 @@
 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;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.distributed.print.business.bean.createPdf.PrintPathVo;
 import com.qmth.distributed.print.business.bean.dto.*;
 import com.qmth.distributed.print.business.bean.dto.client.PrintSingleDto;
 import com.qmth.distributed.print.business.bean.dto.client.UrlMd5Dto;
@@ -14,6 +16,7 @@ import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.mapper.ClientMapper;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.bean.dto.SchoolDto;
+import com.qmth.teachcloud.common.bean.vo.FilePathVo;
 import com.qmth.teachcloud.common.bean.vo.PaperInfoVo;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
@@ -65,6 +68,8 @@ public class ClientServiceImpl implements ClientService {
     @Resource
     private ExamStudentService examStudentService;
     @Resource
+    private ExamCardService examCardService;
+    @Resource
     private TeachcloudCommonService teachcloudCommonService;
     @Resource
     private SysPrivilegeService sysPrivilegeService;
@@ -780,18 +785,58 @@ public class ClientServiceImpl implements ClientService {
         IPage<PrintSingleDto> clientExamTaskDtoList = clientMapper.pagePrintSingleData(page, semesterId, examId, printPlanId, courseCode, paperNumber, examDetailStatus);
         for (PrintSingleDto record : clientExamTaskDtoList.getRecords()) {
             ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamIdAndCourseCodeAndPaperNumber(record.getExamId(), record.getCourseCode(), record.getPaperNumber());
-            // 试卷
             List<PaperInfoVo> paperInfoVoList = examTaskDetail.getPaperInfoVoList(record.getPaperType());
+            // 试卷
             List<UrlMd5Dto> paperList = new ArrayList<>();
+            // 题卡
+            List<UrlMd5Dto> cardList = new ArrayList<>();
             for (PaperInfoVo paperInfoVo : paperInfoVoList) {
                 BasicAttachment basicAttachment = basicAttachmentService.getById(paperInfoVo.getAttachmentId());
-                String url = teachcloudCommonService.filePreview(paperInfoVo.getAttachmentId());
+                String url = teachcloudCommonService.filePreview(Long.valueOf(paperInfoVo.getAttachmentId()));
                 paperList.add(new UrlMd5Dto(url, basicAttachment.getMd5()));
+                ExamCard examCard = examCardService.getById(paperInfoVo.getCardId());
+                if(StringUtils.isBlank(examCard.getBlankCardPath())){
+                    examCardService.createJpgImage(examCard);
+                    examCardService.updateById(examCard);
+                }
+                FilePathVo filePathVo = JSON.parseObject(examCard.getBlankCardPath(), FilePathVo.class);
+                String cardUrl = teachcloudCommonService.filePreviewByPathAndType(filePathVo.getPath(), filePathVo.getUploadType().name(), filePathVo.getType(), false);
+                cardList.add(new UrlMd5Dto(cardUrl, filePathVo.getMd5()));
             }
             record.setPaper(paperList);
-
+            record.setCard(cardList);
+
+            // 签到表
+            List<UrlMd5Dto> signs = new ArrayList<>();
+            // 卷袋贴
+            List<UrlMd5Dto> packages = new ArrayList<>();
+            // 登记表
+            List<UrlMd5Dto> checkIns = new ArrayList<>();
+
+            List<String> examDetailIds = Arrays.asList(record.getExamDetailIds().split(","));
+            List<ExamDetail> examDetails = examDetailService.listByIds(examDetailIds);
+            examDetails.stream().forEach(m->{
+                JSONObject jsonObject = JSONObject.parseObject(m.getAttachmentPath());
+                String pathString = jsonObject.getString("path");
+                List<PrintPathVo> printPathVos = JSON.parseArray(pathString, PrintPathVo.class);
+                for (PrintPathVo printPathVo : printPathVos) {
+                    String url = teachcloudCommonService.filePreviewByPathAndType(printPathVo.getPdfPath(), printPathVo.getUploadType().name(), printPathVo.getType(), false);
+                    if(ClassifyEnum.SIGN.equals(printPathVo.getPrintType())){
+                        signs.add(new UrlMd5Dto(url, printPathVo.getPdfMd5()));
+                    }
+                    if(ClassifyEnum.PACKAGE.equals(printPathVo.getPrintType())){
+                        packages.add(new UrlMd5Dto(url, printPathVo.getPdfMd5()));
+                    }
+                    if(ClassifyEnum.CHECK_IN.equals(printPathVo.getPrintType())){
+                        checkIns.add(new UrlMd5Dto(url, printPathVo.getPdfMd5()));
+                    }
+                }
+            });
+            record.setSigns(signs);
+            record.setPackages(packages);
+            record.setCheckIn(checkIns);
         }
-        return null;
+        return clientExamTaskDtoList;
     }
 
     /**

+ 52 - 53
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamCardServiceImpl.java

@@ -19,7 +19,12 @@ import com.qmth.distributed.print.business.mapper.ExamCardMapper;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.util.CreatePdfUtil;
 import com.qmth.distributed.print.business.util.HtmlToJpgUtil;
-import com.qmth.teachcloud.common.util.HtmlToPdfUtil;
+import com.qmth.distributed.print.business.util.PdfUtil;
+import com.qmth.distributed.print.business.util.pdf.CreatePdfNewUtil;
+import com.qmth.teachcloud.common.bean.vo.FilePathVo;
+import com.qmth.teachcloud.common.enums.UploadFileEnum;
+import com.qmth.teachcloud.common.service.*;
+import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
 import com.qmth.teachcloud.common.bean.vo.PaperInfoVo;
 import com.qmth.teachcloud.common.contant.SystemConstant;
@@ -29,13 +34,6 @@ import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.CardCreateMethodEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.PageSizeEnum;
-import com.qmth.teachcloud.common.service.BasicAttachmentService;
-import com.qmth.teachcloud.common.service.BasicCourseService;
-import com.qmth.teachcloud.common.service.BasicRoleDataPermissionService;
-import com.qmth.teachcloud.common.service.TeachcloudCommonService;
-import com.qmth.teachcloud.common.util.ConvertUtil;
-import com.qmth.teachcloud.common.util.ExamTaskUtil;
-import com.qmth.teachcloud.common.util.ServletUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
@@ -82,15 +80,16 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
 
     @Resource
     BasicCourseService basicCourseService;
-
     @Resource
     HtmlToJpgUtil htmlToJpgUtil;
-
     @Resource
     CreatePdfUtil createPdfUtil;
-
     @Resource
     BasicRoleDataPermissionService basicRoleDataPermissionService;
+    @Resource
+    CreatePdfNewUtil createPdfNewUtil;
+    @Resource
+    private FileUploadService fileUploadService;
 
     @Transactional
     @Override
@@ -131,21 +130,6 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
             examCard.setAttachmentId(examCardParams.getAttachmentId());
             examCard.setCardRuleId(examCardParams.getCardRuleId());
             examCard.insertInfo(user.getId());
-
-            // 自动保存
-            if (CardStatusEnum.SUBMIT.equals(examCardParams.getStatus())) {
-                examCard.setContent(examCardParams.getContent());
-                examCard.setStageContent(null);
-                String htmlContent = examCardParams.getHtmlContent();
-                List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), htmlContent, PageSizeEnum.A3);
-                if (convertJpgStorageList.size() > 0) {
-                    examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
-                }
-                examCard.setHtmlContent(htmlContent);
-            } else {
-                examCard.setStageContent(examCardParams.getContent());
-            }
-            this.save(examCard);
         }
         // 修改
         else {
@@ -164,20 +148,18 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
             examCard.setStatus(examCardParams.getStatus());
             examCard.setUpdateId(user.getId());
             examCard.setUpdateTime(System.currentTimeMillis());
-            if (CardStatusEnum.SUBMIT.equals(examCardParams.getStatus())) {
-                examCard.setContent(examCardParams.getContent());
-                examCard.setStageContent(null);
-                String htmlContent = examCardParams.getHtmlContent();
-                List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), htmlContent, PageSizeEnum.A3);
-                if (convertJpgStorageList.size() > 0) {
-                    examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
-                }
-                examCard.setHtmlContent(htmlContent);
-            } else {
-                examCard.setStageContent(examCardParams.getContent());
-            }
-            this.updateById(examCard);
         }
+
+        // 自动保存
+        if (CardStatusEnum.SUBMIT.equals(examCardParams.getStatus())) {
+            examCard.setContent(examCardParams.getContent());
+            examCard.setStageContent(null);
+            examCard.setHtmlContent(examCardParams.getHtmlContent());
+            createJpgImage(examCard);
+        } else {
+            examCard.setStageContent(examCardParams.getContent());
+        }
+        this.saveOrUpdate(examCard);
         return String.valueOf(examCard.getId());
     }
 
@@ -352,10 +334,7 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
         }
         if (CardStatusEnum.SUBMIT.name().equals(params.getStatus())) {
             // 生成题卡图片
-            List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), examCard.getHtmlContent(), PageSizeEnum.A3);
-            if (convertJpgStorageList.size() > 0) {
-                examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
-            }
+            createJpgImage(examCard);
         }
         this.saveOrUpdate(examCard);
         return examCard.getId();
@@ -401,12 +380,7 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
         copyExamCard.setRemark(String.format("来源题卡:%s(%s)", id, examCard.getTitle()));
         copyExamCard.setUsed(false);
         // 生成图片
-        List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), copyExamCard.getHtmlContent(), PageSizeEnum.A3);
-        if (!convertJpgStorageList.isEmpty()) {
-            copyExamCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
-        } else {
-            copyExamCard.setJpgAttachment(null);
-        }
+        createJpgImage(copyExamCard);
         this.save(copyExamCard);
         return copyExamCard.getId();
     }
@@ -414,11 +388,11 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
     @Override
     public void convertImage(Long id) {
         ExamCard examCard = this.getById(id);
-        List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertHtmlToJpgByCard(examCard.getId(), examCard.getHtmlContent(), PageSizeEnum.A3);
-        if (convertJpgStorageList.size() > 0) {
-            String jpgAttachmentIds = JSON.toJSONString(convertJpgStorageList);
+        createJpgImage(examCard);
+        if (examCard.getJpgAttachment().length() > 0) {
             UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
-            updateWrapper.lambda().set(ExamCard::getJpgAttachment, jpgAttachmentIds)
+            updateWrapper.lambda().set(ExamCard::getBlankCardPath, examCard.getBlankCardPath())
+                    .set(ExamCard::getJpgAttachment, examCard.getJpgAttachment())
                     .eq(ExamCard::getId, id);
             this.update(updateWrapper);
         }
@@ -622,4 +596,29 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
             }
         }
     }
+
+    @Override
+    public ExamCard createJpgImage(ExamCard examCard) {
+        BasicCardRule basicCardRule = basicCardRuleService.getById(examCard.getCardRuleId());
+        String replaceBackupCardHtmlContent = createPdfNewUtil.replaceBackupCardHtmlParam(examCard.getHtmlContent(), null, basicCardRule, null);
+        File pdfFile = PdfUtil.htmlToPdf(replaceBackupCardHtmlContent);
+        try {
+            String fileName = PdfUtil.md5FileName("BLANK" + examCard.getId()) + SystemConstant.PDF_PREFIX;
+            FilePathVo filePathVo = fileUploadService.uploadFile(pdfFile, UploadFileEnum.PDF, fileName);
+            examCard.setBlankCardPath(JSON.toJSONString(filePathVo));
+            List<ConvertJpgStorage> convertJpgStorageList = htmlToJpgUtil.convertPdfToJpg(examCard.getId(), pdfFile, examCard.getCreateId());
+            if (convertJpgStorageList.size() > 0) {
+                examCard.setJpgAttachment(JSON.toJSONString(convertJpgStorageList));
+            } else {
+                examCard.setJpgAttachment(null);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (pdfFile.exists()) {
+                FileUtil.deleteFile(pdfFile);
+            }
+        }
+        return examCard;
+    }
 }

+ 19 - 8
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/GoogleBarCodeUtil.java

@@ -171,13 +171,24 @@ public class GoogleBarCodeUtil {
      * @return
      * @throws IOException
      */
-    public static String createBarCode(String contennt, boolean word) throws IOException {
-        BufferedImage image = GoogleBarCodeUtil.getBarCode(contennt);
-        ByteArrayOutputStream os = new ByteArrayOutputStream();
-        ImageIO.write(image, "png", os);
-        String imageBase64 = Base64Util.encode(os.toByteArray());
-        os.flush();
-        os.close();
-        return imageBase64;
+    public static String createBarCode(String contennt, boolean word) {
+        ByteArrayOutputStream os = null;
+        try {
+            BufferedImage image = GoogleBarCodeUtil.getBarCode(contennt);
+             os = new ByteArrayOutputStream();
+            ImageIO.write(image, "png", os);
+            String imageBase64 = Base64Util.encode(os.toByteArray());
+
+            return imageBase64;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            try {
+                os.flush();
+                os.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
     }
 }

+ 38 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/HtmlToJpgUtil.java

@@ -1,13 +1,17 @@
 package com.qmth.distributed.print.business.util;
 
+import com.alibaba.fastjson.JSON;
 import com.qmth.distributed.print.business.bean.marking.ConvertJpgStorage;
 import com.qmth.distributed.print.business.service.PrintCommonService;
+import com.qmth.teachcloud.common.bean.vo.FilePathVo;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.PageSizeEnum;
 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 com.qmth.teachcloud.common.util.HtmlToPdfUtil;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -25,6 +29,7 @@ import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
@@ -43,17 +48,20 @@ public class HtmlToJpgUtil {
 
     @Lazy
     @Resource
-    PrintCommonService printCommonService;
-
+    private PrintCommonService printCommonService;
+    @Resource
+    private DictionaryConfig dictionaryConfig;
     @Resource
-    DictionaryConfig dictionaryConfig;
+    private BasicAttachmentService basicAttachmentService;
+    @Resource
+    private FileUploadService fileUploadService;
 
     private final static Logger log = LoggerFactory.getLogger(HtmlToJpgUtil.class);
 
     /**
      * 转换html -> jpg : 生成本地临时文件
      *
-     * @param id    题卡Id
+     * @param id           题卡Id
      * @param htmlContent  html内容
      * @param pageSizeEnum 转化pdf的纸张类型
      */
@@ -77,7 +85,7 @@ public class HtmlToJpgUtil {
         // html
         try {
             File htmlFile = new File(htmlPath);
-            if(!htmlFile.exists()){
+            if (!htmlFile.exists()) {
                 htmlFile.getParentFile().mkdirs();
             }
             // 生成html文件
@@ -102,10 +110,34 @@ public class HtmlToJpgUtil {
         return basicAttachmentList;
     }
 
+    public List<ConvertJpgStorage> convertPdfToJpg(Long cardId, File file, Long userId) {
+        // jpg临时路径
+        List<ConvertJpgStorage> convertJpgStorages = new ArrayList<>();
+        List<BasicAttachment> basicAttachmentList = new ArrayList<>();
+        // html
+        try {
+            // pdf文件转jpg
+            List<File> jpgFileList = ConvertUtil.pdfToImageFile(file);
+            for (int i = 0; i < jpgFileList.size(); i++) {
+                int index = i + 1;
+                String fileName = cardId + "-" + index + SystemConstant.JPG_PREFIX;
+                FilePathVo filePathVo = fileUploadService.uploadFile(jpgFileList.get(i), UploadFileEnum.IMAGE, fileName);
+                BasicAttachment basicAttachment = new BasicAttachment(JSON.toJSONString(filePathVo), fileName, SystemConstant.PDF_PREFIX, new BigDecimal(file.length()), filePathVo.getMd5(), userId);
+                basicAttachmentService.save(basicAttachment);
+                basicAttachmentList.add(basicAttachment);
+
+                convertJpgStorages.add(new ConvertJpgStorage(basicAttachment.getId(), index));
+            }
+        } catch (Exception e) {
+            basicAttachmentService.batchDeleteAttachment(basicAttachmentList);
+        }
+        return convertJpgStorages;
+    }
+
     /**
      * 转换html -> jpg : 生成本地临时文件
      *
-     * @param cardTitle    题卡名称
+     * @param id           题卡名称
      * @param htmlContent  题卡内容
      * @param pageSizeEnum 转化pdf的纸张类型
      */

+ 4 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/pdf/CreatePdfNewUtil.java

@@ -1021,14 +1021,13 @@ public class CreatePdfNewUtil {
      * @param basicCardRule     题卡规则
      * @param backupPackageCode 备用题卡条码号
      */
-    public String replaceBackupCardHtmlParam(String htmlContent, String paperType, BasicCardRule basicCardRule, String backupPackageCode) throws
-            IOException {
+    public String replaceBackupCardHtmlParam(String htmlContent, String paperType, BasicCardRule basicCardRule, String backupPackageCode) {
         // 替换条码参数
         htmlContent = htmlContent.replaceAll("<img src=\"data:image/png;base64,\\$\\{examNumber\\}\">", "");
         htmlContent = htmlContent.replaceAll("\\$\\{examNumberStr\\}", "");
 
         //替换卷型参数
-        htmlContent = htmlContent.replaceAll("\\$\\{paperTypeName\\}", paperType);
+        htmlContent = htmlContent.replaceAll("\\$\\{paperTypeName\\}", StringUtils.isBlank(paperType) ? "" : paperType);
         //替换卷型条码(base64)
         if (Objects.nonNull(paperType)) {
             htmlContent = htmlContent.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(paperType), false));
@@ -1060,7 +1059,8 @@ public class CreatePdfNewUtil {
             //通用题卡生成卷袋贴条码
             String packageCodeImg = GoogleBarCodeUtil.createBarCode(backupPackageCode, false);
             htmlContent = htmlContent.replaceAll("\\$\\{packageCodeDom\\}", "<img src='" + "data:image/png;base64," + packageCodeImg + "'><p>" + backupPackageCode + "</p>");
-
+        } else {
+            htmlContent = htmlContent.replaceAll("\\$\\{packageCodeDom\\}", "");
         }
         return htmlContent;
     }

+ 3 - 0
distributed-print/install/mysql/upgrade/3.3.1.sql

@@ -392,3 +392,6 @@ ALTER TABLE `mark_student`
     ADD COLUMN `invalid` bit(1) NOT NULL COMMENT '强制绑定';
 
 ALTER TABLE `exam_card` ADD COLUMN `blank_card_path` VARCHAR(500) NULL COMMENT '空白题卡pdf路径' AFTER `update_time`;
+
+INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('241', '印刷-单文件打印', '/api/admin/client/print/single', 'URL', '199', '17', 'AUTH', '1', '1', '1');
+UPDATE `sys_privilege` SET `related` = '200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,241,973,974,975' WHERE (`id` = '199');

文件差异内容过多而无法显示
+ 0 - 0
distributed-print/src/test/java/com/qmth/distributed/print/ConvertUtilTest.java


+ 0 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/FileUploadServiceImpl.java

@@ -68,7 +68,6 @@ public class FileUploadServiceImpl implements FileUploadService {
 
             String type = isOssUpload(oss, uploadFileEnum) ? SystemConstant.OSS : SystemConstant.LOCAL;
             return new FilePathVo(uploadFileName, uploadFileEnum, type, FileUtil.md5File(pdfFile));
-
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof ApiException) {

+ 44 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/ConvertUtil.java

@@ -277,4 +277,48 @@ public class ConvertUtil {
         return fileList;
     }
 
+    public static List<File> pdfToImageFile(File pdfFile) 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);
+            PDFRenderer pdfRenderer = new PDFRenderer(doc);
+            PDPageTree pages = doc.getPages();
+            int pageCount = pages.getCount();
+            for (int i = 0; i < pageCount; i++) {
+                BufferedImage bim = pdfRenderer.renderImageWithDPI(i, 200);
+                os = new ByteArrayOutputStream();
+                ImageIO.write(bim, "jpg", os);
+                // jpg文件转出路径
+                File file = SystemConstant.getFileTempVar(SystemConstant.JPG_PREFIX);
+                if (!file.getParentFile().exists()) {
+                    // 不存在则创建父目录及子文件
+                    file.getParentFile().mkdirs();
+                    file.createNewFile();
+                }
+                IOUtils.write(os.toByteArray(), new FileOutputStream(file));
+                fileList.add(file);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw e;
+        } finally {
+            if (doc != null) {
+                doc.close();
+            }
+            if (os != null) {
+                os.close();
+            }
+            if (stream != null) {
+                stream.close();
+            }
+        }
+        return fileList;
+    }
+
 }

部分文件因为文件数量过多而无法显示