From 8577a11e5093871b2b5d6988431e7e22e76d43e6 Mon Sep 17 00:00:00 2001
From: value <z1292839451@163.com>
Date: 星期一, 29 四月 2024 01:46:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java | 62 ++++++++++++++++++++----------
1 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
index 2392e16..52eded4 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
@@ -1,31 +1,34 @@
package com.yuanchu.mom.service.impl;
+import com.aspose.words.License;
+import com.aspose.words.SaveFormat;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.Pictures;
-import com.spire.doc.Document;
-import com.spire.doc.FileFormat;
import com.yuanchu.mom.common.GetLook;
import com.yuanchu.mom.common.PrintChina;
import com.yuanchu.mom.dto.ReportPageDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.InsOrderMapper;
+import com.yuanchu.mom.mapper.InsReportMapper;
import com.yuanchu.mom.mapper.UserMapper;
import com.yuanchu.mom.pojo.InsOrder;
import com.yuanchu.mom.pojo.InsReport;
import com.yuanchu.mom.service.InsReportService;
-import com.yuanchu.mom.mapper.InsReportMapper;
import com.yuanchu.mom.utils.QueryWrappers;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
-import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDateTime;
@@ -68,18 +71,6 @@
if (map1.get("look") == 1) reportPageDto.setCreateUser(map1.get("userId"));
map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto)));
return map;
- }
-
- @Override
- public String wordToHtml(String path) {
- try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
- Document document = new Document();
- document.loadFromFile(path.replace("/word", wordUrl));
- document.saveToFile(outputStream, FileFormat.Html);
- return outputStream.toString();
- } catch (Exception e) {
- throw new ErrorException("杞崲澶辫触");
- }
}
@Override
@@ -189,11 +180,8 @@
@Override
public void wordToPdf(String path) {
CompletableFuture.supplyAsync(() -> {
- try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
- Document document = new Document();
- document.loadFromFile(path);
- document.saveToFile(path.replace(".docx", ".pdf"), FileFormat.PDF);
- System.out.println(path.replace(".docx", ".pdf"));
+ try {
+ wordToPdf(path, path.replace(".docx", ".pdf"));
return null;
} catch (Exception e) {
throw new ErrorException("杞崲澶辫触");
@@ -204,6 +192,38 @@
return null;
});
}
+
+ public String wordToPdf(String wordPath,String pdfPath) {
+ FileOutputStream os = null;
+ try {
+ //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃
+// InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml");
+ InputStream is = new ClassPathResource("/lib/license.xml").getInputStream();
+ License license = new License();
+ license.setLicense(is);
+ if (!license.getIsLicensed()) {
+ System.out.println("License楠岃瘉涓嶉�氳繃...");
+ return null;
+ }
+ //鐢熸垚涓�涓┖鐨凱DF鏂囦欢
+ File file = new File(pdfPath);
+ os = new FileOutputStream(file);
+ //瑕佽浆鎹㈢殑word鏂囦欢
+ com.aspose.words.Document doc = new com.aspose.words.Document(wordPath);
+ doc.save(os, SaveFormat.PDF);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
+ }
}
--
Gitblit v1.9.3