Răsfoiți Sursa

本地部署生成pdf调整

wangliang 3 ani în urmă
părinte
comite
149ee77a94

+ 29 - 13
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java

@@ -167,13 +167,14 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
                 UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
 //                htmlFile = ossUtil.ossDownload(filePath, url);
-                htmlFile = fileStoreUtil.ossDownload(filePath, url, uploadType.getFssType());
+                if (oss) {
+                    htmlFile = fileStoreUtil.ossDownload(filePath, url, uploadType.getFssType());
+                } else {
+                    htmlFile = new File(filePath);
+                }
             }
             LocalDateTime nowTime = LocalDateTime.now();
             StringJoiner pdfStringJoiner = new StringJoiner("");
-            if (!oss) {
-                pdfStringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
-            }
             pdfStringJoiner.add(UploadFileEnum.PDF.getTitle()).add(File.separator);
             pdfStringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
                     .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
@@ -203,10 +204,8 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             String md5 = ByteArray.md5(data).toHexString();
             InputStream ins = new ByteArrayInputStream(data);
             //String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
-            PdfDto pdfDto = null;
+            PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
             if (oss) {//上传至oss
-                pdfDto = PdfUtil.addPdfPage(pdfFile);
-//                ossUtil.ossUpload(pdfDirNameStr, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(pdfFileMd5)));
                 fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
 //                htmlFile.delete();
                 ins.close();
@@ -220,7 +219,11 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             object.put(SystemConstant.HTML_PATH, filePath);
             object.put("htmlMd5", htmlFileMd5);
             object.put("pdfMd5", md5);
-            object.put(SystemConstant.PDF_PATH, pdfDirNameStr);
+            if (!oss) {
+                object.put(SystemConstant.PDF_PATH, pdfFile.getPath());
+            } else {
+                object.put(SystemConstant.PDF_PATH, pdfDirNameStr);
+            }
             object.put(SystemConstant.TYPE, SystemConstant.OSS);
             object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
                     UploadFileEnum.HTML,
@@ -327,12 +330,19 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                     finalFile.createNewFile();
                 }
                 FileCopyUtils.copy(bytes, new File(stringJoiner.toString()));
-                fileMd5 = DigestUtils.md5Hex(new FileInputStream(stringJoiner.toString()));
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
                 jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
-                String destUrl = finalFile.getPath().replaceAll(SystemConstant.HTML_PREFIX, SystemConstant.PDF_PREFIX).replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
+                String destUrl = finalFile.getPath().replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
                 HtmlToPdfUtil.convert(finalFile.getPath(), destUrl, PageSizeEnum.A3);
-//                File pdfFile = asposePdfUtil.documentToPdf(finalFile.getPath(), destUrl, PaperSize.A3);
+                File pdfFile = new File(destUrl);
+                if (!pdfFile.exists()) {
+                    pdfFile.getParentFile().mkdirs();
+                    pdfFile.createNewFile();
+                }
+                pdfDto = PdfUtil.addPdfPage(pdfFile);
+                fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
+                localFileList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
+
                 jsonObject.put(SystemConstant.PDF_PATH, destUrl);
                 jsonObject.put("htmlMd5", DigestUtils.md5Hex(new FileInputStream(finalFile)));
                 jsonObject.put("pdfMd5", fileMd5);
@@ -429,9 +439,15 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 fileMd5 = DigestUtils.md5Hex(new FileInputStream(stringJoiner.toString()));
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
                 jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
-                String destUrl = finalFile.getPath().replaceAll(SystemConstant.HTML_PREFIX, SystemConstant.PDF_PREFIX).replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
+                String destUrl = finalFile.getPath().replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
                 HtmlToPdfUtil.convert(finalFile.getPath(), destUrl, PageSizeEnum.A3);
-//                File pdfFile = asposePdfUtil.documentToPdf(finalFile.getPath(), destUrl, PaperSize.A3);
+                File pdfFile = new File(destUrl);
+                if (!pdfFile.exists()) {
+                    pdfFile.getParentFile().mkdirs();
+                    pdfFile.createNewFile();
+                }
+                fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
+
                 jsonObject.put(SystemConstant.PDF_PATH, destUrl);
                 jsonObject.put("htmlMd5", DigestUtils.md5Hex(new FileInputStream(finalFile)));
                 jsonObject.put("pdfMd5", fileMd5);

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -117,8 +117,9 @@ public abstract class AsyncImportTaskTemplete {
                 path = path.replaceAll(UploadFileEnum.PDF.getTitle(), UploadFileEnum.FILE.getTitle());
             }
 
