|
@@ -13,12 +13,14 @@ import com.aliyun.oss.model.*;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.util.TextUtils;
|
|
|
+import org.apache.poi.hwpf.HWPFDocument;
|
|
|
+import org.apache.poi.hwpf.usermodel.Range;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
+import java.io.*;
|
|
|
import java.net.*;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
@@ -154,6 +156,34 @@ public class OSSService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
+ public String bidDocPut(MultipartFile file, Long id) {
|
|
|
+ // 读取DOC文件
|
|
|
+ ByteArrayInputStream fis = new ByteArrayInputStream(IoUtil.readBytes(file.getInputStream()));
|
|
|
+
|
|
|
+ HWPFDocument document = new HWPFDocument(fis);
|
|
|
+ Range range = document.getRange();
|
|
|
+
|
|
|
+ // 创建一个新的空白docx文档
|
|
|
+ XWPFDocument newDocument = new XWPFDocument();
|
|
|
+
|
|
|
+ // 遍历原始doc文件的段落并添加到新的docx文档中
|
|
|
+ for (int i = 0; i < range.numParagraphs(); i++) {
|
|
|
+ XWPFParagraph paragraph = newDocument.createParagraph();
|
|
|
+ paragraph.createRun().setText(range.getParagraph(i).text());
|
|
|
+ }
|
|
|
+
|
|
|
+ String dir = "open/bid/" + id + "/";
|
|
|
+ String fileUrl = dir + file.getOriginalFilename() + "x";
|
|
|
+ ossClient.putObject(bucket, fileUrl , newDocument.getDocument().newInputStream());
|
|
|
+ fis.reset();
|
|
|
+
|
|
|
+ String encodedString = URLEncoder.encode(fileUrl, StandardCharsets.UTF_8);
|
|
|
+ newDocument.close();
|
|
|
+
|
|
|
+ return "https://cxzx.smcic.net/" + encodedString;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|