fix(文档拆分): MinioUtil -> ObsBootUtil

This commit is contained in:
yjz
2024-07-18 11:45:47 +08:00
parent fd5cdba866
commit 7d04c215c6
2 changed files with 49 additions and 40 deletions
@@ -1,7 +1,7 @@
package com.jero.modules.oss.controller;
import com.jero.common.exception.JeroBootException;
import com.jero.common.util.MinioUtil;
import com.jero.common.util.obs.ObsBootUtil;
import com.jero.modules.oss.service.IOSSFileService;
import com.jero.modules.oss.util.SplitFileUtils;
import lombok.extern.slf4j.Slf4j;
@@ -36,9 +36,10 @@ public class SplitFileController {
response.setHeader("Content-Disposition",
"attachment; filename=\"" + SplitFileUtils.encodeFileName(fileName, request) + "\"");
response.setContentType("application/force-download");
if (MinioUtil.doesObjectExist(fileUrl)) {
// if (MinioUtil.doesObjectExist(fileUrl)) {
try (OutputStream os = response.getOutputStream();
InputStream fis = MinioUtil.download(fileUrl)) {
// InputStream fis = MinioUtil.download(fileUrl)) {
InputStream fis = ObsBootUtil.getOssFile(fileUrl)) {
int len = 0;
while ((len = fis.read()) != -1) {
os.write(len);
@@ -49,7 +50,7 @@ public class SplitFileController {
} catch (IOException e) {
throw new JeroBootException("文件不存在");
}
}
// }
}
@@ -2,12 +2,14 @@ package com.jero.modules.split.service.impl;
import cn.hutool.core.lang.RegexPool;
import cn.hutool.core.util.ReUtil;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.exception.JeroBootException;
import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.IntekeyUtils;
import com.jero.common.util.MinioUtil;
import com.jero.common.util.UUIDUtils;
import com.jero.common.util.obs.ObsBootUtil;
import com.jero.modules.laws.documenttool.mapper.DocumentSplitMapper;
import com.jero.modules.laws.standard.entity.LawsDomesticStandard;
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
@@ -40,6 +42,8 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMath;
import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMathPara;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLevelText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
@@ -55,6 +59,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
@@ -173,10 +178,11 @@ public class FileSpiltService {
}
OSSFile ossFile = ossFileList.get(0);
String readFilePath = ossFile.getUrl();
if (StringUtils.isEmpty(readFilePath) || !MinioUtil.doesObjectExist(readFilePath)) {
if (StringUtils.isEmpty(readFilePath)) {
throw new JeroBootException("当前文件未找到,请重新选择!");
}
try (InputStream is = MinioUtil.download(readFilePath);InputStream is1 = MinioUtil.download(readFilePath)) {
// try (InputStream is = MinioUtil.download(readFilePath);InputStream is1 = MinioUtil.download(readFilePath)) {
try (InputStream is = ObsBootUtil.getOssFile(readFilePath);InputStream is1 = ObsBootUtil.getOssFile(readFilePath)) {
String fileName = readFilePath.substring((readFilePath.lastIndexOf("/") + 1));
MultipartFile mFile = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), is);
MultipartFile mFile1 = new MockMultipartFile(fileName, fileName, ContentType.APPLICATION_OCTET_STREAM.toString(), is1);
@@ -217,34 +223,34 @@ public class FileSpiltService {
// //处理段落中的文本以及图片
// handleParagraphRun(content, (XWPFRun) child, imageParser);
//} else
// if (child instanceof CTOMath) {
// CTOMath ctoMath = (CTOMath) child;
// String xmlText = ctoMath.xmlText().replaceAll("xml-fragment","m:oMath");
// Map<String, Object> map = new HashMap<>();
// map.put("encode", xmlText);
// String post = HttpRequest.post(mathToImgUrl)
// .header(Header.CONTENT_TYPE, "application/json")
// .body(xmlText)
// .execute().body();
// //String post = HttpUtil.post(mathToImgUrl, map);
// if (messageList.size() > 0) {
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
// }
// }
// else if (child instanceof CTOMathPara) {
// CTOMathPara ctoMathPara = (CTOMathPara) child;
// String xmlText = ctoMathPara.xmlText().replaceAll("xml-fragment","m:oMath");;
// Map<String,Object> map = new HashMap<>();
// map.put("encode",xmlText);
// String post = HttpRequest.post(mathToImgUrl)
// .header(Header.CONTENT_TYPE, "application/json")
// .body(xmlText)
// .execute().body();
// //String post = HttpUtil.post(mathToImgUrl, map);
// if (messageList.size() > 0) {
// addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
// }
// }
if (child instanceof CTOMath) {
CTOMath ctoMath = (CTOMath) child;
String xmlText = ctoMath.xmlText().replaceAll("xml-fragment","m:oMath");
Map<String, Object> map = new HashMap<>();
map.put("encode", xmlText);
String post = HttpRequest.post(mathToImgUrl)
.header(Header.CONTENT_TYPE, "application/json")
.body(xmlText)
.execute().body();
//String post = HttpUtil.post(mathToImgUrl, map);
if (messageList.size() > 0) {
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
}
}
else if (child instanceof CTOMathPara) {
CTOMathPara ctoMathPara = (CTOMathPara) child;
String xmlText = ctoMathPara.xmlText().replaceAll("xml-fragment","m:oMath");;
Map<String,Object> map = new HashMap<>();
map.put("encode",xmlText);
String post = HttpRequest.post(mathToImgUrl)
.header(Header.CONTENT_TYPE, "application/json")
.body(xmlText)
.execute().body();
//String post = HttpUtil.post(mathToImgUrl, map);
if (messageList.size() > 0) {
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
}
}
}
for (XWPFRun xwrun : p.getRuns()) {
@@ -940,7 +946,8 @@ public class FileSpiltService {
String filepathandname = filePathCos + "/" + imageName;
try {
String path = splitUrl+imageName;
MinioUtil.uploadByte(bytev, filepathandname);
// MinioUtil.uploadByte(bytev, filepathandname);
ObsBootUtil.upload(new ByteArrayInputStream(bytev), filepathandname);
String imgCon = path;
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
message.getItemsCondi().add(imgConVal);
@@ -961,7 +968,8 @@ public class FileSpiltService {
String filepathandname = filePathCos + "/" + imageName;
try {
String path = splitUrl+imageName;
MinioUtil.uploadByte(bytev, filepathandname);
// MinioUtil.uploadByte(bytev, filepathandname);
ObsBootUtil.upload(new ByteArrayInputStream(bytev), filepathandname);
String imgCon = path;
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
stringBuilder.append(imgConVal);
@@ -1118,11 +1126,11 @@ public class FileSpiltService {
}
OSSFile ossFile = ossFileList.get(0);
String readFilePath = ossFile.getUrl();
if (org.apache.commons.lang.StringUtils.isEmpty(readFilePath) || !MinioUtil.doesObjectExist(readFilePath)) {
if (org.apache.commons.lang.StringUtils.isEmpty(readFilePath)) {
throw new JeroBootException("当前文件未找到,请重新选择!");
}
try (InputStream is = MinioUtil.download(readFilePath)) {
// try (InputStream is = MinioUtil.download(readFilePath)) {
try (InputStream is = ObsBootUtil.getOssFile(readFilePath)) {
// InputStream is = new FileInputStream(readFilePath); //需要将文件路更改为word文档所在路径。
XWPFDocument doc = new XWPFDocument(is);