+            path = path.substring(0, path.lastIndexOf("/") + 1);
+            stringJoiner.add(path).add(SystemConstant.getUuid()).add(TXT_PREFIX).toString();
             if (Objects.equals(type, SystemConstant.OSS)) {//上传至oss
-                path = path.substring(0, path.lastIndexOf("/") + 1);
                 stringJoiner.add(path).add(SystemConstant.getUuid()).add(TXT_PREFIX).toString();
                 FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
                 fileStoreUtil.ossUpload(stringJoiner.toString(), inputStream, DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)), fileStoreUtil.getUploadEnumByPath(stringJoiner.toString()).getFssType());

+ 7 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -14,6 +14,7 @@ import com.qmth.distributed.print.business.enums.PrintMethodEnum;
 import com.qmth.distributed.print.business.service.ExamDetailService;
 import com.qmth.distributed.print.business.service.ExamStudentService;
 import com.qmth.distributed.print.business.service.PrintCommonService;
+import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.*;
 import com.qmth.teachcloud.common.enums.*;
@@ -94,6 +95,9 @@ public class CreatePdfUtil {
     @Resource
     ExamStudentService examStudentService;
 
+    @Resource
+    DictionaryConfig dictionaryConfig;
+
     /**
      * 创建登记表
      *
@@ -781,6 +785,7 @@ public class CreatePdfUtil {
                                           ExamDetail examDetail,
                                           BasicExamRule basicExamRule,
                                           List<PdfDto> mergePdfDeleteList) throws Exception {
+        boolean oss = dictionaryConfig.sysDomain().isOss();
         StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
         // oss上只认"/",windows生成的路径分隔符全部替换为"/"
         File localA4PdfFile = null, localA3PdfFile = null, localA3PdfCardFile = null;
@@ -819,12 +824,12 @@ public class CreatePdfUtil {
             examDetail.setStatus(ExamDetailStatusEnum.READY);
         }
         detailService.saveOrUpdate(examDetail);
-        if (Objects.nonNull(localA3PdfFile)) {
+        if (Objects.nonNull(localA3PdfFile) && oss) {
 //            ossUtil.ossUpload(dirNameA3, localA3PdfFile, DigestUtils.md5Hex(new FileInputStream(localA3PdfFile)));
             fileStoreUtil.ossUpload(dirNameA3, localA3PdfFile, DigestUtils.md5Hex(new FileInputStream(localA3PdfFile)), fileStoreUtil.getUploadEnumByPath(dirNameA3).getFssType());
             localA3PdfFile.delete();
         }
-        if (Objects.nonNull(localA3PdfCardFile)) {
+        if (Objects.nonNull(localA3PdfCardFile) && oss) {
             fileStoreUtil.ossUpload(dirNameCardA3, localA3PdfCardFile, DigestUtils.md5Hex(new FileInputStream(localA3PdfCardFile)), fileStoreUtil.getUploadEnumByPath(dirNameCardA3).getFssType());
             localA3PdfCardFile.delete();
         }

+ 7 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java

@@ -96,7 +96,12 @@ public class FreemarkerUtil {
             String ftlName = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
 
             Configuration configuration = new Configuration(Configuration.VERSION_2_3_29);
-            File templates = ResourceUtils.getFile(SystemConstant.TEMP_FILES_DIR + File.separator + ftlPath);
+            File templates = null;
+            if (ftlPath.contains(SystemConstant.TEMP_FILES_DIR)) {
+                templates = ResourceUtils.getFile(ftlPath);
+            } else {
+                templates = ResourceUtils.getFile(SystemConstant.TEMP_FILES_DIR + File.separator + ftlPath);
+            }
             configuration.setDirectoryForTemplateLoading(templates);
             // step1 加载模版文件
             Template template = configuration.getTemplate(ftlName + SystemConstant.FTL_PREFIX);
@@ -123,7 +128,7 @@ public class FreemarkerUtil {
             if (oss) {
                 String htmlStringJoinerStr = htmlStringJoiner.toString().replace("\\", "/");
 //                ossUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)));
-                fileStoreUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)),fileStoreUtil.getUploadEnumByPath(htmlStringJoinerStr).getFssType());
+                fileStoreUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)), fileStoreUtil.getUploadEnumByPath(htmlStringJoinerStr).getFssType());
                 jsonObject.put(SystemConstant.HTML_PATH, htmlStringJoinerStr);
                 jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
                         UploadFileEnum.FILE,

+ 9 - 3
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicAttachmentServiceImpl.java

@@ -102,9 +102,15 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                 localPdfFile.getParentFile().mkdirs();
                 localPdfFile.createNewFile();
             }
+            boolean oss = dictionaryConfig.sysDomain().isOss();
             JSONObject jsonPdf = new JSONObject();
-            jsonPdf.put(SystemConstant.TYPE, SystemConstant.OSS);
-            jsonPdf.put(SystemConstant.PATH, dirName);
+            if (oss) {
+                jsonPdf.put(SystemConstant.TYPE, SystemConstant.OSS);
+                jsonPdf.put(SystemConstant.PATH, dirName);
+            } else {
+                jsonPdf.put(SystemConstant.TYPE, SystemConstant.LOCAL);
+                jsonPdf.put(SystemConstant.PATH, localPdfFile);
+            }
             jsonPdf.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.PDF);
             basicAttachment = new BasicAttachment(jsonPdf.toJSONString(), localPdfFile.getName(), SystemConstant.PDF_PREFIX, new BigDecimal(localPdfFile.length()), DigestUtils.md5Hex(new FileInputStream(localPdfFile)), userId);
             save(basicAttachment);
@@ -200,7 +206,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(format);
             if (oss) {//上传至oss\
                 String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
-                fileStoreUtil.ossUpload(dirName,file.getInputStream(),DigestUtils.md5Hex(file.getInputStream()),type.getFssType());
+                fileStoreUtil.ossUpload(dirName, file.getInputStream(), DigestUtils.md5Hex(file.getInputStream()), type.getFssType());
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
                 jsonObject.put(SystemConstant.PATH, dirName);
             } else {//上传至服务器

+ 8 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -585,7 +585,7 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         String filePath = (String) jsonObject.get(SystemConstant.PATH);
         UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
         if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
-            url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
+            url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + filePath;
         } else {
 //            if (uploadFileEnum == UploadFileEnum.PAPER) {
 //                url = ossUtil.getPrivateUrl(filePath);
@@ -773,11 +773,17 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         String filePath = pdf ? (String) jsonObject.get(SystemConstant.PDF_PATH) : (String) jsonObject.get(SystemConstant.PATH);
         UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
 
-        StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
+        StringJoiner localPath = new StringJoiner("");
         if (Objects.equals(attachmentType, SystemConstant.OSS)) {
 //            file = ossUtil.ossDownload(filePath, localPath.toString());
+            localPath = localPath.add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
             file = fileStoreUtil.ossDownload(filePath, localPath.toString(), uploadType.getFssType());
         } else {
+            if (!filePath.contains(SystemConstant.TEMP_FILES_DIR)) {
+                localPath = localPath.add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
+            } else {
+                localPath = localPath.add(filePath);
+            }
             file = new File(localPath.toString());
         }
         return file;

+ 4 - 4
teachcloud-task/src/main/resources/application-task.properties

@@ -20,7 +20,7 @@ db.password=123456789
 #redis\u6570\u636E\u6E90\u914D\u7F6E
 com.qmth.redis.host=${db.host}
 com.qmth.redis.port=6379
-com.qmth.redis.db=15
+com.qmth.redis.db=1
 #com.qmth.redis.password
 
 #mysql\u914D\u7F6E
@@ -62,7 +62,7 @@ com.qmth.fss.private.config=oss://key:secret@teachcloud-print-dev-private.oss-ap
 com.qmth.fss.private.server=http://oss-file.qmth.com.cn/teachcloud-print-dev-private
 
 #\u7CFB\u7EDF\u914D\u7F6E
-sys.config.oss=true
+sys.config.oss=false
 sys.config.attachmentType=.xlsx,.xls,.doc,.docx,.pdf,.jpg,.jpeg,.png,.html,.zip,.mp3,.wav,.dll,.exe,.ftl,.bpmn,.xml
 sys.config.attachmentLength=100
 sys.config.attachmentSize=200
@@ -74,8 +74,8 @@ sys.config.serverHost=localhost:7011
 sys.config.accessKey=274f823e5f59410f8b3bb6edcd8e2b6e
 sys.config.accessSecret=y7AO6W0TOdTF8HpWBwGHbp3wfIHsmUKr
 sys.config.adminLogoUrl=http://qmth-test.oss-cn-shenzhen.aliyuncs.com/frontend/wx_logo.png
-#sys.config.htmlToPdfUrl=/usr/local/bin/wkhtmltopdf
-sys.config.htmlToPdfUrl=E:/devUtils/wkhtmltopdf/bin/wkhtmltopdf.exe
+sys.config.htmlToPdfUrl=/usr/local/bin/wkhtmltopdf
+#sys.config.htmlToPdfUrl=E:/devUtils/wkhtmltopdf/bin/wkhtmltopdf.exe
 sys.config.autoCreatePdfResetMaxCount=5
 sys.config.threadPoolCoreSize=1
 sys.config.customThreadPoolCoreSize=true